-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
109 lines (88 loc) · 2.12 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
// SPDX-License-Identifier: MIT
'use strict';
const gulp = require('gulp');
const ts = require('gulp-typescript');
const del = require('del');
const sourcemaps = require('gulp-sourcemaps');
const cached = require('gulp-cached');
const vsce = require('vsce');
const extension = ts.createProject('tsconfig.json');
const webview = ts.createProject('./resources/tsconfig.json');
const rootDir = extension.options.rootDir;
const outDir = extension.options.outDir;
// 拷贝 testdata 目录下的内容
function copy() {
return gulp.src(rootDir + '/**/testdata/**/*', { base: 'src' }).
pipe(gulp.dest(outDir))
}
function compileWebview() {
let s = webview.src()
.pipe(cached('webview'))
if (webview.options.sourceMap) {
s = s.pipe(sourcemaps.init())
.pipe(webview())
.pipe(sourcemaps.write('./'))
}
return s.pipe(gulp.dest(webview.options.outDir))
}
// 编译当前的扩展
function compileExtension() {
let s = extension.src()
.pipe(cached('extension'))
if (extension.options.sourceMap) {
s = s.pipe(sourcemaps.init())
.pipe(extension())
.pipe(sourcemaps.write('./'))
}
return s.pipe(gulp.dest(outDir));
}
async function clean() {
await del(webview.options.outDir + "/*.(js|js.map)");
await del(outDir);
}
function watchExtension() {
return gulp.watch(
rootDir,
{
delay: 500,
queue: true,
},
compileExtension,
);
}
function watchWebview() {
return gulp.watch(
webview.options.rootDir,
{
delay: 500,
queue: true,
},
compileWebview,
);
}
function createVSIX() {
return vsce.createVSIX();
}
// 发布当前的扩展
function publish() {
return vsce.publish();
}
exports.compile = gulp.series(
clean,
compileExtension,
copy,
compileWebview,
);
exports.clean = clean;
exports.publish = gulp.series(
createVSIX,
publish,
);
exports.package = gulp.series(
compileExtension,
createVSIX,
);
exports.watch = gulp.parallel(
watchWebview,
watchExtension,
);