-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
83 lines (66 loc) · 2.04 KB
/
gulpfile.js
File metadata and controls
83 lines (66 loc) · 2.04 KB
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
const { src, dest, series, parallel } = require('gulp');
var { exec, spawn } = require('child_process');
const del = require('del');
let loggedSpawn = function(cb, ...args) {
let spawnObject = spawn(...args);
spawnObject.stdout.on('data', data => {
console.log(`${data}`);
});
spawnObject.stderr.on('data', data => {
console.error(`${data}`);
});
if (cb) {
spawnObject.on('exit', () => {cb();});
}
return spawnObject;
}
function appendForWindows(command) {
return (process.platform === 'win32') ? `${command}.cmd` : command
}
function clean(cb) {
// We clean both client and server
del.sync('./dist/**');
cb();
};
function buildServer(cb) {
exec("tsc -p tsconfig.server.json", err => {
if (err) console.error(err);
cb();
})
}
function buildClient(cb) {
let npxCmd = (process.platform === 'win32') ? 'npx.cmd' : 'npx';
exec(`${npxCmd} webpack --config webpack.prod.js`, err => {
if (err) console.error(err);
cb();
});
}
function runServer(cb) {
loggedSpawn(cb, appendForWindows('nodemon'), [ '.\\dist\\server\\index.js']);
}
function buildWatchedServer(cb) {
// We need to suffix .cmd after it to make it work for windows32
let serverSpawn = spawn(appendForWindows('tsc'), ['-p', 'tsconfig.server.json', '--watch']);
serverSpawn.on('exit', () => {cb();});
}
function runWatchedClient(cb) {
loggedSpawn(cb, appendForWindows('.\\node_modules\\.bin\\webpack-dev-server'), ['--config', 'webpack.dev.js']);
}
// .\node_modules\.bin\webpack-dev-server
exports.clean = clean;
exports.buildClient = buildClient;
exports.buildServer = buildServer;
exports.build = parallel(buildClient, buildServer);
exports.runWatchedServer = series(buildServer, parallel(runServer, buildWatchedServer));
exports.runWatchedClient = runWatchedClient;
exports.watch = parallel(
series(
buildServer,
parallel(
runServer,
buildWatchedServer
)
),
runWatchedClient
);
exports.runServer = runServer;