generated from bitmodo/node-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ts
80 lines (61 loc) · 1.89 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
import { src, dest, watch, parallel } from 'gulp';
import { init as smInit, write as smWrite } from 'gulp-sourcemaps';
import { createProject } from 'gulp-typescript';
import minimist = require('minimist');
import gulpIf = require('gulp-if');
import mocha = require('gulp-mocha');
const eslint = require('gulp-eslint');
// Constants
const args = minimist(process.argv.slice(2), {
string: [
'env'
],
boolean: [
'production',
'development'
],
alias: {
production: ['prod', 'p'],
development: ['dev', 'd']
},
default: {
env: (process.env.NODE_ENV || 'production').trim().toLowerCase(),
production: false,
development: false
},
});
// const production = (args.env === 'production' || args.env === 'prod' || args.production) && !args.development;
const development = (args.env === 'development' || args.env === 'dev' || args.development) && !args.production;
const tsProject = createProject('tsconfig.json');
// Regular tasks
function ts() {
return tsProject.src()
.pipe(gulpIf(development, smInit({ loadMaps: true })))
.pipe(tsProject())
.pipe(gulpIf(development, smWrite()))
.pipe(dest('dist'));
}
function lintTs() {
return src('lib/**/*.ts')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
function testTs() {
return src('test/**/*.ts')
.pipe(mocha());
}
// Watch functions
function watchTs() {
return watch('lib/**/*.ts', ts);
}
// Task exports
exports.ts = ts;
exports.build = parallel(exports.ts);
exports.lintTs = lintTs;
exports.lint = parallel(exports.lintTs);
exports.testTs = testTs;
exports.test = parallel(exports.testTs);
exports.watchTs = watchTs;
exports.watch = parallel(exports.watchTs);
exports.default = exports.build;