-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
46 lines (37 loc) · 1.19 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
var gulp = require('gulp');
var fs = require('fs-extra');
var path = require('path');
var spawn = require('child_process').spawn;
var del = require('del');
const os = require('os');
const BUILD_DIR = path.join(__dirname, './lib/');
const tsc = (cb) => {
spawn(path.normalize(`./node_modules/.bin/tsc${/^win/.test(os.platform()) ? '.cmd' : ''}`), ['-p', 'tsconfig.json'], {
stdio: 'inherit'
}).on('close', function (err) {
if (err) {
var err = new Error('TSC failed');
err.showStack = false;
cb(err);
} else {
cb();
}
});
}
const cleanup = (cb) => {
if (fs.existsSync(BUILD_DIR)) del.sync(BUILD_DIR, {force: true})
cb()
}
const distribute = (src, dest) => {
return gulp.src(src).
pipe(gulp.dest(`${BUILD_DIR + (dest || '')}`));
}
const addPackageJson = () => distribute('package.json');
const addTemplates = () => distribute('./src/templates/**', 'templates');
const addWatcher = () => {
return gulp.watch('./src', tsc)
}
const appendFiles = gulp.parallel(addPackageJson, addTemplates)
const build = gulp.series(cleanup, tsc, appendFiles)
exports.watch = addWatcher;
exports.default = build;