-
Notifications
You must be signed in to change notification settings - Fork 28
/
gulpfile.js
70 lines (62 loc) · 1.74 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
const { src, dest, series, watch } = require('gulp');
const gulpTypescript = require('gulp-typescript');
const del = require('del');
const rename = require('gulp-rename');
const eslint = require('gulp-eslint');
const cache = require('gulp-cached');
const remember = require('gulp-remember');
const uglify = require('gulp-uglify');
const dir = require('path').resolve(process.cwd(), 'packages', process.env.DIR);
function buildTs() {
const tsProject = gulpTypescript.createProject(`${dir}/tsconfig.json`);
return src(`${dir}/src/**/*.ts`)
.pipe(cache('build-ts'))
.pipe(tsProject())
.pipe(
rename((path) => {
path.dirname = path.dirname.replace(`${dir}/src`, `${dir}/lib`);
}),
)
.pipe(remember('build-ts'))
.pipe(dest(`${dir}/lib`));
}
function uglifyJS() {
return src(`${dir}/lib/**/*.js`)
.pipe(
uglify({
output: { indent_level: 0 },
}),
)
.pipe(dest(`${dir}/lib`));
}
function moveJSON() {
return src(`${dir}/src/**/*.json`).pipe(dest(`${dir}/lib`));
}
function clean(cb) {
del(`${dir}/lib`).then(() => cb());
}
function buildPackages() {
return series(buildTs, moveJSON);
}
function lint() {
return src(`${dir}/src/**/*.ts`)
.pipe(cache('linting'))
.pipe(
eslint({
quiet: false,
fix: true,
}),
)
.pipe(eslint.format())
.pipe(remember('linting'))
.pipe(eslint.failAfterError());
}
function watchTask() {
watch(`${dir}/src/**/*.ts`, series(lint));
watch(`${dir}/src/**/*.ts`, series(buildTs));
watch(`${dir}/src/**/*.json`, series(moveJSON));
}
exports.default = series(clean, buildPackages(), lint, watchTask);
exports.clean = clean;
exports.build = series(clean, buildPackages(), lint, uglifyJS);
exports.lint = lint;