-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
70 lines (58 loc) · 1.93 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
const gulp = require('gulp');
const path = require('path');
const del = require('del');
const ts = require('gulp-typescript');
const mocha = require('gulp-spawn-mocha');
const sourcemaps = require('gulp-sourcemaps');
const remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul');
const merge = require('merge2');
const scripts = ['src/**/*.ts'];
const clean = () => del(['dist/*', 'dist-es/*']);
const compileTs = (name, dest, settings) => {
const task = () => {
const project = ts.createProject('tsconfig.json', settings);
const result = gulp.src(scripts)
.pipe(sourcemaps.init())
.pipe(project(ts.reporter.defaultReporter()));
return merge([
result.dts
.pipe(gulp.dest(dest)),
result.js
.pipe(sourcemaps.write({ sourceRoot: path.resolve('src') }))
.pipe(gulp.dest(dest)),
]);
};
task.displayName = name;
return task;
};
const buildJS = compileTs('build-js', 'dist', {});
const buildES = compileTs('build-es', 'dist-es', { module: 'es6' });
const build = gulp.parallel(buildJS, buildES);
const tests = () => gulp.src(['dist/test/**/*.js'], { read: false })
.pipe(mocha({
reporter: 'dot',
timeout: 10000,
}))
.on('error', function (e) {
console.log(e.message);
this.emit('end');
});
const coverage = () => gulp.src(['dist/test/**/*.js'], { read: false })
.pipe(mocha({
reporter: 'dot',
timeout: 10000,
istanbul: { print: 'none' },
}));
const useCoverage = process.argv.indexOf('--coverage') !== -1;
const watch = cb => {
gulp.watch([
...scripts, 'test/**/*.psd', 'test/**/*.psb', 'test/**/*.abr', 'test/**/*.png', 'test/**/*.json'
], useCoverage ? cov : test);
cb();
};
const remap = () => gulp.src('coverage/coverage.json')
.pipe(remapIstanbul({ reports: { html: 'coverage-remapped' } }));
const dev = gulp.series(clean, buildJS, watch);
const cov = gulp.series(buildJS, coverage, remap);
const test = gulp.series(buildJS, tests);
module.exports = { build, buildJS, buildES, dev, cov, test };