Skip to content

Commit 8493117

Browse files
committed
cleanup top level gulpfile
1 parent b6b7e82 commit 8493117

2 files changed

Lines changed: 73 additions & 77 deletions

File tree

build/lib/util.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,17 @@ exports.rebase = function (count) {
274274
var parts = f.dirname.split(/[\/\\]/);
275275
f.dirname = parts.slice(count).join(path.sep);
276276
});
277+
};
278+
279+
exports.filter = fn => {
280+
const result = es.through(function(data) {
281+
if (fn(data)) {
282+
this.emit('data', data);
283+
} else {
284+
result.restore.push(data);
285+
}
286+
});
287+
288+
result.restore = es.through();
289+
return result;
277290
};

gulpfile.js

Lines changed: 60 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,53 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
'use strict';
7+
68
// Increase max listeners for event emitters
79
require('events').EventEmitter.defaultMaxListeners = 100;
810

9-
var gulp = require('gulp');
10-
var json = require('gulp-json-editor');
11-
var buffer = require('gulp-buffer');
12-
var tsb = require('gulp-tsb');
13-
var filter = require('gulp-filter');
14-
var mocha = require('gulp-mocha');
15-
var es = require('event-stream');
16-
var watch = require('./build/lib/watch');
17-
var nls = require('./build/lib/nls');
18-
var util = require('./build/lib/util');
19-
var reporter = require('./build/lib/reporter')();
20-
var remote = require('gulp-remote-src');
21-
var zip = require('gulp-vinyl-zip');
22-
var path = require('path');
23-
var bom = require('gulp-bom');
24-
var sourcemaps = require('gulp-sourcemaps');
25-
var _ = require('underscore');
26-
var assign = require('object-assign');
27-
var monacodts = require('./build/monaco/api');
28-
var fs = require('fs');
29-
30-
var rootDir = path.join(__dirname, 'src');
31-
var tsOptions = {
32-
target: 'ES5',
33-
declaration: true,
34-
module: 'amd',
35-
verbose: false,
36-
preserveConstEnums: true,
37-
experimentalDecorators: true,
38-
sourceMap: true,
39-
rootDir: rootDir,
40-
sourceRoot: util.toFileUri(rootDir)
41-
};
42-
43-
function createFastFilter(filterFn) {
44-
var result = es.through(function(data) {
45-
if (filterFn(data)) {
46-
this.emit('data', data);
47-
} else {
48-
result.restore.push(data);
49-
}
50-
});
51-
result.restore = es.through();
52-
return result;
53-
}
11+
const gulp = require('gulp');
12+
const json = require('gulp-json-editor');
13+
const buffer = require('gulp-buffer');
14+
const tsb = require('gulp-tsb');
15+
const filter = require('gulp-filter');
16+
const mocha = require('gulp-mocha');
17+
const es = require('event-stream');
18+
const watch = require('./build/lib/watch');
19+
const nls = require('./build/lib/nls');
20+
const util = require('./build/lib/util');
21+
const reporter = require('./build/lib/reporter')();
22+
const remote = require('gulp-remote-src');
23+
const zip = require('gulp-vinyl-zip');
24+
const path = require('path');
25+
const bom = require('gulp-bom');
26+
const sourcemaps = require('gulp-sourcemaps');
27+
const _ = require('underscore');
28+
const assign = require('object-assign');
29+
const monacodts = require('./build/monaco/api');
30+
const fs = require('fs');
31+
32+
const rootDir = path.join(__dirname, 'src');
33+
const options = require('./src/tsconfig.json').compilerOptions;
34+
options.verbose = false;
35+
options.sourceMap = true;
36+
options.rootDir = rootDir;
37+
options.sourceRoot = util.toFileUri(rootDir);
5438

5539
function createCompile(build, emitError) {
56-
var opts = _.clone(tsOptions);
40+
const opts = _.clone(options);
5741
opts.inlineSources = !!build;
5842
opts.noFilesystemLookup = true;
5943

60-
var ts = tsb.create(opts, null, null, err => reporter(err.toString()));
44+
const ts = tsb.create(opts, null, null, err => reporter(err.toString()));
6145

6246
return function (token) {
63-
var utf8Filter = createFastFilter(function(data) { return /(\/|\\)test(\/|\\).*utf8/.test(data.path); });
64-
var tsFilter = createFastFilter(function(data) { return /\.ts$/.test(data.path); });
65-
var noDeclarationsFilter = createFastFilter(function(data) { return !(/\.d\.ts$/.test(data.path)); });
47+
const utf8Filter = util.filter(data => /(\/|\\)test(\/|\\).*utf8/.test(data.path));
48+
const tsFilter = util.filter(data => /\.ts$/.test(data.path));
49+
const noDeclarationsFilter = util.filter(data => !(/\.d\.ts$/.test(data.path)));
6650

67-
var input = es.through();
68-
var output = input
51+
const input = es.through();
52+
const output = input
6953
.pipe(utf8Filter)
7054
.pipe(bom())
7155
.pipe(utf8Filter.restore)
@@ -78,7 +62,7 @@ function createCompile(build, emitError) {
7862
.pipe(sourcemaps.write('.', {
7963
addComment: false,
8064
includeContent: !!build,
81-
sourceRoot: tsOptions.sourceRoot
65+
sourceRoot: options.sourceRoot
8266
}))
8367
.pipe(tsFilter.restore)
8468
.pipe(reporter.end(emitError));
@@ -88,10 +72,10 @@ function createCompile(build, emitError) {
8872
}
8973

9074
function compileTask(out, build) {
91-
var compile = createCompile(build, true);
75+
const compile = createCompile(build, true);
9276

9377
return function () {
94-
var src = es.merge(
78+
const src = es.merge(
9579
gulp.src('src/**', { base: 'src' }),
9680
gulp.src('node_modules/typescript/lib/lib.d.ts')
9781
);
@@ -104,14 +88,14 @@ function compileTask(out, build) {
10488
}
10589

10690
function watchTask(out, build) {
107-
var compile = createCompile(build);
91+
const compile = createCompile(build);
10892

10993
return function () {
110-
var src = es.merge(
94+
const src = es.merge(
11195
gulp.src('src/**', { base: 'src' }),
11296
gulp.src('node_modules/typescript/lib/lib.d.ts')
11397
);
114-
var watchSrc = watch('src/**', { base: 'src' });
98+
const watchSrc = watch('src/**', { base: 'src' });
11599

116100
return watchSrc
117101
.pipe(util.incremental(compile, src, true))
@@ -121,10 +105,9 @@ function watchTask(out, build) {
121105
}
122106

123107
function monacodtsTask(out, isWatch) {
108+
let timer = -1;
124109

125-
var timer = -1;
126-
127-
var runSoon = function(howSoon) {
110+
const runSoon = function(howSoon) {
128111
if (timer !== -1) {
129112
clearTimeout(timer);
130113
timer = -1;
@@ -135,7 +118,7 @@ function monacodtsTask(out, isWatch) {
135118
}, howSoon);
136119
};
137120

138-
var runNow = function() {
121+
const runNow = function() {
139122
if (timer !== -1) {
140123
clearTimeout(timer);
141124
timer = -1;
@@ -144,7 +127,7 @@ function monacodtsTask(out, isWatch) {
144127
// monacodts.complainErrors();
145128
// return;
146129
// }
147-
var result = monacodts.run(out);
130+
const result = monacodts.run(out);
148131
if (!result.isTheSame) {
149132
if (isWatch) {
150133
fs.writeFileSync(result.filePath, result.content);
@@ -154,11 +137,11 @@ function monacodtsTask(out, isWatch) {
154137
}
155138
};
156139

157-
var resultStream;
140+
let resultStream;
158141

159142
if (isWatch) {
160143

161-
var filesToWatchMap = {};
144+
const filesToWatchMap = {};
162145
monacodts.getFilesToWatch(out).forEach(function(filePath) {
163146
filesToWatchMap[path.normalize(filePath)] = true;
164147
});
@@ -168,7 +151,7 @@ function monacodtsTask(out, isWatch) {
168151
}));
169152

170153
resultStream = es.through(function(data) {
171-
var filePath = path.normalize(data.path);
154+
const filePath = path.normalize(data.path);
172155
if (filesToWatchMap[filePath]) {
173156
runSoon(5000);
174157
}
@@ -217,47 +200,47 @@ gulp.task('test', function () {
217200
});
218201

219202
gulp.task('mixin', function () {
220-
var repo = process.env['VSCODE_MIXIN_REPO'];
203+
const repo = process.env['VSCODE_MIXIN_REPO'];
221204

222205
if (!repo) {
223206
console.log('Missing VSCODE_MIXIN_REPO, skipping mixin');
224207
return;
225208
}
226209

227-
var quality = process.env['VSCODE_QUALITY'];
210+
const quality = process.env['VSCODE_QUALITY'];
228211

229212
if (!quality) {
230213
console.log('Missing VSCODE_QUALITY, skipping mixin');
231214
return;
232215
}
233216

234-
var url = 'https://github.com/' + repo + '/archive/master.zip';
235-
var opts = { base: '' };
236-
var username = process.env['VSCODE_MIXIN_USERNAME'];
237-
var password = process.env['VSCODE_MIXIN_PASSWORD'];
217+
const url = 'https://github.com/' + repo + '/archive/master.zip';
218+
const opts = { base: '' };
219+
const username = process.env['VSCODE_MIXIN_USERNAME'];
220+
const password = process.env['VSCODE_MIXIN_PASSWORD'];
238221

239222
if (username || password) {
240223
opts.auth = { user: username || '', pass: password || '' };
241224
}
242225

243226
console.log('Mixing in sources from \'' + url + '\':');
244227

245-
var all = remote(url, opts)
228+
let all = remote(url, opts)
246229
.pipe(zip.src())
247230
.pipe(filter(function (f) { return !f.isDirectory(); }))
248231
.pipe(util.rebase(1));
249232

250233
if (quality) {
251-
var build = all.pipe(filter('build/**'));
252-
var productJsonFilter = filter('product.json', { restore: true });
234+
const build = all.pipe(filter('build/**'));
235+
const productJsonFilter = filter('product.json', { restore: true });
253236

254-
var mixin = all
237+
const mixin = all
255238
.pipe(filter('quality/' + quality + '/**'))
256239
.pipe(util.rebase(2))
257240
.pipe(productJsonFilter)
258241
.pipe(buffer())
259242
.pipe(json(function (patch) {
260-
var original = require('./product.json');
243+
const original = require('./product.json');
261244
return assign(original, patch);
262245
}))
263246
.pipe(productJsonFilter.restore);

0 commit comments

Comments
 (0)