citra-web/gulpfile.js

74 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-02-26 22:24:53 +01:00
var gulp = require('gulp');
var gutil = require('gulp-util');
var exec = require('child_process').exec;
var rimraf = require('rimraf');
var postcss = require('gulp-postcss');
var cssImport = require('postcss-import');
var cssnext = require('postcss-cssnext');
var md5 = require("gulp-md5-plus");
var ghPages = require('gulp-gh-pages');
var uncss = require('gulp-uncss');
var cleanCSS = require('gulp-clean-css');
var image = require('gulp-image');
var jimp = require("gulp-jimp-resize");
var htmlmin = require('gulp-htmlmin');
const distPath = './site/public';
const cname = 'citra-emu.org';
const deployOptions = {
remoteUrl: "git@github.com:CitraBotWeb/CitraBotWeb.github.io.git",
branch: "master"
};
gulp.task("default", ['html']);
gulp.task('setup', function(cb) {
process.env.HUGO_ENV = 'PRD';
process.env.GULP = 'true';
rimraf(`${distPath}`, cb);
});
gulp.task('hugo', ['setup'], function (cb) {
exec('hugo -s ./site/ -v', function (err, stdout, stderr) {
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`})]))
.pipe(cleanCSS())
.pipe(md5(10, `${distPath}/**/*.html`))
.pipe(gulp.dest('./'))
));
gulp.task('images', ['hugo'], () => (
gulp.src(`${distPath}/images/*`, {base: './'})
.pipe(gulp.dest('./')),
gulp.src(`${distPath}/images/jumbotron/*`, {base: './'})
.pipe(jimp({ sizes: [{"width": 786, "height": 471 }] }))
.pipe(gulp.dest('./')),
gulp.src(`${distPath}/images/banners/*`, {base: './'})
.pipe(jimp({ sizes: [{"width": 824, "height": 306 }] }))
.pipe(gulp.dest('./'))
));
gulp.task('html', ['hugo', 'css', 'images'], () => (
gulp.src(`${distPath}/**/*.html`, {base: './'})
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./'))
));
gulp.task('deploy', ['hugo', 'css', 'images', 'html'], () => {
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));
});