This repository has been archived by the owner on Jun 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
119 lines (108 loc) · 2.18 KB
/
gulpfile.ts
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
109
110
111
112
113
114
115
116
117
118
119
// @ts-check
/** Import project dependencies */
import * as del from 'del';
import * as gulp from 'gulp';
import * as babel from 'gulp-babel';
import * as sq from 'gulp-sequence';
import lint from 'gulp-tslint';
import * as ts from 'gulp-typescript';
import * as tslint from 'tslint';
/** Setting up */
const isProd = process.env.NODE_ENV === 'production';
const SRC = 'src';
const TMP = '.tmp';
const DIST = '.';
const IGNORE_DIR = [
`${SRC}/demo`,
];
const BABELRC = {
presets: [
[
'env',
{
targets: {
node: 'current',
},
spec: true,
modules: 'commonjs',
useBuiltIns: true,
},
],
...(isProd ? [
[
'minify',
{
replace: false,
removeConsole: false,
removeDebugger: true,
},
],
] : []),
],
plugins: [
['transform-object-rest-spread', { useBuiltIns: true }],
],
ignore: isProd
? [
'**/__mocks*__/*.js',
'**/__tests*__/*.dist.spec.js',
'**/__tests*__/*.spec.js',
]
: [],
};
gulp.task('lint', () =>
gulp.src([
`${SRC}/**/*.ts`,
`${SRC}/**/*.tsx`,
])
.pipe(lint({
configuration: `./tslint${
isProd ? '.prod' : ''
}.json`,
formatter: 'stylish',
program: tslint.Linter.createProgram('./tsconfig.json'),
}))
.pipe(lint.report()));
gulp.task('ts', () =>
gulp.src([
`${SRC}/**/*.ts*`,
...IGNORE_DIR.map(n => `${isProd ? '!' : ''}${n}/**/*.ts*`),
])
.pipe(ts.createProject('./tsconfig.json')())
.pipe(gulp.dest(TMP)));
gulp.task('babel', () =>
gulp.src([
`${TMP}/**/*.js`,
])
.pipe(babel(BABELRC))
.pipe(gulp.dest(DIST)));
gulp.task('clean', () => del([
TMP,
'*.js',
'*.jsx',
'*.d.ts*',
'test/',
'demo/',
]));
gulp.task('clear', () => del([
TMP,
'./gulpfile.js',
]));
gulp.task('copy', () => gulp.src([
`${TMP}/**/*`,
`!${TMP}/**/*.js`,
])
.pipe(gulp.dest(DIST)));
gulp.task('watch', () => {
gulp.watch([
`${SRC}/**/*.ts`,
`${SRC}/**/*.tsx`,
], ['build']);
});
gulp.task('build', ['clean'], cb => sq(...[
'lint',
'ts',
['babel', 'copy'],
'clear',
])(cb));
gulp.task('default', ['watch'], sq('build'));