-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.babel.js
111 lines (98 loc) · 2.95 KB
/
gulpfile.babel.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import gulp from "gulp";
import ts from "gulp-typescript";
import chalk from "chalk";
// noinspection NpmUsedModulesInstalled
import del from "del";
// noinspection ES6CheckImport
import pm2 from "pm2";
let log = {
server: false,
client: false
};
const tsProject = ts.createProject("tsconfig.json");
export const clean = () => del(["server/**/*.js"]);
export function compile() {
// noinspection JSCheckFunctionSignatures
let tsResult = gulp.src("server/**/*.ts").pipe(tsProject());
return tsResult.js.pipe(gulp.dest("server"));
}
const restart = () => {
return new Promise((resolve) => {
pm2.connect(true, function () {
pm2.restart("server", () => {
pm2.restart("client", () => {
resolve()
});
});
})
});
};
/**
* Moment docs
* https://momentjs.com/docs/#/displaying/
*/
export function pm2server() {
return new Promise((resolve) => {
pm2.connect(function () {
pm2.start({
name: "server",
script: "server/index.js",
color: true,
env: {
"NODE_ENV": "development"
}
}, function () {
if (!log.server) {
log.server = true;
pm2.streamLogs("server", 0, false, "dddd, MMMM Do YYYY, h:mm:ss a x");
}
resolve()
});
})
});
}
export function pm2client() {
return new Promise((resolve) => {
pm2.connect(function () {
pm2.start({
name: "client",
script: "webpack-dev-server",
color: true,
env: {
"NODE_ENV": "development"
}
}, function () {
if (!log.client) {
log.client = true;
pm2.streamLogs("client", 0, false, "dddd, MMMM Do YYYY, h:mm:ss a x");
}
resolve()
});
})
});
}
export const dev = gulp.series(clean, compile, gulp.parallel(pm2client, pm2server));
// noinspection JSUnusedGlobalSymbols
export function kill() {
return new Promise((resolve) => {
pm2.connect(function () {
pm2.stop("server", function () {
console.log(chalk.green("Killing PM2"));
console.log("PM2 Stopped for Server");
pm2.stop("client", function () {
console.log("PM2 Stopped for Client");
pm2.disconnect();
resolve();
});
});
});
})
}
function watcher() {
// noinspection JSCheckFunctionSignatures
gulp.watch("server/**/*.ts", gulp.series(clean, compile, restart), () => {
});
}
// noinspection JSUnusedGlobalSymbols
// export const watch = gulp.task("watch", gulp.series(dev, watcher));
gulp.task("default", gulp.series(dev, watcher));