citra-web/gulpfile.js

121 lines
3.6 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 22:24:53 +01:00
const browsersync = require('browser-sync');
const ghPages = require('gulp-gh-pages');
2017-02-26 22:24:53 +01: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 22:24:53 +01:00
const imageResize = require('gulp-image-resize');
2017-02-26 22:24:53 +01:00
const htmlmin = require('gulp-htmlmin');
2017-02-26 22:24:53 +01:00
2017-06-25 04:14:34 +02:00
const hugoPath = './site';
const distPath = './public';
2017-02-26 22:24:53 +01:00
const cname = 'citra-emu.org';
const deployOptions = {
remoteUrl: "git@github.com:CitraBotWeb/CitraBotWeb.github.io.git",
branch: "master"
};
2017-06-25 04:14:34 +02:00
gulp.task("default", ['setup', 'serve']);
2017-02-26 22:24:53 +01:00
// PHASE 1 - Setup
2017-02-26 22:24:53 +01:00
gulp.task('setup', function(cb) {
if (util.env.production) {
2017-02-26 22:24:53 +01: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 22:24:53 +01:00
});
// PHASE 2 - Building
2017-06-25 04:14:34 +02:00
gulp.task('hugo', function (cb) {
exec('$(npm bin)/hugo -s ./site/ -d ../public/ -v', function (err, stdout, stderr) {
2017-02-26 22:24:53 +01: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 16:08:37 +02:00
.pipe(gulp.dest('./'))
));
2017-02-26 22:24:53 +01: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 22:24:53 +01:00
.pipe(gulp.dest('./')),
gulp.src(`${distPath}/images/banners/*`, {base: './'})
.pipe(imageResize({ width: 824, height: 306, crop: false }))
2017-06-04 20:30:07 +02:00
.pipe(gulp.dest('./')),
gulp.src(`${distPath}/images/game/boxart/*`, {base: './'})
.pipe(imageResize({ width: 328, height: 300, crop: true }))
2017-06-04 20:30:07 +02:00
.pipe(gulp.dest('./')),
gulp.src(`${distPath}/images/game/icons/*`, {base: './'})
.pipe(imageResize({ width: 48, height: 48, crop: true }))
2017-06-24 21:34:51 +02:00
.pipe(gulp.dest('./')),
2017-06-24 21:34:51 +02:00
gulp.src(`${distPath}/images/screenshots/*`)
.pipe(imageResize({ width: 400, height: 240, crop: false }))
.pipe(gulp.dest(`${distPath}/images/screenshots/thumbs`))
2017-02-26 22:24:53 +01:00
));
// This task ensures all phases up to PHASE 2 are completed.
2017-06-25 04:14:34 +02:00
gulp.task('build', ['hugo', 'css', 'images'], function (done) {
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 22:24:53 +01: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 22:24:53 +01: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 04:14:34 +02:00
gulp.watch('./site/**/*', ['build']);
});
// Used for Production
2017-06-25 04:14:34 +02:00
gulp.task('deploy', ['setup', 'build', 'compress'], () => {
2017-02-26 22:24:53 +01:00
require('fs').writeFileSync(`${distPath}/CNAME`, `${cname}`);
require('fs').writeFileSync(`${distPath}/robots.txt`, `Sitemap: https://${cname}/sitemap.xml\n\nUser-agent: *`);
2017-02-26 22:24:53 +01:00
return gulp.src(`${distPath}/**/*`).pipe(ghPages(deployOptions));
});