Updated gulp file to be able to run hugo locally.
This commit is contained in:
parent
1a41025f95
commit
2c6d226a22
53
gulpfile.js
53
gulpfile.js
|
@ -1,7 +1,9 @@
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
|
const util = require('gulp-util');
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
const rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
|
|
||||||
|
const browsersync = require('browser-sync');
|
||||||
const ghPages = require('gulp-gh-pages');
|
const ghPages = require('gulp-gh-pages');
|
||||||
|
|
||||||
const md5 = require("gulp-md5-plus");
|
const md5 = require("gulp-md5-plus");
|
||||||
|
@ -22,14 +24,26 @@ const deployOptions = {
|
||||||
branch: "master"
|
branch: "master"
|
||||||
};
|
};
|
||||||
|
|
||||||
gulp.task("default", ['html']);
|
gulp.task("default", ['serve']);
|
||||||
|
|
||||||
|
// PHASE 1 - Setup
|
||||||
gulp.task('setup', function(cb) {
|
gulp.task('setup', function(cb) {
|
||||||
|
if (util.env.production) {
|
||||||
process.env.HUGO_ENV = 'PRD';
|
process.env.HUGO_ENV = 'PRD';
|
||||||
|
} else {
|
||||||
|
process.env.HUGO_ENV = 'DEV';
|
||||||
|
}
|
||||||
process.env.GULP = 'true';
|
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);
|
rimraf(`${distPath}`, cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// PHASE 2 - Data Dependencies
|
||||||
|
|
||||||
|
// PHASE 3 - Building
|
||||||
gulp.task('hugo', ['setup'], function (cb) {
|
gulp.task('hugo', ['setup'], function (cb) {
|
||||||
exec('hugo -s ./site/ -v', function (err, stdout, stderr) {
|
exec('hugo -s ./site/ -v', function (err, stdout, stderr) {
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
|
@ -41,14 +55,6 @@ gulp.task('hugo', ['setup'], function (cb) {
|
||||||
gulp.task("css", ['hugo'], () => (
|
gulp.task("css", ['hugo'], () => (
|
||||||
gulp.src(`${distPath}/css/**/*.css`, {base: './'})
|
gulp.src(`${distPath}/css/**/*.css`, {base: './'})
|
||||||
.pipe(postcss([cssnext(), cssImport({from: `${distPath}/css/main.css`})]))
|
.pipe(postcss([cssnext(), cssImport({from: `${distPath}/css/main.css`})]))
|
||||||
.pipe(cleanCSS())
|
|
||||||
.pipe(md5(10, `${distPath}/**/*.html`))
|
|
||||||
.pipe(gulp.dest('./'))
|
|
||||||
));
|
|
||||||
|
|
||||||
gulp.task("js", ['hugo'], () => (
|
|
||||||
gulp.src(`${distPath}/js/**/*.js`, {base: './'})
|
|
||||||
.pipe(md5(10, `${distPath}/**/*.html`))
|
|
||||||
.pipe(gulp.dest('./'))
|
.pipe(gulp.dest('./'))
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -73,13 +79,38 @@ gulp.task('images', ['hugo'], () => (
|
||||||
.pipe(gulp.dest(`${distPath}/images/screenshots/thumbs`))
|
.pipe(gulp.dest(`${distPath}/images/screenshots/thumbs`))
|
||||||
));
|
));
|
||||||
|
|
||||||
gulp.task('html', ['hugo', 'css', 'js', 'images'], () => (
|
// This task ensures all phases up to PHASE 3 are completed.
|
||||||
|
gulp.task('build', ['hugo', 'css', 'images']);
|
||||||
|
|
||||||
|
// STAGE 4 - Optimization
|
||||||
|
gulp.task('compress', ['build'], () => (
|
||||||
|
gulp.src(`${distPath}/js/**/*.js`, {base: './'})
|
||||||
|
.pipe(md5(10, `${distPath}/**/*.html`))
|
||||||
|
.pipe(gulp.dest('./')),
|
||||||
gulp.src(`${distPath}/**/*.html`, {base: './'})
|
gulp.src(`${distPath}/**/*.html`, {base: './'})
|
||||||
.pipe(htmlmin({collapseWhitespace: true}))
|
.pipe(htmlmin({collapseWhitespace: true}))
|
||||||
|
.pipe(gulp.dest('./')),
|
||||||
|
gulp.src(`${distPath}/css/**/*.css`, {base: './'})
|
||||||
|
.pipe(cleanCSS())
|
||||||
|
.pipe(md5(10, `${distPath}/**/*.html`))
|
||||||
.pipe(gulp.dest('./'))
|
.pipe(gulp.dest('./'))
|
||||||
));
|
));
|
||||||
|
|
||||||
gulp.task('deploy', ['html'], () => {
|
// STAGE 5 - Deploy
|
||||||
|
|
||||||
|
// Used for Development
|
||||||
|
gulp.task('serve', ['build'], () => {
|
||||||
|
// Serve files from the root of this project
|
||||||
|
browsersync({
|
||||||
|
server: {
|
||||||
|
baseDir: distPath
|
||||||
|
},
|
||||||
|
open: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Used for Production
|
||||||
|
gulp.task('deploy', ['build', 'compress'], () => {
|
||||||
require('fs').writeFileSync(`${distPath}/CNAME`, `${cname}`);
|
require('fs').writeFileSync(`${distPath}/CNAME`, `${cname}`);
|
||||||
require('fs').writeFileSync(`${distPath}/robots.txt`, `Sitemap: https://${cname}/sitemap.xml\n\nUser-agent: *`);
|
require('fs').writeFileSync(`${distPath}/robots.txt`, `Sitemap: https://${cname}/sitemap.xml\n\nUser-agent: *`);
|
||||||
return gulp.src(`${distPath}/**/*`).pipe(ghPages(deployOptions));
|
return gulp.src(`${distPath}/**/*`).pipe(ghPages(deployOptions));
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "GPLv3",
|
"license": "GPLv3",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"browser-sync": "^2.18.12",
|
||||||
"gulp": "^3.9.1",
|
"gulp": "^3.9.1",
|
||||||
"gulp-clean-css": "^3.0.3",
|
"gulp-clean-css": "^3.0.3",
|
||||||
"gulp-gh-pages": "^0.5.4",
|
"gulp-gh-pages": "^0.5.4",
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
"gulp-md5-plus": "^0.2.5",
|
"gulp-md5-plus": "^0.2.5",
|
||||||
"gulp-postcss": "^7.0.0",
|
"gulp-postcss": "^7.0.0",
|
||||||
"gulp-rename": "^1.2.2",
|
"gulp-rename": "^1.2.2",
|
||||||
|
"gulp-util": "^3.0.8",
|
||||||
"postcss-cssnext": "^2.9.0",
|
"postcss-cssnext": "^2.9.0",
|
||||||
"postcss-import": "^8.2.0",
|
"postcss-import": "^8.2.0",
|
||||||
"rimraf": "^2.6.1"
|
"rimraf": "^2.6.1"
|
||||||
|
|
Reference in New Issue