forked from schaze/node-homie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
109 lines (96 loc) · 3.85 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
const gulp = require('gulp');
const ts = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const ASSETS = ['src/**/*.json', 'src/**/*.json', 'README.md', 'LICENSE'];
const merge = require('merge2')
// pull in the project TypeScript config
const tsProject = ts.createProject('./tsconfig.cjs.json');
const tsProjectES6 = ts.createProject('./tsconfig.es6.json');
const tsProjectESM = ts.createProject('./tsconfig.esm.json');
const tsProjectTypes = ts.createProject('./tsconfig.types.json');
function devBuild() {
const tsResult = tsProject.src()
.pipe(sourcemaps.init({ debug: true }))
.pipe(tsProject());
const tsResultES6 = tsProjectES6.src()
.pipe(sourcemaps.init({ debug: true }))
.pipe(tsProjectES6());
const tsResultESM = tsProjectESM.src()
.pipe(sourcemaps.init({ debug: true }))
.pipe(tsProjectESM());
const tsResultTypes = tsProjectTypes.src()
.pipe(sourcemaps.init({ debug: true }))
.pipe(tsProjectTypes());
return merge([
// tsResult.dts.pipe(gulp.dest(tsProject.options.outDir)),
tsResult.js
.pipe(sourcemaps.mapSources(function (sourcePath, file) {
// source paths are prefixed with '../src/'
return sourcePath.slice(1);
}))
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: function (file) { return file.cwd + '/src/'; } }))
.pipe(gulp.dest(tsProject.options.outDir)),
// tsResultES6.dts.pipe(gulp.dest(tsProjectES6.options.outDir)),
tsResultES6.js
.pipe(sourcemaps.mapSources(function (sourcePath, file) {
// source paths are prefixed with '../src/'
return sourcePath.slice(1);
}))
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: function (file) { return file.cwd + '/src/'; } }))
.pipe(gulp.dest(tsProjectES6.options.outDir)),
tsResultESM.js
.pipe(sourcemaps.mapSources(function (sourcePath, file) {
// source paths are prefixed with '../src/'
return sourcePath.slice(1);
}))
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: function (file) { return file.cwd + '/src/'; } }))
.pipe(gulp.dest(tsProjectESM.options.outDir)),
tsResultTypes.dts
.pipe(sourcemaps.mapSources(function (sourcePath, file) {
// source paths are prefixed with '../src/'
return sourcePath.slice(1);
}))
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: function (file) { return file.cwd + '/src/'; } }))
.pipe(gulp.dest(tsProjectTypes.options.outDir)),
]);
}
function prodBuild() {
const tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject());
const tsResultES6 = tsProjectES6.src()
.pipe(sourcemaps.init())
.pipe(tsProjectES6());
const tsResultESM = tsProjectESM.src()
.pipe(sourcemaps.init())
.pipe(tsProjectESM());
const tsResultTypes = tsProjectTypes.src()
.pipe(sourcemaps.init())
.pipe(tsProjectTypes());
return merge([
tsResult.js.pipe(gulp.dest(tsProject.options.outDir)),
tsResultES6.js.pipe(gulp.dest(tsProjectES6.options.outDir)),
tsResultESM.js.pipe(gulp.dest(tsProjectESM.options.outDir)),
tsResultTypes.dts.pipe(gulp.dest(tsProjectTypes.options.outDir)),
]);
}
function assets() {
return merge([
gulp.src(ASSETS).pipe(gulp.dest(tsProject.options.outDir)),
gulp.src(ASSETS).pipe(gulp.dest(tsProjectES6.options.outDir)),
gulp.src(ASSETS).pipe(gulp.dest(tsProjectESM.options.outDir)),
]);
}
function watch(done) {
gulp.watch(['./src/**/*.ts', './src/**/*.json'], gulp.series(gulp.parallel(devBuild, assets)));
done();
}
function watchTest(done) {
gulp.watch(['./src/**/*.ts', './src/**/*.json'], gulp.series(gulp.parallel(testBuild, assets)));
done();
}
gulp.task('default', gulp.series(
devBuild,
assets));
gulp.task('prod', gulp.series(prodBuild, assets));
gulp.task('watch', gulp.series(devBuild, assets, watch));