-
Notifications
You must be signed in to change notification settings - Fork 459
/
gulpfile.js
429 lines (382 loc) · 14.7 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
const gulp = require('gulp');
const rename = require('gulp-rename');
const ts = require('gulp-typescript');
const tsProject = ts.createProject('tsconfig.json');
const del = require('del');
const srcmap = require('gulp-sourcemaps');
const config = require('./tasks/config');
const concat = require('gulp-concat');
const minifier = require('gulp-uglify/minifier');
const uglifyjs = require('uglify-js');
const argv = require('yargs').argv;
const min = (argv.min === undefined) ? false : true;
const prod = (argv.prod === undefined) ? false : true;
const vscodeTest = require('@vscode/test-electron');
const { exec } = require('child_process');
const gulpESLintNew = require('gulp-eslint-new');
const copy = require('esbuild-plugin-copy');
const clc = require('cli-color');
const path = require('path');
const esbuild = require('esbuild');
const { typecheckPlugin } = require('@jgoz/esbuild-plugin-typecheck');
const run = require('gulp-run-command').default;
require('./tasks/packagetasks');
require('./tasks/localizationtasks');
function getTimeString() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
return clc.white(`${hours}:${minutes}:${seconds}`);
}
function esbuildProblemMatcherPlugin(processName) {
const formattedProcessName = clc.cyan(`${processName}`);
return {
name: 'esbuild-problem-matcher',
setup(build) {
let timeStart;
build.onStart(async () => {
timeStart = Date.now();
timeStart.toString()
console.log(`[${getTimeString()}] Starting '${formattedProcessName}' build`);
});
build.onEnd(async (result) => {
const timeEnd = Date.now();
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(` ${location.file}:${location.line}:${location.column}:`);
});
console.log(`[${getTimeString()}] Finished '${formattedProcessName}' build after ${clc.magenta((timeEnd - timeStart) + ' ms')} `);
})
}
};
}
const cssLoaderPlugin = {
name: 'css-loader',
setup(build) {
build.onLoad({ filter: /\.css$/ }, async (args) => {
const fs = require('fs').promises;
const css = await fs.readFile(args.path, 'utf8');
const contents = `
const style = document.createElement('style');
style.textContent = ${JSON.stringify(css)};
document.head.appendChild(style);
`;
return { contents, loader: 'js' };
});
},
};
// Copy icons for OE
gulp.task('ext:copy-OE-assets', (done) => {
return gulp.src([
config.paths.project.root + '/src/objectExplorer/objectTypes/*'
])
.pipe(gulp.dest('out/src/objectExplorer/objectTypes'));
});
// Copy icons for Query History
gulp.task('ext:copy-queryHistory-assets', (done) => {
return gulp.src([
config.paths.project.root + '/src/queryHistory/icons/*'
])
.pipe(gulp.dest('out/src/queryHistory/icons'));
});
async function generateExtensionBundle() {
const ctx = await esbuild.context({
entryPoints: [
'src/extension.ts',
'src/languageService/serviceInstallerUtil.ts',
'src/telemetry/telemetryInterfaces.ts',
'src/protocol.ts',
'src/models/interfaces.ts'
],
bundle: true,
format: 'cjs',
minify: false,
sourcemap: true,
sourcesContent: false,
platform: 'node',
outdir: 'out/src',
external: [
'vscode',
],
logLevel: 'silent',
loader: {
'.ts': 'ts',
'.js': 'js',
'.json': 'json',
},
plugins: [
{
name: 'custom-types',
setup(build) {
build.onResolve({ filter: /^vscode-mssql$/ }, args => {
return { path: path.resolve(__dirname, 'typings/vscode-mssql.d.ts') };
});
}
},
copy.copy({
assets: [
{
from: 'src/objectExplorer/objectTypes/*.svg',
to: './out/src/objectTypes'
},
{
from: 'src/controllers/sqlOutput.ejs',
to: './out/src/sqlOutput.ejs'
},
{
from: 'src/configurations/config.json',
to: './out/config.json'
}
],
resolveFrom: __dirname
}),
esbuildProblemMatcherPlugin('Extension')
],
});
await ctx.rebuild();
await ctx.dispose();
}
gulp.task('ext:bundle-src', gulp.series(generateExtensionBundle));
gulp.task('ext:compile-src', (done) => {
return gulp.src([
config.paths.project.root + '/src/**/*.ts',
config.paths.project.root + '/src/**/*.js',
config.paths.project.root + '/typings/**/*.d.ts',
'!' + config.paths.project.root + '/src/views/htmlcontent/**/*'])
.pipe(srcmap.init())
.pipe(tsProject())
.on('error', function () {
if (process.env.BUILDMACHINE) {
done('Extension source failed to build. See Above.');
process.exit(1);
}
})
.pipe(srcmap.write('.', { includeContent: false, sourceRoot: '../src' }))
.pipe(gulp.dest('out/src/'));
});
// Compile angular view
gulp.task('ext:compile-view', (done) => {
return gulp.src([
config.paths.project.root + '/src/views/htmlcontent/**/*.ts',
config.paths.project.root + '/typings/**/*.d.ts'])
.pipe(srcmap.init())
.pipe(tsProject())
.pipe(srcmap.write('.', { includeContent: false, sourceRoot: '../src' }))
.pipe(gulp.dest('out/src/views/htmlcontent'));
});
async function generateReactWebviewsBundle() {
const ctx = await esbuild.context({
/**
* Entry points for React webviews. This generates individual bundles (both .js and .css files)
* for each entry point, to be used by the webview's HTML content.
*/
entryPoints: {
'connectionDialog': 'src/reactviews/pages/ConnectionDialog/index.tsx',
'executionPlan': 'src/reactviews/pages/ExecutionPlan/index.tsx',
'tableDesigner': 'src/reactviews/pages/TableDesigner/index.tsx',
'objectExplorerFilter': 'src/reactviews/pages/ObjectExplorerFilter/index.tsx',
'queryResult': 'src/reactviews/pages/QueryResult/index.tsx',
'userSurvey': 'src/reactviews/pages/UserSurvey/index.tsx',
},
bundle: true,
outdir: 'out/src/reactviews/assets',
platform: 'browser',
loader: {
'.tsx': 'tsx',
'.ts': 'ts',
'.css': 'css',
'.svg': 'file',
'.js': 'js',
'.png': 'file',
'.gif': 'file',
},
tsconfig: './tsconfig.react.json',
plugins: [
esbuildProblemMatcherPlugin('React App'),
typecheckPlugin()
],
sourcemap: prod ? false : 'inline',
metafile: true,
minify: prod,
minifyWhitespace: prod,
minifyIdentifiers: prod,
format: 'esm',
splitting: true,
});
const result = await ctx.rebuild();
/**
* Generating esbuild metafile for webviews. You can analyze the metafile https://esbuild.github.io/analyze/
* to see the bundle size and other details.
*/
const fs = require('fs').promises;
if (result.metafile) {
await fs.writeFile('./webviews-metafile.json', JSON.stringify(result.metafile));
}
await ctx.dispose();
}
// Compile react views
gulp.task('ext:compile-reactviews',
gulp.series(generateReactWebviewsBundle)
);
// Copy systemjs config file
gulp.task('ext:copy-systemjs-config', (done) => {
return gulp.src([
config.paths.project.root + '/src/views/htmlcontent/*.js'])
.pipe(gulp.dest('out/src/views/htmlcontent'));
});
// Copy html
gulp.task('ext:copy-html', (done) => {
return gulp.src([
config.paths.project.root + '/src/controllers/sqlOutput.ejs'])
.pipe(gulp.dest('out/src/controllers/'));
});
// Copy css
gulp.task('ext:copy-css', (done) => {
return gulp.src([
config.paths.project.root + '/src/views/htmlcontent/src/css/*.css'])
.pipe(gulp.dest('out/src/views/htmlcontent/src/css'));
});
// Copy images
gulp.task('ext:copy-images', (done) => {
return gulp.src([
config.paths.project.root + '/src/views/htmlcontent/src/images/**/*'])
.pipe(gulp.dest('out/src/views/htmlcontent/src/images'));
});
// Clean angular slickgrid library
gulp.task('ext:clean-library-ts-files', function () {
del(config.paths.project.root + '/node_modules/angular2-slickgrid/**/*.ts');
return del(config.paths.project.root + '/node_modules/rxjs/**/*.ts');
});
// Copy and bundle dependencies into one file (vendor/vendors.js)
// system.config.js can also bundled for convenience
gulp.task('ext:copy-dependencies', (done) => {
gulp.src([config.paths.project.root + '/node_modules/rxjs/**/*'])
.pipe(gulp.dest('out/src/views/htmlcontent/src/js/lib/rxjs'));
gulp.src([config.paths.project.root + '/node_modules/angular-in-memory-web-api/**/*'])
.pipe(gulp.dest('out/src/views/htmlcontent/src/js/lib/angular-in-memory-web-api'));
// concatenate non-angular2 libs, shims & systemjs-config
if (min) {
gulp.src([
config.paths.project.root + '/node_modules/slickgrid/lib/jquery-1.8.3.js',
config.paths.project.root + '/node_modules/slickgrid/lib/jquery.event.drag-2.2.js',
config.paths.project.root + '/node_modules/slickgrid/lib/jquery-ui-1.9.2.js',
config.paths.project.root + '/node_modules/underscore/underscore-min.js',
config.paths.project.root + '/node_modules/slickgrid/slick.core.js',
config.paths.project.root + '/node_modules/slickgrid/slick.grid.js',
config.paths.project.root + '/node_modules/slickgrid/slick.editors.js',
config.paths.project.root + '/node_modules/core-js/client/shim.min.js',
config.paths.project.root + '/node_modules/zone.js/dist/zone.js',
config.paths.project.root + '/node_modules/rangy/lib/rangy-core.js',
config.paths.project.root + '/node_modules/rangy/lib/rangy-textrange.js',
config.paths.project.root + '/node_modules/reflect-metadata/Reflect.js',
config.paths.project.root + '/node_modules/systemjs/dist/system.src.js',
config.paths.project.root + '/src/views/htmlcontent/systemjs.config.js'
])
.pipe(concat('vendors.min.js'))
.pipe(minifier({}, uglifyjs))
.pipe(gulp.dest('out/src/views/htmlcontent/src/js/lib'));
} else {
gulp.src([
config.paths.project.root + '/node_modules/slickgrid/lib/jquery-1.8.3.js',
config.paths.project.root + '/node_modules/slickgrid/lib/jquery.event.drag-2.2.js',
config.paths.project.root + '/node_modules/slickgrid/lib/jquery-ui-1.9.2.js',
config.paths.project.root + '/node_modules/underscore/underscore-min.js',
config.paths.project.root + '/node_modules/slickgrid/slick.core.js',
config.paths.project.root + '/node_modules/slickgrid/slick.grid.js',
config.paths.project.root + '/node_modules/slickgrid/slick.editors.js',
config.paths.project.root + '/node_modules/core-js/client/shim.min.js',
config.paths.project.root + '/node_modules/rangy/lib/rangy-core.js',
config.paths.project.root + '/node_modules/rangy/lib/rangy-textrange.js',
config.paths.project.root + '/node_modules/reflect-metadata/Reflect.js',
config.paths.project.root + '/node_modules/systemjs/dist/system.src.js',
config.paths.project.root + '/src/views/htmlcontent/systemjs.config.js'
])
.pipe(gulp.dest('out/src/views/htmlcontent/src/js/lib'));
gulp.src([config.paths.project.root + '/node_modules/zone.js/**/*'])
.pipe(gulp.dest('out/src/views/htmlcontent/src/js/lib/zone.js'));
}
// copy source maps
gulp.src([
// config.paths.html.root + '/node_modules/es6-shim/es6-shim.map',
config.paths.project.root + '/node_modules/reflect-metadata/Reflect.js.map',
config.paths.project.root + '/node_modules/systemjs/dist/system-polyfills.js.map',
config.paths.project.root + '/node_modules/systemjs-plugin-json/json.js'
]).pipe(gulp.dest('out/src/views/htmlcontent/src/js/lib'));
gulp.src([
config.paths.project.root + '/node_modules/angular2-slickgrid/out/css/SlickGrid.css',
config.paths.project.root + '/node_modules/slickgrid/slick.grid.css'
]).pipe(gulp.dest('out/src/views/htmlcontent/src/css'));
gulp.src([
config.paths.project.root + '/node_modules/angular2-slickgrid/out/**/*.js'
], { base: config.paths.project.root + '/node_modules/angular2-slickgrid' }).pipe(gulp.dest('out/src/views/htmlcontent/src/js/lib/angular2-slickgrid'));
return gulp.src([config.paths.project.root + '/node_modules/@angular/**/*'])
.pipe(gulp.dest('out/src/views/htmlcontent/src/js/lib/@angular'));
});
// Compile tests
gulp.task('ext:compile-tests', (done) => {
return gulp.src([
config.paths.project.root + '/test/**/*.ts',
config.paths.project.root + '/typings/**/*.ts'])
.pipe(srcmap.init())
.pipe(tsProject())
.on('error', function () {
if (process.env.BUILDMACHINE) {
done('Extension Tests failed to build. See Above.');
process.exit(1);
}
})
.pipe(srcmap.write('.', { includeContent: false, sourceRoot: '../test' }))
.pipe(gulp.dest('out/test/'));
});
gulp.task('ext:compile', gulp.series('ext:compile-src', 'ext:compile-tests', 'ext:copy-OE-assets', 'ext:copy-queryHistory-assets'));
gulp.task('ext:copy-tests', () => {
return gulp.src(config.paths.project.root + '/test/resources/**/*')
.pipe(gulp.dest(config.paths.project.root + '/out/test/resources/'))
});
gulp.task('ext:copy-config', () => {
return gulp.src(config.paths.project.root + '/src/configurations/config.json')
.pipe(gulp.dest(config.paths.project.root + '/out/src'));
});
gulp.task('ext:copy-js', () => {
return gulp.src([
config.paths.project.root + '/src/**/*.js',
'!' + config.paths.project.root + '/src/views/htmlcontent/**/*'])
.pipe(gulp.dest(config.paths.project.root + '/out/src'))
});
// Copy the files which aren't used in compilation
gulp.task('ext:copy', gulp.series('ext:copy-tests', 'ext:copy-js', 'ext:copy-config', 'ext:copy-systemjs-config', 'ext:copy-dependencies', 'ext:copy-html', 'ext:copy-css', 'ext:copy-images'));
gulp.task('ext:build', gulp.series('ext:generate-runtime-localization-files', 'ext:copy', 'ext:clean-library-ts-files', 'ext:compile', 'ext:compile-view', 'ext:compile-reactviews')); // removed lint before copy
gulp.task('ext:test', async () => {
let workspace = process.env['WORKSPACE'];
if (!workspace) {
workspace = process.cwd();
}
process.env.JUNIT_REPORT_PATH = workspace + '/test-reports/test-results-ext.xml';
var args = ['--verbose', '--disable-gpu', '--disable-telemetry', '--disable-updates', '-n'];
let extensionTestsPath = `${workspace}/out/test/unit`;
let vscodePath = await vscodeTest.downloadAndUnzipVSCode();
await vscodeTest.runTests({
vscodeExecutablePath: vscodePath,
extensionDevelopmentPath: workspace,
extensionTestsPath: extensionTestsPath,
launchArgs: args
});
});
gulp.task('ext:smoke', run('npx playwright test'));
gulp.task('test', gulp.series('ext:test'));
gulp.task('clean', function (done) {
return del('out', done);
});
gulp.task('build', gulp.series('clean', 'ext:build', 'ext:install-service'));
gulp.task('watch-src', function () {
return gulp.watch('./src/**/*.ts', gulp.series('ext:compile-src'))
});
gulp.task('watch-tests', function () {
return gulp.watch('./test/**/*.ts', gulp.series('ext:compile-tests'))
});
gulp.task('watch-reactviews', function () {
return gulp.watch(['./src/reactviews/**/*', './typings/**/*', './src/sharedInterfaces/**/*'], gulp.series('ext:compile-reactviews'))
});
// Do a full build first so we have the latest compiled files before we start watching for more changes
gulp.task('watch', gulp.series('build', gulp.parallel('watch-src', 'watch-tests', 'watch-reactviews')));