-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
58 lines (46 loc) · 1.27 KB
/
Copy pathgulpfile.js
File metadata and controls
58 lines (46 loc) · 1.27 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
const gulp = require('gulp')
const ts = require('gulp-typescript')
const spawn = require('child_process').spawn
let node
async function startServer() {
if (node) { node.kill() }
node = await spawn("node", ["./dist/server.js"], { stdio: "inherit" })
node.on("close", function (code) {
if (code === 8) {
console.log("Error detected, waiting for changes...")
}
})
}
// Pull in the project TypeScript config
const tsProject = ts.createProject('tsconfig.json')
var otherfiles = [
'./src/assets/*.*'
]
gulp.task('killServer', (resolve) => {
if (node) { node.kill() }
resolve()
})
gulp.task('assets', () => {
return gulp.src(otherfiles)
.pipe(gulp.dest('dist/assets'))
})
gulp.task('scripts', () => {
const tsResult = tsProject.src()
.pipe(tsProject())
return tsResult.js.pipe(gulp.dest('dist'))
})
gulp.task('startServer', () => {
return startServer()
})
// Start or develop, with watcher
gulp.task('start', gulp.series('killServer', 'assets', 'scripts', 'startServer'))
gulp.task('develop',
gulp.series('killServer', 'assets', 'scripts', 'startServer'),
() => {
gulp.watch(['src/assets/*.*', 'src/**/*.ts'], gulp.series('killServer', 'assets', 'scripts', 'startServer'))
})
process.on('exit', () => {
if (node) {
node.kill()
}
})