citra-emu
/
citra-web
Archived
1
0
Fork 0
This repository has been archived on 2024-03-23. You can view files and clone it, but cannot push or open issues or pull requests.
citra-web/gulpfile.js

136 lines
4.0 KiB
JavaScript
Raw Normal View History

const gulp = require('gulp');
const util = require('gulp-util');
const exec = require('child_process').exec;
const rimraf = require('rimraf');
2017-02-26 21:24:53 +00:00
const browsersync = require('browser-sync');
const ghPages = require('gulp-gh-pages');
2017-02-26 21:24:53 +00:00
const md5 = require("gulp-md5-plus");
const postcss = require('gulp-postcss');
const cssImport = require('postcss-import');
const cssnext = require('postcss-cssnext');
const cleanCSS = require('gulp-clean-css');
2017-02-26 21:24:53 +00:00
const imageResize = require('gulp-image-resize');
2017-02-26 21:24:53 +00:00
const htmlmin = require('gulp-htmlmin');
2017-02-26 21:24:53 +00:00
2017-06-25 02:14:34 +00:00
const hugoPath = './site';
const distPath = './public';
2017-02-26 21:24:53 +00:00
const cname = 'citra-emu.org';
const deployOptions = {
remoteUrl: "git@github.com:CitraBotWeb/CitraBotWeb.github.io.git",
branch: "master"
};
2017-06-25 02:14:34 +00:00
gulp.task("default", ['setup', 'serve']);
2017-02-26 21:24:53 +00:00
// PHASE 1 - Setup
2017-02-26 21:24:53 +00:00
gulp.task('setup', function(cb) {
if (util.env.production) {
2017-02-26 21:24:53 +00:00
process.env.HUGO_ENV = 'PRD';
} else {
process.env.HUGO_ENV = 'DEV';
}
process.env.GULP = 'true';
util.log(`process.env.HUGO_ENV = '${process.env.HUGO_ENV}'`);
util.log(`process.env.GULP = '${process.env.GULP}'`);
rimraf(`${distPath}`, cb);
2017-02-26 21:24:53 +00:00
});
// PHASE 2 - Building
2017-06-25 02:14:34 +00:00
gulp.task('hugo', function (cb) {
exec('hugo -s ./site/ -d ../public/ -v', function (err, stdout, stderr) {
2017-02-26 21:24:53 +00:00
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task("css", ['hugo'], () => (
gulp.src(`${distPath}/css/**/*.css`, {base: './'})
.pipe(postcss([cssnext(), cssImport({from: `${distPath}/css/main.css`})]))
2017-06-24 14:08:37 +00:00
.pipe(gulp.dest('./'))
));
2017-02-26 21:24:53 +00:00
gulp.task('images', ['hugo'], () => (
gulp.src(`${distPath}/images/*`, {base: './'})
.pipe(gulp.dest('./')),
gulp.src(`${distPath}/images/jumbotron/*`, {base: './'})
.pipe(imageResize({ width: 786, height: 471, crop: true }))
2017-02-26 21:24:53 +00:00
.pipe(gulp.dest('./')),
gulp.src(`${distPath}/images/banners/*`, {base: './'})
.pipe(imageResize({ width: 824, height: 306, crop: false }))
2017-06-04 18:30:07 +00:00
.pipe(gulp.dest('./')),
gulp.src(`${distPath}/images/game/boxart/*`, {base: './'})
.pipe(imageResize({ width: 328, height: 300, crop: true }))
2017-06-04 18:30:07 +00:00
.pipe(gulp.dest('./')),
gulp.src(`${distPath}/images/game/icons/*`, {base: './'})
.pipe(imageResize({ width: 48, height: 48, crop: true }))
2017-06-24 19:34:51 +00:00
.pipe(gulp.dest('./')),
2017-06-24 19:34:51 +00:00
gulp.src(`${distPath}/images/screenshots/*`)
.pipe(imageResize({ width: 400, height: 240, crop: false }))
.pipe(gulp.dest(`${distPath}/images/screenshots/thumbs`))
2017-02-26 21:24:53 +00:00
));
gulp.task('repogen', ['hugo'], function (cb) {
exec('node app.js', {
cwd: "scripts/downloads"
}, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('repo', ['repogen'], () => (
gulp.src(`scripts/downloads/build/**`)
.pipe(gulp.dest(`${distPath}/repository`))
));
// This task ensures all phases up to PHASE 2 are completed.
gulp.task('build', ['hugo', 'css', 'images', 'repo'], function (done) {
2017-06-25 02:14:34 +00:00
browsersync.reload();
done();
});
// STAGE 3 - Optimization
gulp.task('compress', ['build'], () => (
gulp.src(`${distPath}/js/**/*.js`, {base: './'})
.pipe(md5(10, `${distPath}/**/*.html`))
.pipe(gulp.dest('./')),
2017-02-26 21:24:53 +00:00
gulp.src(`${distPath}/**/*.html`, {base: './'})
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./')),
gulp.src(`${distPath}/css/**/*.css`, {base: './'})
.pipe(cleanCSS())
.pipe(md5(10, `${distPath}/**/*.html`))
2017-02-26 21:24:53 +00:00
.pipe(gulp.dest('./'))
));
// STAGE 4 - Deploy
// Used for Development
gulp.task('serve', ['build'], () => {
// Serve files from the root of this project
browsersync({
server: {
baseDir: distPath
},
open: false
});
2017-06-25 02:14:34 +00:00
gulp.watch('./site/**/*', ['build']);
});
// Used for Production
2017-06-25 02:14:34 +00:00
gulp.task('deploy', ['setup', 'build', 'compress'], () => {
2017-02-26 21:24:53 +00:00
require('fs').writeFileSync(`${distPath}/CNAME`, `${cname}`);
require('fs').writeFileSync(`${distPath}/robots.txt`, `Sitemap: https://${cname}/sitemap.xml\n\nUser-agent: *`);
2017-02-26 21:24:53 +00:00
return gulp.src(`${distPath}/**/*`).pipe(ghPages(deployOptions));
});