-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
99 lines (89 loc) · 2.42 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
87
88
89
90
91
92
93
94
95
96
97
98
99
const { series, dest, src } = require('gulp')
const child_process = require('child_process')
const path = require('path')
const del = require('del')
// const rename = require('gulp-rename');
// const data = require('gulp-data');
// const mustache = require('gulp-mustache');
// const clone = require('gulp-clone');
// const fs = require('fs');
// const uglify = require('gulp-uglify');
// const mergeStreams = require('merge-stream');
// const less = require('gulp-less');
const ts = require('gulp-typescript')
// const { setTimeout } = require("timers/promises");
const tsProject = ts.createProject('tsconfig.json')
const ROOT = path.join(__dirname, '..', '..')
function mainTs() {
return tsProject.src()
.pipe(tsProject())
.js.pipe(dest('lib'))
}
async function clean() {
await del('lib')
console.log('del finished')
}
async function build(cb) {
console.log('run build')
await clean()
console.log('building ts ...')
// series(build_injected_script, static_resource, mainTs)()
series(static_resource, mainTs)()
// series(mainTs,client_scripts,temporaryJob)()
return cb()
}
async function build_injected_script(cb) {
const watchMode = process.argv.slice(2).includes('--watch')
const webPackFiles = [
'src/server/injected/webpack.config.js',
'src/web/recorder/webpack.config.js',
]
for (const file of webPackFiles) {
const step = {
command: 'npx',
args: ['webpack', '--config', quotePath(file), ...(watchMode ? ['--watch', '--stats', 'none'] : [])],
shell: true,
env: {
NODE_ENV: watchMode ? 'development' : 'production',
},
}
runStep(step)
}
return cb
}
function runStep(step) {
const out = child_process.spawnSync(step.command, step.args, {
stdio: 'inherit',
shell: step.shell,
env: {
...process.env,
...step.env,
},
cwd: step.cwd,
})
if (out.status) {
process.exit(out.status)
}
}
/**
* @param {string} path
* @returns {string}
*/
function quotePath(path) {
return `"${path}"`
}
/**
* @param {string} relative
* @returns {string}
*/
function filePath(relative) {
return path.join(ROOT, ...relative.split('/'))
}
function static_resource() {
return src([
'src/**/*.json',
'src/**/*.png',
])
.pipe(dest('lib'))
}
exports.default = build