forked from yuzu-emu/yuzu-emu.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
86 lines (74 loc) · 2.58 KB
/
gulpfile.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const fs = require('fs');
const { spawnSync } = require("child_process");
const gulp = require('gulp');
const log = require('fancy-log');
const parseArgs = require('minimist');
const hugoDefaultArgs = ["-s", "./site/", "-d", "../build", "-v", "--gc"];
// Gulp Run Tasks
gulp.task('scripts:compatdb', function (callback) {
callback(
spawnSync("yarn", ["run", "compatdb"], { cwd: "./scripts/shared-hugo-scripts/" }).error
);
});
gulp.task('scripts:wiki', function (callback) {
callback(
spawnSync("yarn", ["run", "wiki"], { cwd: "./scripts/shared-hugo-scripts/" }).error
);
});
gulp.task('hugo', (callback) => {
import('hugo-bin').then((hugo) => {
const result = spawnSync(hugo.default, hugoDefaultArgs, {
stdio: "inherit",
});
if (result.status !== 0) {
log.error(result.error);
callback(new Error("Hugo build failed"));
return;
}
callback();
});
});
gulp.task('final:serve', (done) => {
import('hugo-bin').then((hugo) => {
let args = hugoDefaultArgs;
args.push("server");
const result = spawnSync(hugo.default, args, {
stdio: "inherit",
});
if (result.status !== 0) {
log.error(result.error);
callback(new Error("Failed to start Hugo preview server"));
return;
}
callback();
});
done();
});
gulp.task('final:publish', (done) => {
fs.writeFileSync('build/CNAME', `${cname}`);
fs.writeFileSync('build/robots.txt', `Sitemap: https://${cname}/sitemap.xml\n\nUser-agent: *`);
done();
});
const cname = 'yuzu-emu.org';
let finalCommand = null;
let ephemeralURL = null;
if (parseArgs(process.argv).production) {
process.env.NODE_ENV = 'production';
process.env.HUGO_ENV = 'PRD';
process.env.HUGO_BASEURL = `https://${cname}`;
finalCommand = 'final:publish';
} else if ((ephemeralURL = parseArgs(process.argv).ephemeral)) {
process.env.NODE_ENV = 'production';
process.env.HUGO_ENV = 'PRD';
process.env.HUGO_BASEURL = ephemeralURL;
finalCommand = 'final:publish';
} else {
process.env.HUGO_ENV = 'DEV';
process.env.HUGO_BASEURL = 'http://localhost:3000';
finalCommand = 'final:serve';
}
log.info(`process.env.HUGO_ENV = '${process.env.HUGO_ENV}'`);
log.info(`process.env.HUGO_BASEURL = '${process.env.HUGO_BASEURL}'`);
gulp.task('default', gulp.series('hugo', finalCommand));
gulp.task('all', gulp.series(gulp.parallel('scripts:compatdb', 'scripts:wiki'), 'hugo', finalCommand));
gulp.task('content', gulp.series('hugo', finalCommand));