-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Gulpfile.js
108 lines (86 loc) · 2.21 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
100
101
102
103
104
105
106
107
108
// @ts-check
const childProcess = require('child_process');
const fs = require('fs');
const path = require('path');
const ts = require('gulp-typescript');
const gulp = require('gulp');
const clean = require('gulp-clean');
const { join } = require('path');
const debug = require('gulp-debug');
const { promisify } = require('util');
const exec = promisify(childProcess.exec);
/**
* SETTINGS
*/
const DIST = join(__dirname, 'dist');
const LIB = join(__dirname, 'lib');
const SAMPLE = join(__dirname, 'sample/deprecated/');
const terminus = ts.createProject(join(__dirname, 'tsconfig.json'));
/**
* UTIL
*/
function getFolders(dir) {
return fs
.readdirSync(dir)
.filter((file) => fs.statSync(path.join(dir, file)).isDirectory());
}
const getDirs = (base) => getFolders(base).map((path) => `${base}/${path}`);
/**
* TASK
*/
gulp.task('clean', () => {
return gulp
.src(
[DIST, SAMPLE + '/*/node_modules/@nestjs/terminus', SAMPLE + '/*/dist'],
{
allowEmpty: true,
},
)
.pipe(clean());
});
gulp.task('move:protos', () => {
return gulp
.src(join(LIB, './**/*.proto'), { base: LIB })
.pipe(debug({ title: 'move:protos' }))
.pipe(gulp.dest(join(DIST)));
});
gulp.task('build', () => {
return terminus.src().pipe(terminus()).pipe(gulp.dest(DIST));
});
gulp.task('move', () => {
const directories = getDirs(SAMPLE);
let stream = gulp.src(['dist/**/*']);
directories.forEach((dir) => {
stream = stream.pipe(gulp.dest(dir + '/node_modules/@nestjs/terminus'));
});
return stream;
});
gulp.task('install:sample', async () => {
const directories = getDirs(SAMPLE);
const promises = directories.map((dir) =>
exec(`npm install --prefix ${dir}`),
);
return await Promise.all(promises);
});
gulp.task('build:sample', async () => {
const directories = getDirs(SAMPLE);
const promises = directories.map((dir) =>
exec(`npm run build --prefix ${dir}`),
);
return await Promise.all(promises);
});
/**
* Aliases
*/
gulp.task('default', gulp.series(['clean', 'build']));
gulp.task('build:app', gulp.series(['default']));
gulp.task(
'build:all',
gulp.series([
'build:app',
'install:sample',
'move:protos',
'move',
'build:sample',
]),
);