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