2016-07-21 17:33:50 +00:00
|
|
|
import gulp from "gulp";
|
2017-07-30 02:03:01 +00:00
|
|
|
import { spawn } from "child_process";
|
|
|
|
import hugoBin from "hugo-bin"
|
2016-07-21 17:33:50 +00:00
|
|
|
import gutil from "gulp-util";
|
|
|
|
import postcss from "gulp-postcss";
|
|
|
|
import cssImport from "postcss-import";
|
|
|
|
import cssnext from "postcss-cssnext";
|
|
|
|
import BrowserSync from "browser-sync";
|
|
|
|
import webpack from "webpack";
|
|
|
|
import webpackConfig from "./webpack.conf";
|
|
|
|
|
|
|
|
const browserSync = BrowserSync.create();
|
2016-09-01 14:59:24 +00:00
|
|
|
const defaultArgs = ["-d", "../dist", "-s", "site", "-v"];
|
2016-07-21 17:33:50 +00:00
|
|
|
|
2016-09-01 14:59:24 +00:00
|
|
|
gulp.task("hugo", (cb) => buildSite(cb));
|
|
|
|
gulp.task("hugo-preview", (cb) => buildSite(cb, ["--buildDrafts", "--buildFuture"]));
|
2016-07-03 22:07:47 +00:00
|
|
|
|
2016-07-21 17:33:50 +00:00
|
|
|
gulp.task("build", ["css", "js", "hugo"]);
|
2016-09-01 14:59:24 +00:00
|
|
|
gulp.task("build-preview", ["css", "js", "hugo-preview"]);
|
2016-07-03 22:07:47 +00:00
|
|
|
|
2016-07-21 17:33:50 +00:00
|
|
|
gulp.task("css", () => (
|
|
|
|
gulp.src("./src/css/*.css")
|
2017-04-14 15:40:53 +00:00
|
|
|
.pipe(postcss([cssImport({from: "./src/css/main.css"}), cssnext()]))
|
2016-08-09 22:38:45 +00:00
|
|
|
.pipe(gulp.dest("./dist/css"))
|
2016-07-21 17:33:50 +00:00
|
|
|
.pipe(browserSync.stream())
|
|
|
|
));
|
2016-07-03 22:07:47 +00:00
|
|
|
|
2016-07-21 17:33:50 +00:00
|
|
|
gulp.task("js", (cb) => {
|
2016-07-03 22:07:47 +00:00
|
|
|
const myConfig = Object.assign({}, webpackConfig);
|
|
|
|
|
|
|
|
webpack(myConfig, (err, stats) => {
|
2016-07-21 17:33:50 +00:00
|
|
|
if (err) throw new gutil.PluginError("webpack", err);
|
|
|
|
gutil.log("[webpack]", stats.toString({
|
2016-07-03 22:07:47 +00:00
|
|
|
colors: true,
|
|
|
|
progress: true
|
|
|
|
}));
|
2016-07-21 17:33:50 +00:00
|
|
|
browserSync.reload();
|
2016-07-03 22:07:47 +00:00
|
|
|
cb();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-07-21 17:33:50 +00:00
|
|
|
gulp.task("server", ["hugo", "css", "js"], () => {
|
|
|
|
browserSync.init({
|
|
|
|
server: {
|
|
|
|
baseDir: "./dist"
|
2016-07-05 18:38:18 +00:00
|
|
|
}
|
2016-07-21 17:33:50 +00:00
|
|
|
});
|
|
|
|
gulp.watch("./src/js/**/*.js", ["js"]);
|
|
|
|
gulp.watch("./src/css/**/*.css", ["css"]);
|
|
|
|
gulp.watch("./site/**/*", ["hugo"]);
|
2016-07-03 22:07:47 +00:00
|
|
|
});
|
2016-09-01 14:59:24 +00:00
|
|
|
|
|
|
|
function buildSite(cb, options) {
|
|
|
|
const args = options ? defaultArgs.concat(options) : defaultArgs;
|
|
|
|
|
2017-07-30 02:03:01 +00:00
|
|
|
return spawn(hugoBin, args, {stdio: "inherit"}).on("close", (code) => {
|
2016-10-19 05:40:29 +00:00
|
|
|
if (code === 0) {
|
|
|
|
browserSync.reload();
|
|
|
|
cb();
|
|
|
|
} else {
|
|
|
|
browserSync.notify("Hugo build failed :(");
|
|
|
|
cb("Hugo build failed");
|
|
|
|
}
|
2016-09-01 14:59:24 +00:00
|
|
|
});
|
|
|
|
}
|