forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
191 lines (162 loc) · 5.68 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// Increase max listeners for event emitters
require('events').EventEmitter.defaultMaxListeners = 100;
var gulp = require('gulp');
var tsb = require('gulp-tsb');
var filter = require('gulp-filter');
var mocha = require('gulp-mocha');
var es = require('event-stream');
var watch = require('./build/lib/watch');
var nls = require('./build/lib/nls');
var style = require('./build/lib/style');
var copyrights = require('./build/lib/copyrights');
var util = require('./build/lib/util');
var reporter = require('./build/lib/reporter')();
var remote = require('gulp-remote-src');
var rename = require('gulp-rename');
var zip = require('gulp-vinyl-zip');
var path = require('path');
var bom = require('gulp-bom');
var sourcemaps = require('gulp-sourcemaps');
var _ = require('underscore');
var rootDir = path.join(__dirname, 'src');
var tsOptions = {
target: 'ES5',
module: 'amd',
verbose: true,
preserveConstEnums: true,
experimentalDecorators: true,
sourceMap: true,
rootDir: rootDir,
sourceRoot: util.toFileUri(rootDir)
};
function createCompile(build) {
var opts = _.clone(tsOptions);
opts.inlineSources = !!build;
var ts = tsb.create(opts, null, null, function (err) { reporter(err.toString()); });
return function (token) {
var utf8Filter = filter('**/test/**/*utf8*', { restore: true });
var tsFilter = filter([
'**/*.ts',
'!vs/languages/typescript/common/lib/lib.**.ts'
], { restore: true });
var input = es.through();
var output = input
.pipe(utf8Filter)
.pipe(bom())
.pipe(utf8Filter.restore)
.pipe(tsFilter)
.pipe(util.loadSourcemaps())
.pipe(ts(token))
.pipe(build ? nls() : es.through())
.pipe(sourcemaps.write('.', {
addComment: false,
includeContent: !!build,
sourceRoot: tsOptions.sourceRoot
}))
.pipe(tsFilter.restore)
.pipe(reporter());
return es.duplex(input, output);
};
}
function compileTask(out, build) {
var compile = createCompile(build);
return function () {
var src = gulp.src('src/**', { base: 'src' });
return src
.pipe(compile())
.pipe(gulp.dest(out));
};
}
function watchTask(out, build) {
var compile = createCompile(build);
return function () {
var src = gulp.src('src/**', { base: 'src' });
var watchSrc = watch('src/**', { base: 'src' });
return watchSrc
.pipe(util.incremental(compile, src, true))
.pipe(gulp.dest(out));
};
}
// 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));
// Full compile, including nls and inline sources in sourcemaps, for build
gulp.task('clean-build', util.rimraf('out-build'));
gulp.task('compile-build', ['clean-build'], compileTask('out-build', true));
gulp.task('watch-build', ['clean-build'], watchTask('out-build', true));
// Default
gulp.task('default', ['compile-all']);
// All
gulp.task('clean', ['clean-client', 'clean-plugins']);
gulp.task('compile', ['compile-client', 'compile-plugins']);
gulp.task('watch', ['watch-client', 'watch-plugins']);
var LINE_FEED_FILES = [
'build/**/*',
'extensions/**/*',
'scripts/**/*',
'src/**/*',
'test/**/*',
'!extensions/csharp-o/bin/**',
'!extensions/**/out/**',
'!**/node_modules/**',
'!**/fixtures/**',
'!**/*.{svg,exe,png,scpt,bat,cur,ttf,woff,eot}',
];
gulp.task('eol-style', function() {
return gulp.src(LINE_FEED_FILES).pipe(style({complain:true}));
});
gulp.task('fix-eol-style', function() {
return gulp.src(LINE_FEED_FILES, { base: '.' }).pipe(style({})).pipe(gulp.dest('.'));
});
var WHITESPACE_FILES = LINE_FEED_FILES.concat([
'!**/lib/**'
]);
gulp.task('whitespace-style', function() {
return gulp.src(LINE_FEED_FILES).pipe(style({complain:true, whitespace:true}));
});
gulp.task('fix-whitespace-style', function() {
return gulp.src(LINE_FEED_FILES, { base: '.' }).pipe(style({whitespace:true})).pipe(gulp.dest('.'));
});
gulp.task('copyrights', function() {
return gulp.src(['src/vs/**/*.ts', 'src/vs/**/*.css', 'extensions/**/*.ts', 'extensions/**/*.css']).pipe(copyrights.copyrights());
});
gulp.task('insert-copyrights', function() {
return gulp.src(['src/vs/**/*.ts', 'src/vs/**/*.css', 'extensions/**/*.ts', 'extensions/**/*.css']).pipe(copyrights.insertCopyrights());
});
gulp.task('test', function () {
return gulp.src('test/all.js')
.pipe(mocha({ ui: 'tdd', delay: true }))
.once('end', function () { process.exit(); });
});
gulp.task('mixin', function () {
var repo = process.env['VSCODE_MIXIN_REPO'];
if (!repo) {
return;
}
var url = 'https://github.com/' + repo + '/archive/master.zip';
var opts = { base: '' };
var username = process.env['VSCODE_MIXIN_USERNAME'];
var password = process.env['VSCODE_MIXIN_PASSWORD'];
if (username || password) {
opts.auth = { user: username || '', pass: password || '' };
}
console.log('Mixing in sources from \'' + url + '\':');
return remote(url, opts)
.pipe(zip.src())
.pipe(rename(function (f) {
f.dirname = f.dirname.replace(/^[^\/\\]+[\/\\]?/, '');
}))
.pipe(es.mapSync(function (f) {
console.log(f.relative);
return f;
}))
.pipe(gulp.dest('.'));
});
require('./gulpfile.vscode');
require('./gulpfile.editor');
require('./gulpfile.plugins');