forked from angular/zone.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
423 lines (357 loc) · 14.3 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
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
'use strict';
var gulp = require('gulp');
var rollup = require('gulp-rollup');
var rename = require("gulp-rename");
var uglify = require('gulp-uglify');
var pump = require('pump');
var path = require('path');
var spawn = require('child_process').spawn;
const os = require('os');
function generateScript(inFile, outFile, minify, callback) {
inFile = path.join('./build-esm/', inFile).replace(/\.ts$/, '.js');
var parts = [
gulp.src('./build-esm/lib/**/*.js')
.pipe(rollup({
entry: inFile,
format: 'umd',
onwarn: function (warning) {
// https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
if (warning.code === 'THIS_IS_UNDEFINED') {
return;
}
console.error(warning.message);
},
banner: '/**\n'
+ '* @license\n'
+ '* Copyright Google Inc. All Rights Reserved.\n'
+ '*\n'
+ '* Use of this source code is governed by an MIT-style license that can be\n'
+ '* found in the LICENSE file at https://angular.io/license\n'
+ '*/',
globals: {
'rxjs/Observable': 'Rx',
'rxjs/Subscriber': 'Rx',
'rxjs/Subscription': 'Rx',
'rxjs/scheduler/asap': 'Rx.Scheduler',
'rxjs/symbol/rxSubscriber': 'Rx.Symbol'
}
}))
.pipe(rename(outFile)),
];
if (minify) {
parts.push(uglify());
}
parts.push(gulp.dest('./dist'));
pump(parts, callback);
}
// returns the script path for the current platform
function platformScriptPath(path) {
return /^win/.test(os.platform()) ? `${path}.cmd` : path;
}
function tsc(config, cb) {
spawn(path.normalize(platformScriptPath('./node_modules/.bin/tsc')), ['-p', config], {stdio: 'inherit'})
.on('close', function(exitCode) {
if (exitCode) {
var err = new Error('TypeScript compiler failed');
// The stack is not useful in this context.
err.showStack = false;
cb(err);
} else {
cb();
}
});
}
// This is equivalent to `npm run tsc`.
gulp.task('compile', function(cb) {
tsc('tsconfig.json', cb);
});
gulp.task('compile-node', function(cb) {
tsc('tsconfig-node.json', cb);
});
gulp.task('compile-esm', function(cb) {
tsc('tsconfig-esm.json', cb);
});
gulp.task('compile-esm-node', function(cb) {
tsc('tsconfig-esm-node.json', cb);
});
gulp.task('build/zone.js.d.ts', ['compile-esm'], function() {
return gulp.src('./build-esm/lib/zone.d.ts').pipe(rename('zone.js.d.ts')).pipe(gulp.dest('./dist'));
});
// Zone for Node.js environment.
gulp.task('build/zone-node.js', ['compile-esm-node'], function(cb) {
return generateScript('./lib/node/rollup-main.ts', 'zone-node.js', false, cb);
});
// Zone for the browser.
gulp.task('build/zone.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/rollup-main.ts', 'zone.js', false, cb);
});
gulp.task('build/zone.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/rollup-main.ts', 'zone.min.js', true, cb);
});
// Zone test bundle for the browser.
gulp.task('build/zone-testing-bundle.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/rollup-test-main.ts', 'zone-testing-bundle.js', false, cb);
});
// Zone test bundle for node.
gulp.task('build/zone-testing-node-bundle.js', ['compile-esm'], function(cb) {
return generateScript('./lib/node/rollup-test-main.ts', 'zone-testing-node-bundle.js', false, cb);
});
// Zone test related files for the browser.
gulp.task('build/zone-testing.js', ['compile-esm'], function(cb) {
return generateScript('./lib/testing/zone-testing.ts', 'zone-testing.js', false, cb);
});
// Zone for electron/nw environment.
gulp.task('build/zone-mix.js', ['compile-esm-node'], function(cb) {
return generateScript('./lib/mix/rollup-mix.ts', 'zone-mix.js', false, cb);
});
gulp.task('build/zone-error.js', ['compile-esm'], function(cb) {
return generateScript('./lib/common/error-rewrite.ts', 'zone-error.js', false, cb);
});
gulp.task('build/zone-error.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/common/error-rewrite.ts', 'zone-error.min.js', true, cb);
});
gulp.task('build/webapis-media-query.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/webapis-media-query.ts', 'webapis-media-query.js', false, cb);
});
gulp.task('build/webapis-media-query.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/webapis-media-query.ts', 'webapis-media-query.min.js', true, cb);
});
gulp.task('build/webapis-notification.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/webapis-notification.ts', 'webapis-notification.js', false, cb);
});
gulp.task('build/webapis-notification.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/webapis-notification.ts', 'webapis-notification.min.js', true, cb);
});
gulp.task('build/webapis-rtc-peer-connection.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/webapis-rtc-peer-connection.ts', 'webapis-rtc-peer-connection.js', false, cb);
});
gulp.task('build/webapis-rtc-peer-connection.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/webapis-rtc-peer-connection.ts', 'webapis-rtc-peer-connection.min.js', true, cb);
});
gulp.task('build/webapis-shadydom.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/shadydom.ts', 'webapis-shadydom.js', false, cb);
});
gulp.task('build/webapis-shadydom.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/shadydom.ts', 'webapis-shadydom.min.js', true, cb);
});
gulp.task('build/zone-patch-cordova.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/cordova.ts', 'zone-patch-cordova.js', false, cb);
});
gulp.task('build/zone-patch-cordova.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/cordova.ts', 'zone-patch-cordova.min.js', true, cb);
});
gulp.task('build/zone-patch-electron.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/electron.ts', 'zone-patch-electron.js', false, cb);
});
gulp.task('build/zone-patch-electron.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/electron.ts', 'zone-patch-electron.min.js', true, cb);
});
gulp.task('build/zone-patch-user-media.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/webapis-user-media.ts', 'zone-patch-user-media.js', false, cb);
});
gulp.task('build/zone-patch-user-media.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/browser/webapis-user-media.ts', 'zone-patch-user-media.min.js', true, cb);
});
gulp.task('build/bluebird.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/bluebird.ts', 'zone-bluebird.js', false, cb);
});
gulp.task('build/bluebird.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/extra/bluebird.ts', 'zone-bluebird.min.js', true, cb);
});
gulp.task('build/jasmine-patch.js', ['compile-esm'], function(cb) {
return generateScript('./lib/jasmine/jasmine.ts', 'jasmine-patch.js', false, cb);
});
gulp.task('build/jasmine-patch.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/jasmine/jasmine.ts', 'jasmine-patch.min.js', true, cb);
});
gulp.task('build/mocha-patch.js', ['compile-esm'], function(cb) {
return generateScript('./lib/mocha/mocha.ts', 'mocha-patch.js', false, cb);
});
gulp.task('build/mocha-patch.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/mocha/mocha.ts', 'mocha-patch.min.js', true, cb);
});
gulp.task('build/long-stack-trace-zone.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/long-stack-trace.ts', 'long-stack-trace-zone.js', false, cb);
});
gulp.task('build/long-stack-trace-zone.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/long-stack-trace.ts', 'long-stack-trace-zone.min.js', true, cb);
});
gulp.task('build/proxy-zone.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/proxy.ts', 'proxy.js', false, cb);
});
gulp.task('build/proxy-zone.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/proxy.ts', 'proxy.min.js', true, cb);
});
gulp.task('build/task-tracking.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/task-tracking.ts', 'task-tracking.js', false, cb);
});
gulp.task('build/task-tracking.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/task-tracking.ts', 'task-tracking.min.js', true, cb);
});
gulp.task('build/wtf.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/wtf.ts', 'wtf.js', false, cb);
});
gulp.task('build/wtf.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/wtf.ts', 'wtf.min.js', true, cb);
});
gulp.task('build/async-test.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/async-test.ts', 'async-test.js', false, cb);
});
gulp.task('build/fake-async-test.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/fake-async-test.ts', 'fake-async-test.js', false, cb);
});
gulp.task('build/sync-test.js', ['compile-esm'], function(cb) {
return generateScript('./lib/zone-spec/sync-test.ts', 'sync-test.js', false, cb);
});
gulp.task('build/rxjs.js', ['compile-esm'], function(cb) {
return generateScript('./lib/rxjs/rxjs.ts', 'zone-patch-rxjs.js', false, cb);
});
gulp.task('build/rxjs.min.js', ['compile-esm'], function(cb) {
return generateScript('./lib/rxjs/rxjs.ts', 'zone-patch-rxjs.min.js', true, cb);
});
gulp.task('build/closure.js', function() {
return gulp.src('./lib/closure/zone_externs.js')
.pipe(gulp.dest('./dist'));
});
gulp.task('build', [
'build/zone.js',
'build/zone.js.d.ts',
'build/zone.min.js',
'build/zone-testing.js',
'build/zone-testing-bundle.js',
'build/zone-testing-node-bundle.js',
'build/zone-error.js',
'build/zone-error.min.js',
'build/zone-node.js',
'build/webapis-media-query.js',
'build/webapis-media-query.min.js',
'build/webapis-notification.js',
'build/webapis-notification.min.js',
'build/webapis-rtc-peer-connection.js',
'build/webapis-rtc-peer-connection.min.js',
'build/webapis-shadydom.js',
'build/webapis-shadydom.min.js',
'build/zone-patch-cordova.js',
'build/zone-patch-cordova.min.js',
'build/zone-patch-electron.js',
'build/zone-patch-electron.min.js',
'build/zone-patch-user-media.js',
'build/zone-patch-user-media.min.js',
'build/zone-mix.js',
'build/bluebird.js',
'build/bluebird.min.js',
'build/jasmine-patch.js',
'build/jasmine-patch.min.js',
'build/mocha-patch.js',
'build/mocha-patch.min.js',
'build/long-stack-trace-zone.js',
'build/long-stack-trace-zone.min.js',
'build/proxy-zone.js',
'build/proxy-zone.min.js',
'build/task-tracking.js',
'build/task-tracking.min.js',
'build/wtf.js',
'build/wtf.min.js',
'build/async-test.js',
'build/fake-async-test.js',
'build/sync-test.js',
'build/rxjs.js',
'build/rxjs.min.js',
'build/closure.js'
]);
gulp.task('test/node', ['compile-node'], function(cb) {
var JasmineRunner = require('jasmine');
var jrunner = new JasmineRunner();
var specFiles = ['build/test/node_entry_point.js'];
jrunner.configureDefaultReporter({showColors: true});
jrunner.onComplete(function(passed) {
if (!passed) {
var err = new Error('Jasmine node tests failed.');
// The stack is not useful in this context.
err.showStack = false;
cb(err);
} else {
cb();
}
});
jrunner.print = function(value) {
process.stdout.write(value);
};
jrunner.addReporter(new JasmineRunner.ConsoleReporter(jrunner));
jrunner.projectBaseDir = __dirname;
jrunner.specDir = '';
jrunner.addSpecFiles(specFiles);
jrunner.execute();
});
// Check the coding standards and programming errors
gulp.task('lint', () => {
const tslint = require('gulp-tslint');
// Built-in rules are at
// https://github.com/palantir/tslint#supported-rules
const tslintConfig = require('./tslint.json');
return gulp.src(['lib/**/*.ts', 'test/**/*.ts'])
.pipe(tslint({
tslint: require('tslint').default,
configuration: tslintConfig,
formatter: 'prose',
}))
.pipe(tslint.report({emitError: true}));
});
// clang-format entry points
const srcsToFmt = [
'lib/**/*.ts',
'test/**/*.ts',
];
// Check source code for formatting errors (clang-format)
gulp.task('format:enforce', () => {
const format = require('gulp-clang-format');
const clangFormat = require('clang-format');
return gulp.src(srcsToFmt).pipe(
format.checkFormat('file', clangFormat, {verbose: true, fail: true}));
});
// Format the source code with clang-format (see .clang-format)
gulp.task('format', () => {
const format = require('gulp-clang-format');
const clangFormat = require('clang-format');
return gulp.src(srcsToFmt, { base: '.' }).pipe(
format.format('file', clangFormat)).pipe(gulp.dest('.'));
});
// Update the changelog with the latest changes
gulp.task('changelog', () => {
const conventionalChangelog = require('gulp-conventional-changelog');
return gulp.src('CHANGELOG.md')
.pipe(conventionalChangelog({preset: 'angular', releaseCount: 1}, {
// Conventional Changelog Context
// We have to manually set version number so it doesn't get prefixed with `v`
// See https://github.com/conventional-changelog/conventional-changelog-core/issues/10
currentTag: require('./package.json').version
}))
.pipe(gulp.dest('./'));
});
// run promise aplus test
gulp.task('promisetest', ['build/zone-node.js'], (cb) => {
const promisesAplusTests = require('promises-aplus-tests');
const adapter = require('./promise-adapter');
promisesAplusTests(adapter, { reporter: "dot" }, function (err) {
if (err) {
cb(err);
}
});
});
// check dist file size limitation
gulp.task('filesize', ['build'], (cb) => {
const checker = require('./check-file-size');
const result = checker(require('./file-size-limit.json'));
if (result) {
cb();
} else {
cb('check file size failed');
}
});