-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool.js
80 lines (74 loc) · 1.89 KB
/
tool.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
const gulp = require('gulp');
const gulpClean = require('gulp-clean');
const gulpConcat = require('gulp-concat');
const read = gulp.src;
const save = gulp.dest;
const task = process.argv[2];
const arch = process.argv[3];
console.log(
'\x1B[36m%s\x1B[0m',
`
-------------------------------
command: ${task}, arch: ${arch || 'amd64'}
-------------------------------
`
);
function catchError(err) {
const noSuchArch = err.toString().search('File not found') > -1;
if (noSuchArch) {
console.error(
'\x1B[31m%s\x1B[39m',
`
-------------------------------------------------
No matching arch: ${arch}, docker file not found.
-------------------------------------------------
`
);
} else {
console.error(err);
}
throw `
-------------------------
No matching arch: ${arch}
-------------------------
`;
}
/** Clean all dist folder. */
async function clean() {
read(
[
'client/dist',
'server/dist',
'dist'
],
{ allowEmpty: true }
)
.pipe(gulpClean());
}
/** Build and pack application. */
async function pack(arch) {
const suffix = arch ? `.${arch}` : '';
// read(`docker/config/**/*`)
// .pipe(save('dist/config'));
// read(`docker/server/Dockerfile${suffix}`)
// .on('error', catchError)
// .pipe(gulpConcat('Dockerfile'))
// .pipe(save('dist/server'));
// read(`docker/docker-compose${suffix}.yml`)
// .on('error', catchError)
// .pipe(gulpConcat('docker-compose.yml'))
// .pipe(save('dist'));
read(`docker/**/*`).pipe(save('dist'));
read(`client/dist/**/*`).pipe(save('dist/client'));
read([
'server/dist/**/*.js',
'server/package*.json',
'server/rester.json'
], { allowEmpty: true }
).pipe(save('dist/server'));
}
switch (task.toLowerCase()) {
case 'clean': clean(); break;
case 'pack': pack(arch); break;
default: console.error('Task: clean or pack.'); break;
}