-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (87 loc) · 2.33 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
// @ts-check
/** Import project dependencies */
const del = require('del');
const gulp = require('gulp');
const gulpBabel = require('gulp-babel');
const gulpFilter = require('gulp-filter');
const gulpIf = require('gulp-if');
const gulpRename = require('gulp-rename');
const gulpTslint = require('gulp-tslint').default;
const gulpTs = require('gulp-typescript');
const { Linter } = require('tslint');
/** Setting up */
const srcPath = 'src';
const distPath = '.';
const ignores = ['**/demo*', '**/test*'];
const isProd = process.env.NODE_ENV === 'production';
const tslintConfig = `./tslint${isProd ? '.prod' : ''}.json`;
const tsconfig = './tsconfig.json';
const compile = (esm) => {
const filterFn = gulpFilter([
'**',
'!**/*.d.ts',
], { restore: true });
const src = [
`${srcPath}/**/*.ts*`,
'!**/*.d.ts',
...ignores.map(n => `!${n}/**/*.ts*`),
];
return gulp.src(src, { since: gulp.lastRun(compile) })
.pipe(gulpTs.createProject(tsconfig)())
.pipe(filterFn)
// @ts-ignore
.pipe(gulpBabel({
presets: [
['@babel/preset-env', {
targets: { node: 'current' },
spec: true,
modules: esm ? false : 'commonjs',
useBuiltIns: 'usage',
shippedProposals: true,
}],
...(
isProd
? [['minify', {
mangle: { keepFnName: true },
deadcode: { keepFnName: true },
removeConsole: false,
removeDebugger: true,
}]]
: []
),
],
}))
.pipe(gulpIf(esm, gulpRename({ extname: '.mjs' })))
.pipe(filterFn.restore)
.pipe(gulp.dest(distPath));
}
gulp.task('clean', () => {
return del([
'./*.@(mj|j)s',
'./*.d.ts',
'!./gulpfile.js',
'!./json.d.ts',
]);
});
gulp.task('lint', function lint() {
return gulp.src([
`${srcPath}/**/*.ts*`,
'!**/*.d.ts',
...ignores.map(n => `!${n}/**/*.ts*`),
], {
since: gulp.lastRun(lint),
})
.pipe(gulpTslint({
configuration: tslintConfig,
formatter: 'stylish',
program: Linter.createProgram(tsconfig),
}))
.pipe(gulpTslint.report());
});
gulp.task('esm', function esm() { return compile(true); });
gulp.task('js', function js() { return compile(false); });
gulp.task('default', gulp.series(...[
'clean',
'lint',
gulp.parallel('esm', 'js'),
]));