-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
74 lines (59 loc) · 1.83 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
var gulp = require("gulp");
var spawn = require('child_process').spawn;
let {Deploy} = require("./src/build/deploy");
function createStylusCompiler() {
return require("./src/build/stylus-compiler").createCompiler({
container: {
dir: `src/server/public/assets/styl`,
file: "style.styl",
},
lookupDirs: [
`src/client`
],
distDir: `dist/css/client`,
});
}
const stylusCompiler = createStylusCompiler();
gulp.task("build:watch", () => {
stylusCompiler.watch();
cmd("webpack --watch --mode development");
});
function cmd(cmd, options = {
stdio: "inherit",
// stdio: "ignore"
}) {
return new Promise((resolve, reject) => {
let split = cmd.split(" ");
const spawnOptions = !/^win/.test(process.platform) ? [split[0], split.slice(1), options] : ['cmd', ['/s', "/c", ...split], options];
let p = spawn(...spawnOptions);
p.on("close", (a, b) => {
// console.log(a, b)
resolve();
});
});
}
gulp.task("dev", ["build:watch"], () => {
require("./src/server/server");
});
gulp.task("deploy", [], () => {
(()=> {
return new Promise((resolve, reject) => {
let ps;
if (!/^win/.test(process.platform)) { // linux
ps = spawn("webpack", "-p".split(" "), {stdio: "inherit"});
} else {
ps = spawn('cmd', ['/s', "/c", "webpack"].concat("-p".split(" ")), {stdio: "inherit"});
}
ps.on('close', (code) => {
if (code !== 0) {
console.log(`ps process exited with code ${code}`);
reject(code);
} else {
resolve();
}
});
});
})().then(() => {
Deploy.doDeploy();
});
});