Merge pull request #3 from netlify/add_deploy_context
Add deploy preview context.
This commit is contained in:
commit
d750ef3af8
|
@ -10,20 +10,13 @@ import webpackConfig from "./webpack.conf";
|
||||||
|
|
||||||
const browserSync = BrowserSync.create();
|
const browserSync = BrowserSync.create();
|
||||||
const hugoBin = "hugo";
|
const hugoBin = "hugo";
|
||||||
|
const defaultArgs = ["-d", "../dist", "-s", "site", "-v"];
|
||||||
|
|
||||||
gulp.task("hugo", (cb) => {
|
gulp.task("hugo", (cb) => buildSite(cb));
|
||||||
const args = ["-d", "../dist", "-s", "site", "-v"];
|
gulp.task("hugo-preview", (cb) => buildSite(cb, ["--buildDrafts", "--buildFuture"]));
|
||||||
return cp.spawn(hugoBin, args, {stdio: "inherit"}).on("close", (code) => {
|
|
||||||
if (code === 0) {
|
|
||||||
browserSync.reload();
|
|
||||||
} else {
|
|
||||||
browserSync.notify("Hugo build failed :(");
|
|
||||||
}
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task("build", ["css", "js", "hugo"]);
|
gulp.task("build", ["css", "js", "hugo"]);
|
||||||
|
gulp.task("build-preview", ["css", "js", "hugo-preview"]);
|
||||||
|
|
||||||
gulp.task("css", () => (
|
gulp.task("css", () => (
|
||||||
gulp.src("./src/css/*.css")
|
gulp.src("./src/css/*.css")
|
||||||
|
@ -56,3 +49,12 @@ gulp.task("server", ["hugo", "css", "js"], () => {
|
||||||
gulp.watch("./src/css/**/*.css", ["css"]);
|
gulp.watch("./src/css/**/*.css", ["css"]);
|
||||||
gulp.watch("./site/**/*", ["hugo"]);
|
gulp.watch("./site/**/*", ["hugo"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function buildSite(cb, options) {
|
||||||
|
const args = options ? defaultArgs.concat(options) : defaultArgs;
|
||||||
|
|
||||||
|
return cp.spawn(hugoBin, args, {stdio: "inherit"}).on("close", () => {
|
||||||
|
browserSync.reload();
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
[build]
|
[build]
|
||||||
command = "npm run build"
|
command = "npm run build"
|
||||||
publish = "dist"
|
publish = "dist"
|
||||||
|
|
||||||
|
[context.deploy-preview]
|
||||||
|
command = "npm run build-preview"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"hugo": "gulp hugo",
|
"hugo": "gulp hugo",
|
||||||
"webpack": "gulp webpack",
|
"webpack": "gulp webpack",
|
||||||
"build": "gulp build",
|
"build": "gulp build",
|
||||||
|
"build-preview": "gulp build-preview",
|
||||||
"start": "gulp server",
|
"start": "gulp server",
|
||||||
"lint": "eslint src"
|
"lint": "eslint src"
|
||||||
},
|
},
|
||||||
|
|
Reference in New Issue