forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js.old
1583 lines (1308 loc) · 55.6 KB
/
gulpfile.js.old
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
// THIS CHECK SHOULD BE THE FIRST THING IN THIS FILE
// This is to ensure that we catch env issues before we error while requiring other dependencies.
require('./tools/check-environment')(
{requiredNpmVersion: '>=3.5.3 <4.0.0', requiredNodeVersion: '>=5.4.1 <6.0.0'});
var fse = require('fs-extra');
var gulp = require('gulp');
var gulpPlugins = require('gulp-load-plugins')();
var merge = require('merge');
var merge2 = require('merge2');
var minimist = require('minimist');
var os = require('os');
var path = require('path');
var runSequence = require('run-sequence');
var shell = require('gulp-shell');
var licenseWrap = require('./tools/build/licensewrap');
var analytics = require('./tools/analytics/analytics');
var pubget = require('./tools/build/pubget');
var linknodemodules = require('./tools/build/linknodemodules');
var pubbuild = require('./tools/build/pubbuild');
var jsserve = require('./tools/build/jsserve');
var pubserve = require('./tools/build/pubserve');
var runServerDartTests = require('./tools/build/run_server_dart_tests');
var util = require('./tools/build/util');
var buildRouter = require('./modules/angular1_router/build');
var shouldLog = require('./tools/build/logging');
var dartSdk = require('./tools/build/dart');
var browserProvidersConf = require('./browser-providers.conf.js');
var cliArgs = minimist(process.argv.slice(2));
if (cliArgs.projects) {
// normalize for analytics
cliArgs.projects.split(',').sort().join(',');
}
// --projects=angular2 => {angular2: true}
var allProjects =
'angular1_router,angular2,benchmarks,benchmarks_external,benchpress,playground,payload_tests,bundle_deps';
var cliArgsProjects = (cliArgs.projects || allProjects)
.split(',')
.reduce((map, projectName) => {
map[projectName] = true;
return map;
}, {});
var generateEs6 = !cliArgs.projects;
function printModulesWarning() {
if (!cliArgs.projects && !process.env.CI) {
// if users didn't specify projects to build, tell them why and how they should
console.warn(
"Pro Tip: Did you know that you can speed up your build by specifying project name(s)?");
console.warn(" It's like pressing the turbo button in the old days, but better!");
console.warn(" Examples: --project=angular2 or --project=angular2");
}
}
// Make it easy to quiet down portions of the build.
// --logs=all -> log everything (This is the default)
// --logs=quiet -> log nothing
// --logs=<comma-separated-list> -> log listed items.
//
// Not all commands support optional logging, feel free
// to add support by adding a new key to this list,
// and toggling output from the command based on it.
var logs = {dartfmt: shouldLog('dartfmt')};
// dynamic require in build.tools so we can bootstrap TypeScript compilation
function throwToolsBuildMissingError() {
throw new Error('ERROR: build.tools task should have been run before using angularBuilder');
}
var angularBuilder = {
rebuildBrowserDevTree: throwToolsBuildMissingError,
rebuildBrowserProdTree: throwToolsBuildMissingError,
rebuildNodeTree: throwToolsBuildMissingError,
rebuildDartTree: throwToolsBuildMissingError,
uninitialized: true
};
function sequenceComplete(done) {
return function(err) {
if (err) {
var error = new Error('build sequence failed');
error.showStack = false;
done(error);
} else {
done();
}
};
}
var treatTestErrorsAsFatal = true;
function runJasmineTests(globs, done) {
var fork = require('child_process').fork;
var args = ['--'].concat(globs);
fork('./dist/tools/cjs-jasmine', args, {stdio: 'inherit'})
.on('close', function jasmineCloseHandler(exitCode) {
if (exitCode && treatTestErrorsAsFatal) {
var err = new Error('Jasmine tests failed');
// Mark the error for gulp similar to how gulp-utils.PluginError does it.
// The stack is not useful in this context.
err.showStack = false;
done(err);
} else {
done();
}
});
}
// Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped.
var DART_SDK = dartSdk.detect(gulp);
// -----------------------
// configuration
var CONFIG = {
dest: {
js: {
all: 'dist/js',
dev: {es6: 'dist/js/dev/es6', es5: 'dist/js/dev/es5'},
prod: {es6: 'dist/js/prod/es6', es5: 'dist/js/prod/es5'},
cjs: 'dist/js/cjs',
dart2js: 'dist/js/dart2js',
dart_dev_compiler: 'dist/js/ddc'
},
dart: 'dist/dart',
docs: 'dist/docs',
docs_angular_io: 'dist/angular.io',
bundles: {all: 'dist/build', benchpress: 'dist/build/benchpress_bundle/'}
}
};
var ANGULAR2_BUNDLE_CONFIG = [
'angular2/common',
'angular2/core',
'angular2/compiler',
'angular2/instrumentation',
'angular2/platform/browser',
'angular2/platform/common_dom'
];
var NG2_BUNDLE_CONTENT = ANGULAR2_BUNDLE_CONFIG.join(' + ') + ' - rxjs/*';
var HTTP_BUNDLE_CONTENT = 'angular2/http - rxjs/* - ' + ANGULAR2_BUNDLE_CONFIG.join(' - ');
var ROUTER_BUNDLE_CONTENT = 'angular2/router + angular2/router/router_link_dsl - rxjs/* - ' +
ANGULAR2_BUNDLE_CONFIG.join(' - ');
var ALT_ROUTER_BUNDLE_CONTENT =
'angular2/alt_router - rxjs/* - ' + ANGULAR2_BUNDLE_CONFIG.join(' - ');
var TESTING_BUNDLE_CONTENT =
'angular2/testing + angular2/http/testing + angular2/router/testing + angular2/platform/testing/browser - rxjs/* - ' +
ANGULAR2_BUNDLE_CONFIG.join(' - ');
var UPGRADE_BUNDLE_CONTENT = 'angular2/upgrade - rxjs/* - ' + ANGULAR2_BUNDLE_CONFIG.join(' - ');
var BENCHPRESS_BUNDLE_CONFIG = {
entries: ['./dist/js/cjs/benchpress/index.js'],
packageJson: './dist/js/cjs/benchpress/package.json',
includes: ['angular2'],
excludes: ['reflect-metadata', 'selenium-webdriver', 'zone.js'],
ignore: [],
dest: CONFIG.dest.bundles.benchpress
};
var PAYLOAD_TESTS_CONFIG = {
ts: {
bundleName: 'app-bundle-deps.min.js',
cases: ['hello_world'],
dist: function(caseName, packaging) {
return path.join(__dirname, CONFIG.dest.js.prod.es5, 'payload_tests', caseName,
'ts/' + packaging);
},
systemjs: {sizeLimits: {'uncompressed': 880 * 1024, 'gzip level=9': 170 * 1024}},
webpack: {sizeLimits: {'uncompressed': 560 * 1024, 'gzip level=9': 130 * 1024}}
}
};
// ------------
// clean
gulp.task('build/clean.tools', (done) => fse.remove(path.join('dist', 'tools'), done));
gulp.task('build/clean.js', (done) => fse.remove(CONFIG.dest.js.all, done));
gulp.task('build/clean.dart', (done) => fse.remove(CONFIG.dest.dart, done));
gulp.task('build/clean.docs', (done) => fse.remove(CONFIG.dest.docs, done));
gulp.task('build/clean.docs_angular_io', (done) => fse.remove(CONFIG.dest.docs_angular_io, done));
gulp.task('build/clean.bundles', (done) => fse.remove(CONFIG.dest.bundles.all, done));
gulp.task('build/clean.bundles.benchpress',
(done) => fse.remove(CONFIG.dest.bundles.benchpress, done));
// ------------
// transpile
gulp.task('build/tree.dart', ['build/clean.dart', 'build.tools'],
function(done) { runSequence('!build/tree.dart', sequenceComplete(done)); });
gulp.task('!build/tree.dart',
function() { return angularBuilder.rebuildDartTree(cliArgsProjects); });
// ------------
// pubspec
// Run a top-level `pub get` for this project.
gulp.task('pubget.dart', pubget.dir(gulp, gulpPlugins, {dir: '.', command: DART_SDK.PUB}));
// Run `pub get` only on the angular2 dir of CONFIG.dest.dart
gulp.task('!build/pubget.angular2.dart',
pubget.dir(gulp, gulpPlugins,
{dir: path.join(CONFIG.dest.dart, 'angular2'), command: DART_SDK.PUB}));
// Run `pub get` over CONFIG.dest.dart
gulp.task('build/pubspec.dart',
pubget.subDir(gulp, gulpPlugins, {dir: CONFIG.dest.dart, command: DART_SDK.PUB}));
// This is a hacky way to work around dart's pub that creates `packages` symlink in every directory
// that contains a dart file with the main method. For our tests this means that every test
// subfolder
// has a link to the root `packages` directory which causes Karma to sift through 80k files during
// each `karma run` invocation.
//
// Since these directories are not needed for karma tests to run, it's safe to delete them without
// breaking any functionality.
//
// See #2437 for more info.
gulp.task('!build/remove-pub-symlinks', function(done) {
var exec = require('child_process').exec;
if (process.platform == 'win32') {
done();
return;
}
exec('find dist/dart/angular2/test/ -name packages | xargs rm -r',
function(error, stdout, stderr) {
if (error) {
done(stderr);
return;
}
done();
});
});
// ------------
// dartanalyzer
gulp.task('build/analyze.dart', () => {
var dartanalyzer = require('./tools/build/dartanalyzer');
return dartanalyzer(gulp, gulpPlugins, {dest: CONFIG.dest.dart, command: DART_SDK.ANALYZER});
});
gulp.task('build/analyze.ddc.dart', () => {
var dartanalyzer = require('./tools/build/dartanalyzer');
return dartanalyzer(gulp, gulpPlugins,
{dest: CONFIG.dest.dart, command: DART_SDK.ANALYZER, use_ddc: true});
});
gulp.task('build/check.apidocs.dart', () => {
var dartapidocs = require('./tools/build/dartapidocs');
return dartapidocs(gulp, gulpPlugins,
{dest: CONFIG.dest.dart, output: os.tmpdir(), command: DART_SDK.DARTDOCGEN});
});
// ------------
// pubbuild
// WARNING: this task is very slow (~15m as of July 2015)
gulp.task(
'build/pubbuild.dart',
pubbuild.subdirs(gulp, gulpPlugins,
{src: CONFIG.dest.dart, dest: CONFIG.dest.js.dart2js, command: DART_SDK.PUB}));
// ------------
// formatting
function doCheckFormat() {
var clangFormat = require('clang-format');
var gulpFormat = require('gulp-clang-format');
return gulp.src([
'modules/**/*.ts',
'tools/**/*.ts',
'!**/typings/**/*.d.ts',
// workaround https://github.com/angular/clang-format/issues/28
'!tools/compiler_cli/src/main.ts',
'gulpfile.js'
])
.pipe(gulpFormat.checkFormat('file', clangFormat));
}
gulp.task('check-format', function() {
return doCheckFormat().on('warning', function(e) {
console.log("NOTE: this will be promoted to an ERROR in the continuous build");
});
});
gulp.task('enforce-format', function() {
return doCheckFormat().on('warning', function(e) {
console.log("ERROR: You forgot to run clang-format on your change.");
console.log("See https://github.com/angular/angular/blob/master/DEVELOPER.md#clang-format");
process.exit(1);
});
});
gulp.task('lint', ['build.tools'], function() {
var tslint = require('gulp-tslint');
// Built-in rules are at
// https://github.com/palantir/tslint#supported-rules
var tslintConfig = require('./tslint.json');
return gulp.src(['modules/angular2/src/**/*.ts', '!modules/angular2/src/testing/**'])
.pipe(tslint({
tslint: require('tslint').default,
configuration: tslintConfig,
rulesDirectory: 'dist/tools/tslint'
}))
.pipe(tslint.report('prose', {emitError: true}));
});
// ------------
// check circular dependencies in Node.js context
gulp.task('build/checkCircularDependencies', function(done) {
var madge = require('madge');
var dependencyObject = madge([CONFIG.dest.js.dev.es5], {
format: 'cjs',
extensions: ['.js'],
onParseFile: function(data) { data.src = data.src.replace(/\/\* circular \*\//g, "//"); }
});
var circularDependencies = dependencyObject.circular().getArray();
if (circularDependencies.length > 0) {
console.log(circularDependencies);
process.exit(1);
}
done();
});
function jsServeDev() {
return jsserve(gulp, gulpPlugins, {path: CONFIG.dest.js.dev.es5, port: 8000})();
}
function jsServeProd() {
return jsserve(gulp, gulpPlugins, {path: CONFIG.dest.js.prod.es5, port: 8001})();
}
function jsServeDartJs() {
return jsserve(gulp, gulpPlugins, {path: CONFIG.dest.js.dart2js, port: 8002})();
}
function jsServeDartDevCompiler() {
return jsserve(gulp, gulpPlugins, {path: CONFIG.dest.js.dart_dev_compiler, port: 8003})();
}
function proxyServeDart() {
return jsserve(gulp, gulpPlugins, {
port: 8002,
proxies: [
{route: '/playground', url: 'http://localhost:8004'},
{route: '/benchmarks_external', url: 'http://localhost:8008'},
{route: '/benchmarks', url: 'http://localhost:8006'}
]
})();
}
// ------------------
// web servers
gulp.task('serve.js.dev', ['build.js.dev', 'build.js.cjs'], function(neverDone) {
var watch = require('./tools/build/watch');
watch('modules/**', {ignoreInitial: true}, '!broccoli.js.dev');
jsServeDev();
});
gulp.task('serve.js.prod', jsServeProd);
gulp.task('serve.e2e.dev', ['build.js.dev', 'build.js.cjs'], function(neverDone) {
var watch = require('./tools/build/watch');
watch('modules/**', {ignoreInitial: true}, ['!broccoli.js.dev', '!build.js.cjs']);
jsServeDev();
});
gulp.task('serve.e2e.prod', ['build.js.prod', 'build.js.cjs'], function(neverDone) {
var watch = require('./tools/build/watch');
watch('modules/**', {ignoreInitial: true}, ['!broccoli.js.prod', '!build.js.cjs']);
jsServeProd();
});
gulp.task('serve.js.dart2js', jsServeDartJs);
gulp.task('serve.js.ddc', jsServeDartDevCompiler);
gulp.task('!proxyServeDart', proxyServeDart);
gulp.task('serve.dart', function(done) {
runSequence(
[
'!proxyServeDart',
'serve/playground.dart',
'serve/benchmarks.dart',
'serve/benchmarks_external.dart'
],
done);
});
gulp.task('serve/playground.dart',
pubserve(gulp, gulpPlugins,
{command: DART_SDK.PUB, path: CONFIG.dest.dart + '/playground', port: 8004}));
gulp.task('serve/benchmarks.dart',
pubserve(gulp, gulpPlugins,
{command: DART_SDK.PUB, path: CONFIG.dest.dart + '/benchmarks', port: 8006}));
gulp.task(
'serve/benchmarks_external.dart',
pubserve(gulp, gulpPlugins,
{command: DART_SDK.PUB, path: CONFIG.dest.dart + '/benchmarks_external', port: 8008}));
gulp.task('serve.e2e.dart', ['build.js.cjs'], function(neverDone) {
var watch = require('./tools/build/watch');
// Note: we are not using build.dart as the dart analyzer takes too long...
watch('modules/**', {ignoreInitial: true}, ['!build/tree.dart', '!build.js.cjs']);
runSequence('build/packages.dart', 'build/pubspec.dart', 'serve.dart');
});
// ------------------
// CI tests suites
function execProcess(name, args, done) {
var exec = require('child_process').exec;
var cmd = process.platform === 'win32' ? 'node_modules\\.bin\\' + name + ' ' :
'node node_modules/.bin/' + name + ' ';
cmd += args;
exec(cmd, done);
}
function runKarma(configFile, done) {
execProcess('karma', 'run ' + configFile, function(e, stdout) {
// ignore errors, we don't want to fail the build in the interactive (non-ci) mode
// karma server will print all test failures
done();
});
}
// Gulp-typescript doesn't work with typescript@next:
// https://github.com/ivogabe/gulp-typescript/issues/331
function runTsc(project, done) {
execProcess('tsc', '-p ' + project, function(e, stdout, stderr) {
if (e) {
console.log(stdout);
console.error(stderr);
done(e);
} else {
done();
}
});
}
gulp.task('test.js', function(done) {
runSequence('test.compiler_cli', 'test.unit.tools/ci', 'test.transpiler.unittest',
'test.unit.js/ci', 'test.unit.cjs/ci', 'test.typings', 'check-public-api',
sequenceComplete(done));
});
gulp.task('test.dart', function(done) {
runSequence('versions.dart', 'test.transpiler.unittest', 'test.unit.dart/ci',
sequenceComplete(done));
});
gulp.task('versions.dart', function() { dartSdk.logVersion(DART_SDK); });
// Reuse the Travis scripts
// TODO: rename test_*.sh to test_all_*.sh
gulp.task('test.all.js', shell.task(['./scripts/ci/test_js.sh']));
gulp.task('test.all.dart', shell.task(['./scripts/ci/test_dart.sh']));
// karma tests
// These tests run in the browser and are allowed to access
// HTML DOM APIs.
function getBrowsersFromCLI(provider, isDart) {
var isProvider = false;
var rawInput =
cliArgs.browsers ? cliArgs.browsers : (isDart ? 'DartiumWithWebPlatform' : 'Chrome');
var inputList = rawInput.replace(' ', '').split(',');
var outputList = [];
for (var i = 0; i < inputList.length; i++) {
var input = inputList[i];
var karmaChromeLauncher = require('karma-chrome-launcher');
if (browserProvidersConf.customLaunchers.hasOwnProperty(input) ||
karmaChromeLauncher.hasOwnProperty("launcher:" + input)) {
// In case of non-sauce browsers, or browsers defined in karma-chrome-launcher (Chrome,
// ChromeCanary and Dartium):
// overrides everything, ignoring other options
outputList = [input];
isProvider = false;
break;
} else if (provider &&
browserProvidersConf.customLaunchers.hasOwnProperty(provider + "_" +
input.toUpperCase())) {
isProvider = true;
outputList.push(provider + "_" + input.toUpperCase());
} else if (provider && provider == 'SL' &&
browserProvidersConf.sauceAliases.hasOwnProperty(input.toUpperCase())) {
outputList = outputList.concat(browserProvidersConf.sauceAliases[input.toUpperCase()]);
isProvider = true;
} else if (provider && provider == 'BS' &&
browserProvidersConf.browserstackAliases.hasOwnProperty(input.toUpperCase())) {
outputList = outputList.concat(browserProvidersConf.browserstackAliases[input.toUpperCase()]);
isProvider = true;
} else {
throw new Error('ERROR: unknown browser found in getBrowsersFromCLI()');
}
}
return {
browsersToRun:
outputList.filter(function(item, pos, self) { return self.indexOf(item) == pos; }),
isProvider: isProvider
};
}
gulp.task('test.unit.js', ['build.js.dev'], function(neverDone) {
var watch = require('./tools/build/watch');
printModulesWarning();
runSequence('!test.unit.js/karma-server', function() {
watch('modules/**', {ignoreInitial: true}, ['!broccoli.js.dev', '!test.unit.js/karma-run']);
});
});
gulp.task('watch.js.dev', ['build.js.dev'], function(neverDone) {
var watch = require('./tools/build/watch');
printModulesWarning();
watch('modules/**', ['!broccoli.js.dev']);
});
gulp.task('test.unit.js.sauce', ['build.js.dev'], function(done) {
printModulesWarning();
var browserConf = getBrowsersFromCLI('SL');
if (browserConf.isProvider) {
launchKarmaWithExternalBrowsers(['dots'], browserConf.browsersToRun, done);
} else {
throw new Error('ERROR: no Saucelabs browsers provided, add them with the --browsers option');
}
});
gulp.task('test.unit.js.browserstack', ['build.js.dev'], function(done) {
printModulesWarning();
var browserConf = getBrowsersFromCLI('BS');
if (browserConf.isProvider) {
launchKarmaWithExternalBrowsers(['dots'], browserConf.browsersToRun, done);
} else {
throw new Error(
'ERROR: no Browserstack browsers provided, add them with the --browsers option');
}
});
function launchKarmaWithExternalBrowsers(reporters, browsers, done) {
var karma = require('karma');
new karma.Server(
{
configFile: __dirname + '/karma-js.conf.js',
singleRun: true,
browserNoActivityTimeout: 240000,
captureTimeout: 120000,
reporters: reporters,
browsers: browsers
},
function(err) {
done();
process.exit(err ? 1 : 0);
})
.start();
}
gulp.task('!test.unit.js/karma-server', function(done) {
var karma = require('karma');
var watchStarted = false;
var server = new karma.Server({configFile: __dirname + '/karma-js.conf.js'});
server.on('run_complete', function() {
if (!watchStarted) {
watchStarted = true;
done();
}
});
server.start();
});
gulp.task('!test.unit.js/karma-run', function(done) {
// run the run command in a new process to avoid duplicate logging by both server and runner from
// a single process
runKarma('karma-js.conf.js', done);
});
gulp.task('test.unit.router', function(neverDone) {
var watch = require('./tools/build/watch');
runSequence('!test.unit.router/karma-server', function() {
watch('modules/**', ['buildRouter.dev', '!test.unit.router/karma-run']);
});
});
gulp.task('!test.unit.router/karma-server', function() {
var karma = require('karma');
new karma.Server({configFile: __dirname + '/modules/angular1_router/karma-router.conf.js'})
.start();
});
gulp.task('!test.unit.router/karma-run', function(done) {
var karma = require('karma');
karma.runner.run({configFile: __dirname + '/modules/angular1_router/karma-router.conf.js'},
function(exitCode) {
// ignore exitCode, we don't want to fail the build in the interactive (non-ci)
// mode
// karma will print all test failures
done();
});
});
gulp.task('buildRouter.dev', function() {
var modulesSrcDir = __dirname + '/modules';
var distDir = __dirname + '/dist';
buildRouter(modulesSrcDir, distDir);
});
gulp.task('test.unit.dart', function(done) {
printModulesWarning();
runSequence('build/tree.dart', 'build/pure-packages.dart', '!build/pubget.angular2.dart',
'!build/remove-pub-symlinks', function(error) {
var watch = require('./tools/build/watch');
// if initial build failed (likely due to build or formatting step) then exit
// otherwise karma server doesn't start and we can't continue running properly
if (error) {
done(error);
return;
}
// treatTestErrorsAsFatal = false;
watch(['modules/angular2/**'],
['!build/tree.dart', '!test.unit.dart/run/angular2']);
});
});
// Dart Payload Size Test
// This test will fail if the size of our hello_world app goes beyond one of
// these values when compressed at the specified level.
// Measure in bytes.
var _DART_PAYLOAD_SIZE_LIMITS = {'uncompressed': 320 * 1024, 'gzip level=9': 90 * 1024};
gulp.task('test.payload.dart/ci', function(done) {
runSequence('build/packages.dart', '!pubget.payload.dart', '!pubbuild.payload.dart',
'!checkAndReport.payload.dart', done);
});
gulp.task('!pubget.payload.dart',
pubget.dir(gulp, gulpPlugins,
{dir: 'modules_dart/payload/hello_world', command: DART_SDK.PUB}));
gulp.task('!pubbuild.payload.dart',
pubbuild.single(gulp, gulpPlugins,
{command: DART_SDK.PUB, src: 'modules_dart/payload/hello_world'}));
gulp.task('!checkAndReport.payload.dart', function() {
var reportSize = require('./tools/analytics/reportsize');
return reportSize('modules_dart/payload/hello_world/build/web/*.dart.js',
{failConditions: _DART_PAYLOAD_SIZE_LIMITS, prefix: 'hello_world'});
});
// JS payload size tracking
gulp.task('test.payload.js/ci', function(done) {
runSequence('build.payload.js', '!checkAndReport.payload.js', sequenceComplete(done));
});
gulp.task('build.payload.js', ['build.js'], function(done) {
runSequence('!build.payload.js.webpack', '!build.payload.js.systemjs', sequenceComplete(done));
});
gulp.task('!build.payload.js.webpack', function() {
var webpack = require('./tools/build/webpack/promiseify');
var ES5_PROD_ROOT = __dirname + '/' + CONFIG.dest.js.prod.es5;
return Promise.all(PAYLOAD_TESTS_CONFIG.ts.cases.map(function(caseName) {
var CASE_PATH = PAYLOAD_TESTS_CONFIG.ts.dist(caseName, 'webpack');
return webpack({
// bundle app + framework
entry: CASE_PATH + '/index.js',
output: {path: CASE_PATH, filename: "app-bundle.js"},
resolve: {
extensions: ['', '.js'],
packageAlias: '', // option added to ignore "broken" package.json in our dist folder
root: [ES5_PROD_ROOT]
}
})
.then(function() { // pad bundle with mandatory dependencies
return new Promise(function(resolve, reject) {
gulp.src([
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/reflect-metadata/Reflect.js',
CASE_PATH + '/app-bundle.js'
])
.pipe(gulpPlugins.concat(PAYLOAD_TESTS_CONFIG.ts.bundleName))
.pipe(gulpPlugins.uglify())
.pipe(gulp.dest(CASE_PATH))
.on('end', resolve)
.on('error', reject);
});
});
}));
});
gulp.task('!build.payload.js.systemjs', function() {
var bundler = require('./tools/build/bundle');
return Promise.all(PAYLOAD_TESTS_CONFIG.ts.cases.map(function(caseName) {
var CASE_PATH = PAYLOAD_TESTS_CONFIG.ts.dist(caseName, 'systemjs');
return bundler
.bundle(
{
paths: {'index': CASE_PATH + '/index.js'},
meta: {'angular2/core': {build: false}, 'angular2/platform/browser': {build: false}}
},
'index', CASE_PATH + '/index.register.js', {})
.then(function() {
return new Promise(function(resolve, reject) {
gulp.src([
'node_modules/systemjs/dist/system.src.js',
'dist/js/prod/es5/bundle/angular2-polyfills.js',
'dist/js/prod/es5/bundle/angular2.js',
'dist/js/prod/es5//rxjs/bundles/Rx.js',
CASE_PATH + '/index.register.js',
'tools/build/systemjs/payload_tests_import.js'
])
.pipe(gulpPlugins.concat(PAYLOAD_TESTS_CONFIG.ts.bundleName))
.pipe(gulpPlugins.uglify())
.pipe(gulp.dest(CASE_PATH))
.on('end', resolve)
.on('error', reject);
});
});
}));
});
gulp.task('!checkAndReport.payload.js', function() {
var reportSize = require('./tools/analytics/reportsize');
function caseSizeStream(caseName, packaging) {
return reportSize(PAYLOAD_TESTS_CONFIG.ts.dist(caseName, packaging) + '/' +
PAYLOAD_TESTS_CONFIG.ts.bundleName,
{
failConditions: PAYLOAD_TESTS_CONFIG.ts[packaging].sizeLimits,
prefix: caseName + '_' + packaging
});
}
return PAYLOAD_TESTS_CONFIG.ts.cases.reduce(function(sizeReportingStreams, caseName) {
sizeReportingStreams.add(caseSizeStream(caseName, 'systemjs'));
sizeReportingStreams.add(caseSizeStream(caseName, 'webpack'));
}, merge2());
});
gulp.task('watch.dart.dev', function(done) {
runSequence('build/tree.dart', 'build/pure-packages.dart', '!build/pubget.angular2.dart',
'!build/remove-pub-symlinks', function(error) {
var watch = require('./tools/build/watch');
// if initial build failed (likely due to build or formatting step) then exit
// otherwise karma server doesn't start and we can't continue running properly
if (error) {
done(error);
return;
}
watch(['modules/angular2/**', 'modules_dart/**'], {ignoreInitial: true},
['!build/tree.dart', 'build/pure-packages.dart']);
});
});
gulp.task('test.unit.router/ci', function(done) {
var karma = require('karma');
var browserConf = getBrowsersFromCLI();
new karma.Server(
{
configFile: __dirname + '/modules/angular1_router/karma-router.conf.js',
singleRun: true,
reporters: ['dots'],
browsers: browserConf.browsersToRun
},
done)
.start();
});
gulp.task('test.unit.js/ci', function(done) {
var karma = require('karma');
var browserConf = getBrowsersFromCLI();
new karma.Server(
{
configFile: __dirname + '/karma-js.conf.js',
singleRun: true,
reporters: ['dots'],
browsers: browserConf.browsersToRun
},
function(err) { done(); })
.start();
});
gulp.task('test.unit.js.sauce/ci', function(done) {
var browsers = browserProvidersConf.sauceAliases.CI_REQUIRED;
if (cliArgs.mode && cliArgs.mode == 'saucelabs_optional') {
browsers = browserProvidersConf.sauceAliases.CI_OPTIONAL;
}
launchKarmaWithExternalBrowsers(['dots', 'saucelabs'], browsers, done);
});
gulp.task('test.unit.js.browserstack/ci', function(done) {
var browsers = browserProvidersConf.browserstackAliases.CI_REQUIRED;
if (cliArgs.mode && cliArgs.mode == 'browserstack_optional') {
browsers = browserProvidersConf.browserstackAliases.CI_OPTIONAL;
}
launchKarmaWithExternalBrowsers(['dots'], browsers, done);
});
gulp.task('test.unit.dart/ci', function(done) {
runSequence('test.dart.dartium_symlink', '!test.unit.dart/run/angular2',
'!test.unit.dart/run/angular2_testing', '!test.unit.dart/run/benchpress',
sequenceComplete(done));
});
// At the moment, dart test requires dartium to be an executable on the path.
// Make a temporary directory and symlink dartium from there (just for this command)
// so that it can run.
// TODO(juliemr): this won't work with windows - remove the hack and make this platform agnostic.
var dartiumTmpdir = path.join(os.tmpdir(), 'dartium' + new Date().getTime().toString());
var dartiumPathPrefix = 'PATH=$PATH:' + dartiumTmpdir + ' ';
gulp.task(
'test.dart.dartium_symlink',
shell.task(['mkdir ' + dartiumTmpdir, 'ln -s $DARTIUM_BIN ' + dartiumTmpdir + '/dartium']));
gulp.task('!test.unit.dart/run/angular2', function() {
var pubtest = require('./tools/build/pubtest');
return pubtest({
dir: path.join(CONFIG.dest.dart, 'angular2'),
dartiumTmpdir: dartiumTmpdir,
command: DART_SDK.PUB,
files: '**/*_spec.dart',
bunchFiles: true,
useExclusiveTests: true
});
});
gulp.task('!test.unit.dart/run/angular2_testing', function() {
var pubtest = require('./tools/build/pubtest');
return pubtest({
dir: path.join(CONFIG.dest.dart, 'angular2_testing'),
dartiumTmpdir: dartiumTmpdir,
command: DART_SDK.PUB,
files: '**/*_test.dart',
useExclusiveTests: true
});
});
gulp.task('!test.unit.dart/run/benchpress', function() {
var pubtest = require('./tools/build/pubtest');
return pubtest({
dir: path.join(CONFIG.dest.dart, 'benchpress'),
dartiumTmpdir: dartiumTmpdir,
command: DART_SDK.PUB,
files: '**/*_spec.dart',
useExclusiveTests: true
});
});
gulp.task('test.unit.cjs/ci', function(done) {
runJasmineTests(['dist/js/cjs/{angular2,benchpress}/test/**/*_spec.js'], done);
});
gulp.task('check-public-api', ['build.tools'],
function(done) { runJasmineTests(['dist/tools/public_api_guard/**/*_spec.js'], done); });
gulp.task('test.unit.cjs', ['build/clean.js', 'build.tools'], function(neverDone) {
var watch = require('./tools/build/watch');
printModulesWarning();
treatTestErrorsAsFatal = false;
watch('modules/**', ['!build.js.cjs', 'test.unit.cjs/ci']);
});
// Use this target to continuously run dartvm unit-tests (such as transformer
// tests) while coding. Note: these tests do not use Karma.
gulp.task('test.unit.dartvm', function(neverDone) {
var watch = require('./tools/build/watch');
runSequence('build/tree.dart', 'build/pure-packages.dart', '!build/pubget.angular2.dart',
'!test.unit.dartvm/run', function(error) {
// Watch for changes made in the TS and Dart code under "modules" and
// run ts2dart and test change detector generator prior to rerunning the
// tests.
watch('modules/angular2/**', {ignoreInitial: true},
['!build/tree.dart', '!test.unit.dartvm/run']);
// Watch for changes made in Dart code under "modules_dart", then copy it
// to dist and run test change detector generator prior to retunning the
// tests.
watch('modules_dart/**', {ignoreInitial: true},
['build/pure-packages.dart', '!test.unit.dartvm/run']);
});
});
gulp.task('!test.unit.dartvm/run',
runServerDartTests(gulp, gulpPlugins, {dir: 'dist/dart/angular2'}));
gulp.task('test.unit.tools/ci', function(done) {
runJasmineTests(['dist/tools/**/*.spec.js', 'tools/**/*.spec.js'], done);
});
gulp.task('test.unit.tools', ['build/clean.tools'], function(neverDone) {
var watch = require('./tools/build/watch');
treatTestErrorsAsFatal = false;
watch(['tools/**', '!tools/**/test-fixtures/**'], ['!build.tools', 'test.unit.tools/ci']);
});
// ------------------
// server tests
// These tests run on the VM on the command-line and are
// allowed to access the file system and network.
gulp.task('test.server.dart', runServerDartTests(gulp, gulpPlugins, {dest: 'dist/dart'}));
// -----------------
// test builders
gulp.task('test.transpiler.unittest',
function(done) { runJasmineTests(['tools/transpiler/unittest/**/*.js'], done); });
// -----------------
// Pre-test checks
gulp.task('pre-test-checks', function(done) {
runSequence('build/checkCircularDependencies', sequenceComplete(done));
});
// -----------------
// Checks which should fail the build, but should not block us running the tests.
// This task is run in a separate travis worker, so these checks provide faster
// feedback while allowing tests to execute.
gulp.task('static-checks', ['!build.tools'], function(done) {
runSequence(
// We do not run test.typings here because it requires building, which is too slow.
['enforce-format', 'lint'], sequenceComplete(done));
});
// -----------------
// Tests for the typings we deliver for TS users
//
// Typings are contained in individual .d.ts files produced by the compiler,
// distributed in our npm package, and loaded from node_modules by
// the typescript compiler.
// Make sure the typings tests are isolated, by running in a tempdir