-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
138 lines (137 loc) · 3.62 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// gulpfile.js
const { series, parallel, src, dest, watch } = require('gulp')
const mocha = require('gulp-mocha')
const tslint = require('gulp-tslint')
const rollup = require('rollup')
const rollupTypescript = require('@wessberg/rollup-plugin-ts')
const rollupNodeResolve = require('rollup-plugin-node-resolve')
const rollupCommonjs = require('rollup-plugin-commonjs')
const rollupSourceMaps = require('rollup-plugin-sourcemaps')
const terser = require('gulp-terser')
const del = require('del')
const pkg = require('./package.json')
const allFiles = ['src/**/*.ts', 'test/**/*.ts']
// Task functions
/**
* Bundle function
*/
function bundle() {
return rollup.rollup({
input: 'src/xydata.ts',
plugins: [
rollupTypescript({ typescript: require('typescript'), tsconfig: './tsconfig.json' }),
rollupCommonjs(),
rollupNodeResolve(),
rollupSourceMaps()
]
})
.then(bundle =>
Promise.all([
bundle.write({
file: pkg.main,
format: 'cjs',
exports: 'named',
sourcemap: true,
name: 'xydata'
}),
bundle.write({
file: pkg.module,
format: 'es',
exports: 'named',
sourcemap: true,
name: 'xydata'
}),
bundle.write({
file: pkg.iife,
format: 'iife',
exports: 'named',
sourcemap: true,
name: 'xydata'
})
])
)
}
/**
* Minify function
*/
function minify() {
return src([pkg.iife])
.pipe(terser({
mangle: {
toplevel: true,
reserved: [
'xydata'
],
properties: {
regex: /\b_\w*/,
keep_quoted: true
}
},
keep_classnames: false,
keep_fnames: false
}))
.pipe(dest('dist'))
}
/**
* Linting function
*/
function lint() {
return src(allFiles)
.pipe(tslint({
formatter: 'verbose'
}))
.pipe(tslint.report({ allowWarnings: true }))
}
// Lint watcher
const lintWatcher = () => watch(allFiles, series(lint))
const lintWatch = series(lint, lintWatcher)
/**
* Testing task
*/
function test() {
return src('./test/**/*.spec.ts', { read: false })
.pipe(mocha({
"timeout": 100000,
require: 'ts-node/register',
reporter: 'spec'
}))
}
/**
* Test watch functions
*/
const testWatcher = () => watch(allFiles, test)
const testWatch = series(test, testWatcher)
/**
* Cleaning function
*/
const clean = () => del('dist')
/**
* CI watch functions
*/
const ciWatcher = () => watch(allFiles, parallel(test, lint))
const ciWatch = series(parallel(test, lint), ciWatcher)
/**
* Building functions
*/
const build = series(clean, bundle, minify)
const buildWatcher = () => watch(allFiles, build)
const buildWatch = series(build, buildWatcher)
// Export functions for gulp CLI
// Start testing
exports.test = test
// Start test watching
exports.testWatch = testWatch
// Start linting
exports.lint = lint
// Start lint watching
exports.lintWatch = lintWatch
// Start CI watching
exports.ciWatch = ciWatch
// Clean folder with distribution
exports.clean = clean
// Build distribution
exports.build = build
// Start build watching
exports.buildWatch = buildWatch
// Default case: build distribution
exports.default = build