-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ts
77 lines (67 loc) · 1.77 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
import {Levels, Log} from '@toreda/log';
import {Build} from '@toreda/build-tools';
import {EventEmitter} from 'events';
import {series} from 'gulp';
// Using require in a ts file is bad practice and not ideal here.
import {webpack} from 'webpack';
import webpackConfig from './webpack.config';
const build: Build = new Build({
events: new EventEmitter(),
log: new Log({
consoleEnabled: true,
globalLevel: Levels.ALL
})
});
/**
* Run ESLint using a helper from `@toreda/build-tools`.
* @returns
*/
function runLint(): Promise<NodeJS.ReadWriteStream> {
return build.gulpSteps.lint({
formatterId: 'stylish',
srcPatterns: ['src/**']
});
}
/**
* Create dist directory before build.
* @returns
*/
function createDist(): Promise<NodeJS.ReadWriteStream> {
return build.gulpSteps.createDir('./dist', true);
}
/**
* Remove everything in dist directory before build starts.
* @returns
*/
function cleanDist(): Promise<NodeJS.ReadWriteStream> {
return build.gulpSteps.cleanDir('./dist', true);
}
function buildSrc(): Promise<NodeJS.ReadWriteStream> {
return build.run.typescript('./dist', 'tsconfig.json');
}
/**
* Build the project webpack bundle.
* @returns
*/
function runWebpack(): any {
return new Promise((resolve, reject) => {
webpack(webpackConfig, (err, stats) => {
if (err) {
console.error(`webpack build failed: ${err.message}.`);
return reject(err);
}
if (!stats) {
return reject(new Error(`webpack failure - stats arg is missing in build callback`));
}
if (stats.hasErrors()) {
const errors: string[] = [];
stats.compilation.errors.forEach((error) => {
errors.push(error.message);
});
return reject(errors.join('\n'));
}
resolve(true);
});
});
}
exports.default = series(createDist, cleanDist, runLint, runWebpack);