Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Dima <alexdima@microsoft.com>2016-10-20 15:59:07 +0300
committerAlex Dima <alexdima@microsoft.com>2016-10-20 16:00:05 +0300
commit9f0f868c653a98adddffd8ab6f62a5a4f08db7d3 (patch)
tree76cfba801ea75aa794bd6a3f43a74edb2bea7c73
parent3d726b59c148de6ff8bb15f811436f9a181e421c (diff)
Extract client compilation code out of gulpfile.js
-rw-r--r--build/lib/compilation.js134
-rw-r--r--build/lib/compilation.ts163
-rw-r--r--build/lib/nls.ts2
-rw-r--r--build/lib/reporter.js6
-rw-r--r--build/lib/reporter.ts4
-rw-r--r--build/lib/typings/gulp-bom.d.ts12
-rw-r--r--build/lib/typings/gulp-tsb.d.ts16
-rw-r--r--gulpfile.js159
8 files changed, 337 insertions, 159 deletions
diff --git a/build/lib/compilation.js b/build/lib/compilation.js
new file mode 100644
index 00000000000..da18bdcbc63
--- /dev/null
+++ b/build/lib/compilation.js
@@ -0,0 +1,134 @@
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+'use strict';
+var gulp = require('gulp');
+var tsb = require('gulp-tsb');
+var es = require('event-stream');
+var watch = require('./watch');
+var nls = require('./nls');
+var util = require('./util');
+var reporter_1 = require('./reporter');
+var path = require('path');
+var bom = require('gulp-bom');
+var sourcemaps = require('gulp-sourcemaps');
+var _ = require('underscore');
+var monacodts = require('../monaco/api');
+var fs = require('fs');
+var reporter = reporter_1.createReporter();
+var rootDir = path.join(__dirname, '../../src');
+var options = require('../../src/tsconfig.json').compilerOptions;
+options.verbose = false;
+options.sourceMap = true;
+options.rootDir = rootDir;
+options.sourceRoot = util.toFileUri(rootDir);
+function createCompile(build, emitError) {
+ var opts = _.clone(options);
+ opts.inlineSources = !!build;
+ opts.noFilesystemLookup = true;
+ var ts = tsb.create(opts, null, null, function (err) { return reporter(err.toString()); });
+ return function (token) {
+ var utf8Filter = util.filter(function (data) { return /(\/|\\)test(\/|\\).*utf8/.test(data.path); });
+ var tsFilter = util.filter(function (data) { return /\.ts$/.test(data.path); });
+ var noDeclarationsFilter = util.filter(function (data) { return !(/\.d\.ts$/.test(data.path)); });
+ var input = es.through();
+ var output = input
+ .pipe(utf8Filter)
+ .pipe(bom())
+ .pipe(utf8Filter.restore)
+ .pipe(tsFilter)
+ .pipe(util.loadSourcemaps())
+ .pipe(ts(token))
+ .pipe(noDeclarationsFilter)
+ .pipe(build ? nls() : es.through())
+ .pipe(noDeclarationsFilter.restore)
+ .pipe(sourcemaps.write('.', {
+ addComment: false,
+ includeContent: !!build,
+ sourceRoot: options.sourceRoot
+ }))
+ .pipe(tsFilter.restore)
+ .pipe(reporter.end(emitError));
+ return es.duplex(input, output);
+ };
+}
+function compileTask(out, build) {
+ var compile = createCompile(build, true);
+ return function () {
+ var src = es.merge(gulp.src('src/**', { base: 'src' }), gulp.src('node_modules/typescript/lib/lib.d.ts'));
+ return src
+ .pipe(compile())
+ .pipe(gulp.dest(out))
+ .pipe(monacodtsTask(out, false));
+ };
+}
+exports.compileTask = compileTask;
+function watchTask(out, build) {
+ var compile = createCompile(build);
+ return function () {
+ var src = es.merge(gulp.src('src/**', { base: 'src' }), gulp.src('node_modules/typescript/lib/lib.d.ts'));
+ var watchSrc = watch('src/**', { base: 'src' });
+ return watchSrc
+ .pipe(util.incremental(compile, src, true))
+ .pipe(gulp.dest(out))
+ .pipe(monacodtsTask(out, true));
+ };
+}
+exports.watchTask = watchTask;
+function monacodtsTask(out, isWatch) {
+ var timer = null;
+ var runSoon = function (howSoon) {
+ if (timer !== null) {
+ clearTimeout(timer);
+ timer = null;
+ }
+ timer = setTimeout(function () {
+ timer = null;
+ runNow();
+ }, howSoon);
+ };
+ var runNow = function () {
+ if (timer !== null) {
+ clearTimeout(timer);
+ timer = null;
+ }
+ // if (reporter.hasErrors()) {
+ // monacodts.complainErrors();
+ // return;
+ // }
+ var result = monacodts.run(out);
+ if (!result.isTheSame) {
+ if (isWatch) {
+ fs.writeFileSync(result.filePath, result.content);
+ }
+ else {
+ resultStream.emit('error', 'monaco.d.ts is no longer up to date. Please run gulp watch and commit the new file.');
+ }
+ }
+ };
+ var resultStream;
+ if (isWatch) {
+ var filesToWatchMap_1 = {};
+ monacodts.getFilesToWatch(out).forEach(function (filePath) {
+ filesToWatchMap_1[path.normalize(filePath)] = true;
+ });
+ watch('build/monaco/*').pipe(es.through(function () {
+ runSoon(5000);
+ }));
+ resultStream = es.through(function (data) {
+ var filePath = path.normalize(data.path);
+ if (filesToWatchMap_1[filePath]) {
+ runSoon(5000);
+ }
+ this.emit('data', data);
+ });
+ }
+ else {
+ resultStream = es.through(null, function () {
+ runNow();
+ this.emit('end');
+ });
+ }
+ return resultStream;
+}
diff --git a/build/lib/compilation.ts b/build/lib/compilation.ts
new file mode 100644
index 00000000000..eed6a156cbd
--- /dev/null
+++ b/build/lib/compilation.ts
@@ -0,0 +1,163 @@
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+
+'use strict';
+
+import * as gulp from 'gulp';
+import * as tsb from 'gulp-tsb';
+import * as es from 'event-stream';
+const watch = require('./watch');
+import * as nls from './nls';
+import * as util from './util';
+import { createReporter } from './reporter';
+import * as path from 'path';
+import * as bom from 'gulp-bom';
+import * as sourcemaps from 'gulp-sourcemaps';
+import * as _ from 'underscore';
+import * as monacodts from '../monaco/api';
+import * as fs from 'fs';
+
+const reporter = createReporter();
+
+const rootDir = path.join(__dirname, '../../src');
+const options = require('../../src/tsconfig.json').compilerOptions;
+options.verbose = false;
+options.sourceMap = true;
+options.rootDir = rootDir;
+options.sourceRoot = util.toFileUri(rootDir);
+
+function createCompile(build:boolean, emitError?:boolean): (token?:util.ICancellationToken) => NodeJS.ReadWriteStream {
+ const opts = _.clone(options);
+ opts.inlineSources = !!build;
+ opts.noFilesystemLookup = true;
+
+ const ts = tsb.create(opts, null, null, err => reporter(err.toString()));
+
+ return function (token?:util.ICancellationToken) {
+ const utf8Filter = util.filter(data => /(\/|\\)test(\/|\\).*utf8/.test(data.path));
+ const tsFilter = util.filter(data => /\.ts$/.test(data.path));
+ const noDeclarationsFilter = util.filter(data => !(/\.d\.ts$/.test(data.path)));
+
+ const input = es.through();
+ const output = input
+ .pipe(utf8Filter)
+ .pipe(bom())
+ .pipe(utf8Filter.restore)
+ .pipe(tsFilter)
+ .pipe(util.loadSourcemaps())
+ .pipe(ts(token))
+ .pipe(noDeclarationsFilter)
+ .pipe(build ? nls() : es.through())
+ .pipe(noDeclarationsFilter.restore)
+ .pipe(sourcemaps.write('.', {
+ addComment: false,
+ includeContent: !!build,
+ sourceRoot: options.sourceRoot
+ }))
+ .pipe(tsFilter.restore)
+ .pipe(reporter.end(emitError));
+
+ return es.duplex(input, output);
+ };
+}
+
+export function compileTask(out:string, build:boolean): () => NodeJS.ReadWriteStream {
+ const compile = createCompile(build, true);
+
+ return function () {
+ const src = es.merge(
+ gulp.src('src/**', { base: 'src' }),
+ gulp.src('node_modules/typescript/lib/lib.d.ts')
+ );
+
+ return src
+ .pipe(compile())
+ .pipe(gulp.dest(out))
+ .pipe(monacodtsTask(out, false));
+ };
+}
+
+export function watchTask(out:string, build:boolean): () => NodeJS.ReadWriteStream {
+ const compile = createCompile(build);
+
+ return function () {
+ const src = es.merge(
+ gulp.src('src/**', { base: 'src' }),
+ gulp.src('node_modules/typescript/lib/lib.d.ts')
+ );
+ const watchSrc = watch('src/**', { base: 'src' });
+
+ return watchSrc
+ .pipe(util.incremental(compile, src, true))
+ .pipe(gulp.dest(out))
+ .pipe(monacodtsTask(out, true));
+ };
+}
+
+function monacodtsTask(out:string, isWatch:boolean): NodeJS.ReadWriteStream {
+ let timer:NodeJS.Timer = null;
+
+ const runSoon = function(howSoon:number) {
+ if (timer !== null) {
+ clearTimeout(timer);
+ timer = null;
+ }
+ timer = setTimeout(function() {
+ timer = null;
+ runNow();
+ }, howSoon);
+ };
+
+ const runNow = function() {
+ if (timer !== null) {
+ clearTimeout(timer);
+ timer = null;
+ }
+ // if (reporter.hasErrors()) {
+ // monacodts.complainErrors();
+ // return;
+ // }
+ const result = monacodts.run(out);
+ if (!result.isTheSame) {
+ if (isWatch) {
+ fs.writeFileSync(result.filePath, result.content);
+ } else {
+ resultStream.emit('error', 'monaco.d.ts is no longer up to date. Please run gulp watch and commit the new file.');
+ }
+ }
+ };
+
+ let resultStream: NodeJS.ReadWriteStream;
+
+ if (isWatch) {
+
+ const filesToWatchMap: {[file:string]:boolean;} = {};
+ monacodts.getFilesToWatch(out).forEach(function(filePath) {
+ filesToWatchMap[path.normalize(filePath)] = true;
+ });
+
+ watch('build/monaco/*').pipe(es.through(function() {
+ runSoon(5000);
+ }));
+
+ resultStream = es.through(function(data) {
+ const filePath = path.normalize(data.path);
+ if (filesToWatchMap[filePath]) {
+ runSoon(5000);
+ }
+ this.emit('data', data);
+ });
+
+ } else {
+
+ resultStream = es.through(null, function() {
+ runNow();
+ this.emit('end');
+ });
+
+ }
+
+ return resultStream;
+}
diff --git a/build/lib/nls.ts b/build/lib/nls.ts
index 2a813f6301b..e3cda1658db 100644
--- a/build/lib/nls.ts
+++ b/build/lib/nls.ts
@@ -62,7 +62,7 @@ define([], [${ wrap + lines.map(l => indent + l).join(',\n') + wrap }]);`;
/**
* Returns a stream containing the patched JavaScript and source maps.
*/
-function nls(): Stream {
+function nls(): NodeJS.ReadWriteStream {
var input = through();
var output = input.pipe(through(function (f: FileSourceMap) {
if (!f.sourceMap) {
diff --git a/build/lib/reporter.js b/build/lib/reporter.js
index b122d9d0db4..df242ade196 100644
--- a/build/lib/reporter.js
+++ b/build/lib/reporter.js
@@ -24,7 +24,7 @@ function onEnd() {
errors.map(function (err) { return util.log(util.colors.red('Error') + ": " + err); });
util.log("Finished " + util.colors.green('compilation') + " with " + errors.length + " errors after " + util.colors.magenta((new Date().getTime() - startTime) + ' ms'));
}
-exports.createReporter = function () {
+function createReporter() {
var errors = [];
allErrors.push(errors);
var ReportFunc = (function () {
@@ -50,4 +50,6 @@ exports.createReporter = function () {
return ReportFunc;
}());
return ReportFunc;
-};
+}
+exports.createReporter = createReporter;
+;
diff --git a/build/lib/reporter.ts b/build/lib/reporter.ts
index dfdebf83ee9..afd9e83b875 100644
--- a/build/lib/reporter.ts
+++ b/build/lib/reporter.ts
@@ -39,7 +39,7 @@ export interface IReporter {
end(emitError:boolean): NodeJS.ReadWriteStream;
}
-exports.createReporter = () => {
+export function createReporter(): IReporter {
const errors:Error[] = [];
allErrors.push(errors);
@@ -68,5 +68,5 @@ exports.createReporter = () => {
}
}
- return ReportFunc;
+ return <IReporter><any>ReportFunc;
};
diff --git a/build/lib/typings/gulp-bom.d.ts b/build/lib/typings/gulp-bom.d.ts
new file mode 100644
index 00000000000..94dc5fd6d21
--- /dev/null
+++ b/build/lib/typings/gulp-bom.d.ts
@@ -0,0 +1,12 @@
+
+declare module "gulp-bom" {
+ function f(): NodeJS.ReadWriteStream;
+
+ /**
+ * This is required as per:
+ * https://github.com/Microsoft/TypeScript/issues/5073
+ */
+ namespace f {}
+
+ export = f;
+}
diff --git a/build/lib/typings/gulp-tsb.d.ts b/build/lib/typings/gulp-tsb.d.ts
new file mode 100644
index 00000000000..600bfacf261
--- /dev/null
+++ b/build/lib/typings/gulp-tsb.d.ts
@@ -0,0 +1,16 @@
+
+
+declare module "gulp-tsb" {
+
+ export interface ICancellationToken {
+ isCancellationRequested(): boolean;
+ }
+
+ export interface IncrementalCompiler {
+ (token?:ICancellationToken): NodeJS.ReadWriteStream;
+ // program?: ts.Program;
+ }
+
+ export function create(configOrName: { [option: string]: string | number | boolean; } | string, verbose?: boolean, json?: boolean, onError?: (message: any) => void): IncrementalCompiler;
+
+} \ No newline at end of file
diff --git a/gulpfile.js b/gulpfile.js
index fb870c79e2e..813c9ec47bd 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -11,176 +11,27 @@ require('events').EventEmitter.defaultMaxListeners = 100;
const gulp = require('gulp');
const json = require('gulp-json-editor');
const buffer = require('gulp-buffer');
-const tsb = require('gulp-tsb');
const filter = require('gulp-filter');
const mocha = require('gulp-mocha');
const es = require('event-stream');
-const watch = require('./build/lib/watch');
-const nls = require('./build/lib/nls');
const util = require('./build/lib/util');
-const reporter = require('./build/lib/reporter').createReporter();
const remote = require('gulp-remote-src');
const zip = require('gulp-vinyl-zip');
const path = require('path');
-const bom = require('gulp-bom');
-const sourcemaps = require('gulp-sourcemaps');
-const _ = require('underscore');
const assign = require('object-assign');
-const monacodts = require('./build/monaco/api');
-const fs = require('fs');
const glob = require('glob');
const pkg = require('./package.json');
-
-const rootDir = path.join(__dirname, 'src');
-const options = require('./src/tsconfig.json').compilerOptions;
-options.verbose = false;
-options.sourceMap = true;
-options.rootDir = rootDir;
-options.sourceRoot = util.toFileUri(rootDir);
-
-function createCompile(build, emitError) {
- const opts = _.clone(options);
- opts.inlineSources = !!build;
- opts.noFilesystemLookup = true;
-
- const ts = tsb.create(opts, null, null, err => reporter(err.toString()));
-
- return function (token) {
- const utf8Filter = util.filter(data => /(\/|\\)test(\/|\\).*utf8/.test(data.path));
- const tsFilter = util.filter(data => /\.ts$/.test(data.path));
- const noDeclarationsFilter = util.filter(data => !(/\.d\.ts$/.test(data.path)));
-
- const input = es.through();
- const output = input
- .pipe(utf8Filter)
- .pipe(bom())
- .pipe(utf8Filter.restore)
- .pipe(tsFilter)
- .pipe(util.loadSourcemaps())
- .pipe(ts(token))
- .pipe(noDeclarationsFilter)
- .pipe(build ? nls() : es.through())
- .pipe(noDeclarationsFilter.restore)
- .pipe(sourcemaps.write('.', {
- addComment: false,
- includeContent: !!build,
- sourceRoot: options.sourceRoot
- }))
- .pipe(tsFilter.restore)
- .pipe(reporter.end(emitError));
-
- return es.duplex(input, output);
- };
-}
-
-function compileTask(out, build) {
- const compile = createCompile(build, true);
-
- return function () {
- const src = es.merge(
- gulp.src('src/**', { base: 'src' }),
- gulp.src('node_modules/typescript/lib/lib.d.ts')
- );
-
- return src
- .pipe(compile())
- .pipe(gulp.dest(out))
- .pipe(monacodtsTask(out, false));
- };
-}
-
-function watchTask(out, build) {
- const compile = createCompile(build);
-
- return function () {
- const src = es.merge(
- gulp.src('src/**', { base: 'src' }),
- gulp.src('node_modules/typescript/lib/lib.d.ts')
- );
- const watchSrc = watch('src/**', { base: 'src' });
-
- return watchSrc
- .pipe(util.incremental(compile, src, true))
- .pipe(gulp.dest(out))
- .pipe(monacodtsTask(out, true));
- };
-}
-
-function monacodtsTask(out, isWatch) {
- let timer = -1;
-
- const runSoon = function(howSoon) {
- if (timer !== -1) {
- clearTimeout(timer);
- timer = -1;
- }
- timer = setTimeout(function() {
- timer = -1;
- runNow();
- }, howSoon);
- };
-
- const runNow = function() {
- if (timer !== -1) {
- clearTimeout(timer);
- timer = -1;
- }
- // if (reporter.hasErrors()) {
- // monacodts.complainErrors();
- // return;
- // }
- const result = monacodts.run(out);
- if (!result.isTheSame) {
- if (isWatch) {
- fs.writeFileSync(result.filePath, result.content);
- } else {
- resultStream.emit('error', 'monaco.d.ts is no longer up to date. Please run gulp watch and commit the new file.');
- }
- }
- };
-
- let resultStream;
-
- if (isWatch) {
-
- const filesToWatchMap = {};
- monacodts.getFilesToWatch(out).forEach(function(filePath) {
- filesToWatchMap[path.normalize(filePath)] = true;
- });
-
- watch('build/monaco/*').pipe(es.through(function() {
- runSoon(5000);
- }));
-
- resultStream = es.through(function(data) {
- const filePath = path.normalize(data.path);
- if (filesToWatchMap[filePath]) {
- runSoon(5000);
- }
- this.emit('data', data);
- });
-
- } else {
-
- resultStream = es.through(null, function() {
- runNow();
- this.emit('end');
- });
-
- }
-
- return resultStream;
-}
+const compilation = require('./build/lib/compilation');
// Fast compile for development time
gulp.task('clean-client', util.rimraf('out'));
-gulp.task('compile-client', ['clean-client'], compileTask('out', false));
-gulp.task('watch-client', ['clean-client'], watchTask('out', false));
+gulp.task('compile-client', ['clean-client'], compilation.compileTask('out', false));
+gulp.task('watch-client', ['clean-client'], compilation.watchTask('out', false));
// Full compile, including nls and inline sources in sourcemaps, for build
gulp.task('clean-client-build', util.rimraf('out-build'));
-gulp.task('compile-client-build', ['clean-client-build'], compileTask('out-build', true));
-gulp.task('watch-client-build', ['clean-client-build'], watchTask('out-build', true));
+gulp.task('compile-client-build', ['clean-client-build'], compilation.compileTask('out-build', true));
+gulp.task('watch-client-build', ['clean-client-build'], compilation.watchTask('out-build', true));
// Default
gulp.task('default', ['compile']);