-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgulpfile.js
More file actions
74 lines (61 loc) · 1.76 KB
/
gulpfile.js
File metadata and controls
74 lines (61 loc) · 1.76 KB
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
import gulpESLintNew from 'gulp-eslint-new';
import gulp from 'gulp';
import gulpcache from 'gulp-cached';
import gulpClean from 'gulp-clean';
import { Logger } from '@btc-vision/logger';
import ts from 'gulp-typescript';
import { Transform } from 'stream';
process.on('uncaughtException', function (err) {
console.log('Caught exception: ', err);
});
class GulpLogger extends Logger {
moduleName = 'Compiler';
logColor = '#4f77f9';
}
const logger = new GulpLogger();
process.on('uncaughtException', function (err) {
console.log('Caught exception: ', err);
});
function onError(e) {
logger.error(String(e));
}
function logPipe(before, after, extname) {
let started = false;
return new Transform({
objectMode: true,
transform(file, _enc, cb) {
if (!started) {
logger.log(before);
started = true;
}
if (file.relative) {
logger.log(`${file.relative}${extname ? ` -> ${extname}` : ''}`);
}
cb(null, file);
},
flush(cb) {
logger.success(after);
cb();
},
});
}
const tsProject = ts.createProject('tsconfig.build.json');
function buildESM() {
return tsProject
.src()
.on('error', onError)
.pipe(gulpcache())
.pipe(logPipe('Starting...', 'Project compiled!', '.js'))
.pipe(gulpESLintNew())
.pipe(gulpESLintNew.format())
.pipe(tsProject())
.pipe(gulp.dest('build'));
}
export async function clean() {
return gulp.src('./build/src', { read: false }).pipe(gulpClean());
}
export const build = buildESM;
export default build;
export function watch() {
gulp.watch(['src/**/*.ts', 'src/**/*.js'], gulp.series(buildESM));
}