2017-06-10 20:35:01 +00:00
|
|
|
const gulp = require('gulp');
|
2017-06-24 23:04:10 +00:00
|
|
|
const util = require('gulp-util');
|
2017-06-10 20:35:01 +00:00
|
|
|
const exec = require('child_process').exec;
|
|
|
|
const rimraf = require('rimraf');
|
2017-02-26 21:24:53 +00:00
|
|
|
|
2017-06-24 23:04:10 +00:00
|
|
|
const browsersync = require('browser-sync');
|
2017-06-10 20:35:01 +00:00
|
|
|
const ghPages = require('gulp-gh-pages');
|
2017-02-26 21:24:53 +00:00
|
|
|
|
2017-06-10 20:35:01 +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
|
|
|
|
2017-06-10 20:35:01 +00:00
|
|
|
const imageResize = require('gulp-image-resize');
|
2017-02-26 21:24:53 +00:00
|
|
|
|
2017-06-10 20:35:01 +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
|
|
|
|
2017-06-24 23:04:10 +00:00
|
|
|
// PHASE 1 - Setup
|
2017-02-26 21:24:53 +00:00
|
|
|
gulp.task('setup', function(cb) {
|
2017-06-24 23:04:10 +00:00
|
|
|
if (util.env.production) {
|
2017-02-26 21:24:53 +00:00
|
|
|
process.env.HUGO_ENV = 'PRD';
|
2017-06-24 23:04:10 +00:00
|
|
|
} 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
|
|
|
});
|
|
|
|
|
2017-06-27 22:54:43 +00:00
|
|
|
// PHASE 2 - Building
|
2017-06-25 02:14:34 +00:00
|
|
|
gulp.task('hugo', function (cb) {
|
2017-07-15 23:08:50 +00:00
|
|
|
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: './'})
|
2017-06-10 20:35:01 +00:00
|
|
|
.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: './'})
|
2017-06-10 20:35:01 +00:00
|
|
|
.pipe(imageResize({ width: 824, height: 306, crop: false }))
|
2017-06-04 18:30:07 +00:00
|
|
|
.pipe(gulp.dest('./')),
|
2017-06-04 18:28:06 +00:00
|
|
|
gulp.src(`${distPath}/images/game/boxart/*`, {base: './'})
|
2017-06-10 20:35:01 +00:00
|
|
|
.pipe(imageResize({ width: 328, height: 300, crop: true }))
|
2017-06-04 18:30:07 +00:00
|
|
|
.pipe(gulp.dest('./')),
|
2017-06-04 18:28:06 +00:00
|
|
|
gulp.src(`${distPath}/images/game/icons/*`, {base: './'})
|
2017-06-10 20:35:01 +00:00
|
|
|
.pipe(imageResize({ width: 48, height: 48, crop: true }))
|
2017-06-24 19:34:51 +00:00
|
|
|
.pipe(gulp.dest('./')),
|
2017-06-24 23:04:10 +00:00
|
|
|
|
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
|
|
|
));
|
|
|
|
|
2017-06-27 22:54:43 +00:00
|
|
|
// This task ensures all phases up to PHASE 2 are completed.
|
2017-06-25 02:14:34 +00:00
|
|
|
gulp.task('build', ['hugo', 'css', 'images'], function (done) {
|
|
|
|
browsersync.reload();
|
|
|
|
done();
|
|
|
|
});
|
2017-06-24 23:04:10 +00:00
|
|
|
|
2017-06-27 22:54:43 +00:00
|
|
|
// STAGE 3 - Optimization
|
2017-06-24 23:04:10 +00:00
|
|
|
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}))
|
2017-06-24 23:04:10 +00:00
|
|
|
.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('./'))
|
|
|
|
));
|
|
|
|
|
2017-06-27 22:54:43 +00:00
|
|
|
// STAGE 4 - Deploy
|
2017-06-24 23:04:10 +00:00
|
|
|
|
|
|
|
// 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']);
|
2017-06-24 23:04:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// 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}`);
|
2017-02-27 02:24:32 +00:00
|
|
|
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));
|
|
|
|
});
|