1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
const gulp = require("gulp");
const del = require("del");
const htmlmin = require("gulp-htmlmin");
const spawn = require("child_process").spawn;
const target = "public";
gulp.task("build", (cb) => {
del([ target ]);
const hugo = spawn("hugo", ["-t", "einfach"], {stdio: "inherit"});
hugo.on("exit", function (code) {cb(code === 0?null : 'ERROR: Hugo process exited with code: ' + code)});
});
gulp.task("minify-html", () => {
const minOptions = {
collapseWhitespace: true,
caseSensitive: true,
minifyCSS: true,
minifyJS: true
};
return gulp.src(`${target}/**/*.html`)
.pipe(htmlmin(minOptions))
.pipe(gulp.dest(target));
});
gulp.task("sync", (cb) => {
const sync = spawn("aws", ["s3", "sync", "./public/", "s3://joeyliu.net", "--acl", "public-read", "--cache-control", "public,no-cache,max-age=604800", "--delete"], {stdio: "inherit"})
sync.on("exit", function (code) {cb(code === 0 || code === 255 ? null : "ERROR: aws s3 sync process exited with code: " + code)})
});
gulp.task("clean-cache", (cb) => {
const sync = spawn("aws", ["cloudfront", "create-invalidation", "--distribution-id", "EKCKL2MN34GEY", "--paths", "/*"], {stdio: "inherit"})
sync.on("exit", function (code) {cb(code === 0 || code === 255 ? null : "ERROR: aws s3 sync process exited with code: " + code)})
});
gulp.task("build:minify", gulp.series("build", "minify-html"));
gulp.task("deploy", gulp.series("sync", "clean-cache"));
|