2015-04-25 17:45:08 -04:00
|
|
|
'use strict';
|
|
|
|
|
2015-02-17 14:56:24 -05:00
|
|
|
var autoprefixer = require('gulp-autoprefixer');
|
2015-04-27 03:46:48 -04:00
|
|
|
var del = require('del');
|
2015-04-01 13:45:56 -04:00
|
|
|
var format = require('gulp-clang-format');
|
2015-04-14 02:56:07 -04:00
|
|
|
var fork = require('child_process').fork;
|
2014-10-28 06:45:48 -04:00
|
|
|
var gulp = require('gulp');
|
2014-12-05 19:26:30 -05:00
|
|
|
var gulpPlugins = require('gulp-load-plugins')();
|
2015-02-17 14:56:24 -05:00
|
|
|
var sass = require('gulp-sass');
|
2015-03-19 14:36:27 -04:00
|
|
|
var shell = require('gulp-shell');
|
2014-10-28 06:45:48 -04:00
|
|
|
var runSequence = require('run-sequence');
|
2015-03-16 13:48:14 -04:00
|
|
|
var madge = require('madge');
|
2014-12-05 19:26:30 -05:00
|
|
|
var merge = require('merge');
|
2015-04-24 18:59:13 -04:00
|
|
|
var merge2 = require('merge2');
|
2015-03-17 19:43:30 -04:00
|
|
|
var path = require('path');
|
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
var clean = require('./tools/build/clean');
|
|
|
|
var transpile = require('./tools/build/transpile');
|
2015-02-23 20:56:47 -05:00
|
|
|
var pubget = require('./tools/build/pubget');
|
2015-02-11 14:40:29 -05:00
|
|
|
var linknodemodules = require('./tools/build/linknodemodules');
|
2014-12-22 20:50:10 -05:00
|
|
|
var pubbuild = require('./tools/build/pubbuild');
|
2014-12-05 19:26:30 -05:00
|
|
|
var dartanalyzer = require('./tools/build/dartanalyzer');
|
|
|
|
var jsserve = require('./tools/build/jsserve');
|
|
|
|
var pubserve = require('./tools/build/pubserve');
|
2015-01-30 14:03:11 -05:00
|
|
|
var rundartpackage = require('./tools/build/rundartpackage');
|
2015-03-17 19:43:30 -04:00
|
|
|
var file2moduleName = require('./tools/build/file2modulename');
|
2015-04-27 19:11:20 -04:00
|
|
|
var karma = require('karma');
|
2014-11-07 12:29:19 -05:00
|
|
|
var minimist = require('minimist');
|
2015-02-20 20:44:23 -05:00
|
|
|
var runServerDartTests = require('./tools/build/run_server_dart_tests');
|
2015-03-30 16:25:18 -04:00
|
|
|
var sourcemaps = require('gulp-sourcemaps');
|
|
|
|
var tsc = require('gulp-typescript');
|
2015-02-23 20:56:47 -05:00
|
|
|
var util = require('./tools/build/util');
|
2015-03-23 16:18:05 -04:00
|
|
|
var bundler = require('./tools/build/bundle');
|
2015-04-02 22:53:11 -04:00
|
|
|
var replace = require('gulp-replace');
|
|
|
|
var insert = require('gulp-insert');
|
2015-04-13 12:52:02 -04:00
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
|
|
|
|
// 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');
|
2015-04-13 12:52:02 -04:00
|
|
|
}
|
2015-04-26 03:31:53 -04:00
|
|
|
|
|
|
|
var angularBuilder = {
|
|
|
|
rebuildBrowserDevTree: throwToolsBuildMissingError,
|
|
|
|
rebuildBrowserProdTree: throwToolsBuildMissingError,
|
|
|
|
rebuildNodeTree: throwToolsBuildMissingError,
|
|
|
|
rebuildDartTree: throwToolsBuildMissingError,
|
|
|
|
cleanup: function() {}
|
|
|
|
};
|
2014-12-22 20:50:10 -05:00
|
|
|
|
2015-03-19 14:36:27 -04:00
|
|
|
// Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped.
|
2015-03-23 16:18:05 -04:00
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
var DART_SDK = require('./tools/build/dartdetect')(gulp);
|
2015-03-23 16:18:05 -04:00
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
// -----------------------
|
|
|
|
// configuration
|
2014-09-18 17:56:38 -04:00
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
var CONFIG = {
|
|
|
|
dest: {
|
|
|
|
js: {
|
|
|
|
all: 'dist/js',
|
2015-02-07 00:04:43 -05:00
|
|
|
dev: {
|
|
|
|
es6: 'dist/js/dev/es6',
|
|
|
|
es5: 'dist/js/dev/es5'
|
|
|
|
},
|
|
|
|
prod: {
|
|
|
|
es6: 'dist/js/prod/es6',
|
|
|
|
es5: 'dist/js/prod/es5'
|
|
|
|
},
|
2015-02-11 14:40:29 -05:00
|
|
|
cjs: 'dist/js/cjs',
|
2014-12-22 20:50:10 -05:00
|
|
|
dart2js: 'dist/js/dart2js'
|
2014-12-05 19:26:30 -05:00
|
|
|
},
|
2015-01-06 18:19:22 -05:00
|
|
|
dart: 'dist/dart',
|
2015-01-16 08:21:55 -05:00
|
|
|
docs: 'dist/docs'
|
2014-12-05 19:26:30 -05:00
|
|
|
},
|
2015-01-30 14:03:11 -05:00
|
|
|
formatDart: {
|
|
|
|
packageName: 'dart_style',
|
|
|
|
args: ['dart_style:format', '-w', 'dist/dart']
|
2014-11-17 23:47:05 -05:00
|
|
|
}
|
2014-12-05 19:26:30 -05:00
|
|
|
};
|
2014-10-08 16:15:38 -04:00
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
// ------------
|
|
|
|
// clean
|
|
|
|
|
2015-04-27 03:46:48 -04:00
|
|
|
gulp.task('build/clean.tools', function() {
|
|
|
|
if (rebuildTools && 'AngularBuilder' in global) {
|
|
|
|
del(path.join('dist', 'tools'));
|
|
|
|
};
|
|
|
|
});
|
2015-04-27 02:14:52 -04:00
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
gulp.task('build/clean.js', clean(gulp, gulpPlugins, {
|
|
|
|
path: CONFIG.dest.js.all
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('build/clean.dart', clean(gulp, gulpPlugins, {
|
|
|
|
path: CONFIG.dest.dart
|
|
|
|
}));
|
|
|
|
|
2015-01-16 08:21:55 -05:00
|
|
|
gulp.task('build/clean.docs', clean(gulp, gulpPlugins, {
|
|
|
|
path: CONFIG.dest.docs
|
|
|
|
}));
|
|
|
|
|
2015-01-06 18:19:22 -05:00
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
// ------------
|
|
|
|
// transpile
|
|
|
|
|
2015-04-26 04:04:28 -04:00
|
|
|
gulp.task('build/tree.dart', ['build.tools'], function() {
|
2015-04-26 03:31:53 -04:00
|
|
|
return angularBuilder.rebuildDartTree();
|
2015-03-18 17:42:18 -04:00
|
|
|
});
|
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
// ------------
|
|
|
|
// pubspec
|
|
|
|
|
2015-03-19 14:36:27 -04:00
|
|
|
// 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` over CONFIG.dest.dart
|
|
|
|
gulp.task('build/pubspec.dart', pubget.subDir(gulp, gulpPlugins, {
|
2015-02-23 20:56:47 -05:00
|
|
|
dir: CONFIG.dest.dart,
|
2014-12-05 19:26:30 -05:00
|
|
|
command: DART_SDK.PUB
|
|
|
|
}));
|
|
|
|
|
|
|
|
// ------------
|
2014-12-22 20:50:10 -05:00
|
|
|
// dartanalyzer
|
2014-12-05 19:26:30 -05:00
|
|
|
|
|
|
|
gulp.task('build/analyze.dart', dartanalyzer(gulp, gulpPlugins, {
|
|
|
|
dest: CONFIG.dest.dart,
|
2015-02-02 19:25:34 -05:00
|
|
|
command: DART_SDK.ANALYZER
|
2014-12-05 19:26:30 -05:00
|
|
|
}));
|
2014-10-08 16:15:38 -04:00
|
|
|
|
2014-12-22 20:50:10 -05:00
|
|
|
// ------------
|
|
|
|
// pubbuild
|
|
|
|
|
|
|
|
gulp.task('build/pubbuild.dart', pubbuild(gulp, gulpPlugins, {
|
|
|
|
src: CONFIG.dest.dart,
|
|
|
|
dest: CONFIG.dest.js.dart2js,
|
|
|
|
command: DART_SDK.PUB
|
|
|
|
}));
|
|
|
|
|
2015-01-30 14:03:11 -05:00
|
|
|
// ------------
|
2015-04-01 13:45:56 -04:00
|
|
|
// formatting
|
2015-01-30 14:03:11 -05:00
|
|
|
|
|
|
|
gulp.task('build/format.dart', rundartpackage(gulp, gulpPlugins, {
|
|
|
|
pub: DART_SDK.PUB,
|
|
|
|
packageName: CONFIG.formatDart.packageName,
|
|
|
|
args: CONFIG.formatDart.args
|
|
|
|
}));
|
|
|
|
|
2015-04-11 16:29:32 -04:00
|
|
|
function doCheckFormat() {
|
2015-04-25 02:30:30 -04:00
|
|
|
return gulp.src(['Brocfile*.js', 'modules/**/*.ts', 'tools/**/*.ts', '!**/typings/**/*.d.ts',
|
|
|
|
'!tools/broccoli/tree-differ.ts']) // See https://github.com/angular/clang-format/issues/4
|
2015-04-11 16:29:32 -04:00
|
|
|
.pipe(format.checkFormat('file'));
|
|
|
|
}
|
|
|
|
|
2015-04-01 13:45:56 -04:00
|
|
|
gulp.task('check-format', function() {
|
2015-04-11 16:29:32 -04:00
|
|
|
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: Some files need formatting");
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2015-04-01 13:45:56 -04:00
|
|
|
});
|
|
|
|
|
2015-03-16 13:48:14 -04:00
|
|
|
// ------------
|
|
|
|
// check circular dependencies in Node.js context
|
|
|
|
gulp.task('build/checkCircularDependencies', function (done) {
|
|
|
|
var dependencyObject = madge(CONFIG.dest.js.dev.es6, {
|
|
|
|
format: 'es6',
|
|
|
|
paths: [CONFIG.dest.js.dev.es6],
|
|
|
|
extensions: ['.js', '.es6'],
|
|
|
|
onParseFile: function(data) {
|
|
|
|
data.src = data.src.replace(/import \* as/g, "//import * as");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var circularDependencies = dependencyObject.circular().getArray();
|
|
|
|
if (circularDependencies.length > 0) {
|
|
|
|
console.log(circularDependencies);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2014-09-18 17:56:38 -04:00
|
|
|
// ------------------
|
2014-12-05 19:26:30 -05:00
|
|
|
// web servers
|
|
|
|
gulp.task('serve.js.dev', jsserve(gulp, gulpPlugins, {
|
2015-02-07 00:04:43 -05:00
|
|
|
path: CONFIG.dest.js.dev.es5,
|
2014-12-22 20:50:10 -05:00
|
|
|
port: 8000
|
2014-12-05 19:26:30 -05:00
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('serve.js.prod', jsserve(gulp, gulpPlugins, {
|
2015-02-07 00:04:43 -05:00
|
|
|
path: CONFIG.dest.js.prod.es5,
|
2014-12-22 20:50:10 -05:00
|
|
|
port: 8001
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('serve.js.dart2js', jsserve(gulp, gulpPlugins, {
|
|
|
|
path: CONFIG.dest.js.dart2js,
|
|
|
|
port: 8002
|
2014-12-05 19:26:30 -05:00
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('serve/examples.dart', pubserve(gulp, gulpPlugins, {
|
|
|
|
command: DART_SDK.PUB,
|
|
|
|
path: CONFIG.dest.dart + '/examples'
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('serve/benchmarks.dart', pubserve(gulp, gulpPlugins, {
|
|
|
|
command: DART_SDK.PUB,
|
|
|
|
path: CONFIG.dest.dart + '/benchmarks'
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('serve/benchmarks_external.dart', pubserve(gulp, gulpPlugins, {
|
|
|
|
command: DART_SDK.PUB,
|
|
|
|
path: CONFIG.dest.dart + '/benchmarks_external'
|
|
|
|
}));
|
2014-12-04 09:02:03 -05:00
|
|
|
|
|
|
|
// --------------
|
|
|
|
// doc generation
|
|
|
|
var Dgeni = require('dgeni');
|
|
|
|
var bower = require('bower');
|
2015-03-17 12:49:31 -04:00
|
|
|
var webserver = require('gulp-webserver');
|
|
|
|
|
2014-12-04 09:02:03 -05:00
|
|
|
gulp.task('docs/bower', function() {
|
|
|
|
var bowerTask = bower.commands.install(undefined, undefined, { cwd: 'docs' });
|
|
|
|
bowerTask.on('log', function (result) {
|
|
|
|
console.log('bower:', result.id, result.data.endpoint.name);
|
|
|
|
});
|
|
|
|
bowerTask.on('error', function(error) {
|
|
|
|
console.log(error);
|
|
|
|
});
|
|
|
|
return bowerTask;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-04-25 17:45:08 -04:00
|
|
|
function createDocsTasks(publicBuild) {
|
|
|
|
var dgeniPackage = publicBuild ? './docs/public-docs-package' : './docs/dgeni-package';
|
|
|
|
var distDocsPath = publicBuild ? 'dist/public_docs' : 'dist/docs';
|
|
|
|
var taskPrefix = publicBuild ? 'public_docs' : 'docs';
|
2014-12-04 09:02:03 -05:00
|
|
|
|
2015-03-17 12:49:31 -04:00
|
|
|
gulp.task(taskPrefix + '/dgeni', function() {
|
|
|
|
try {
|
|
|
|
var dgeni = new Dgeni([require(dgeniPackage)]);
|
|
|
|
return dgeni.generate();
|
|
|
|
} catch(x) {
|
2015-04-15 18:35:38 -04:00
|
|
|
console.log(x);
|
2015-03-17 12:49:31 -04:00
|
|
|
console.log(x.stack);
|
|
|
|
throw x;
|
|
|
|
}
|
|
|
|
});
|
2014-12-04 09:02:03 -05:00
|
|
|
|
2015-03-17 12:49:31 -04:00
|
|
|
gulp.task(taskPrefix + '/assets', ['docs/bower'], function() {
|
|
|
|
return gulp.src('docs/bower_components/**/*')
|
|
|
|
.pipe(gulp.dest(distDocsPath + '/lib'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task(taskPrefix + '/app', function() {
|
|
|
|
return gulp.src('docs/app/**/*')
|
|
|
|
.pipe(gulp.dest(distDocsPath));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task(taskPrefix, [taskPrefix + '/assets', taskPrefix + '/app', taskPrefix + '/dgeni']);
|
|
|
|
gulp.task(taskPrefix + '/watch', function() {
|
|
|
|
return gulp.watch('docs/app/**/*', [taskPrefix + '/app']);
|
|
|
|
});
|
|
|
|
|
2015-04-26 05:40:13 -04:00
|
|
|
gulp.task(taskPrefix + '/test', function (done) {
|
|
|
|
fork('./tools/traceur-jasmine', ['docs/**/*.spec.js'], {
|
|
|
|
stdio: 'inherit'
|
|
|
|
}).on('close', function (exitCode) {
|
|
|
|
done(exitCode);
|
|
|
|
});
|
2015-03-17 12:49:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task(taskPrefix + '/serve', function() {
|
|
|
|
gulp.src(distDocsPath + '/')
|
|
|
|
.pipe(webserver({
|
|
|
|
fallback: 'index.html'
|
2014-12-06 05:41:07 -05:00
|
|
|
}));
|
2015-03-17 12:49:31 -04:00
|
|
|
});
|
|
|
|
}
|
2014-12-04 09:02:03 -05:00
|
|
|
|
2015-03-17 12:49:31 -04:00
|
|
|
createDocsTasks(true);
|
|
|
|
createDocsTasks(false);
|
2014-12-05 19:26:30 -05:00
|
|
|
|
2015-04-25 17:29:20 -04:00
|
|
|
gulp.task('docs/angular.io', function() {
|
|
|
|
try {
|
|
|
|
var dgeni = new Dgeni([require('./docs/angular.io-package')]);
|
|
|
|
return dgeni.generate();
|
|
|
|
} catch(x) {
|
|
|
|
console.log(x);
|
|
|
|
console.log(x.stack);
|
|
|
|
throw x;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-11-07 12:29:19 -05:00
|
|
|
// ------------------
|
2015-03-19 14:36:27 -04:00
|
|
|
// CI tests suites
|
|
|
|
|
|
|
|
gulp.task('test.js', function(done) {
|
2015-04-27 02:16:10 -04:00
|
|
|
runSequence('test.unit.tools/ci', 'test.transpiler.unittest', 'docs/test', 'test.unit.js/ci',
|
2015-03-19 14:36:27 -04:00
|
|
|
'test.unit.cjs/ci', done);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('test.dart', function(done) {
|
|
|
|
runSequence('test.transpiler.unittest', 'docs/test', 'test.unit.dart/ci', done);
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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']))
|
|
|
|
|
2015-02-20 20:44:23 -05:00
|
|
|
// karma tests
|
|
|
|
// These tests run in the browser and are allowed to access
|
|
|
|
// HTML DOM APIs.
|
2014-11-07 12:29:19 -05:00
|
|
|
function getBrowsersFromCLI() {
|
|
|
|
var args = minimist(process.argv.slice(2));
|
|
|
|
return [args.browsers?args.browsers:'DartiumWithWebPlatform']
|
|
|
|
}
|
2015-04-27 19:11:20 -04:00
|
|
|
|
|
|
|
gulp.task('test.unit.js', ['build/clean.js'], function (neverDone) {
|
|
|
|
|
|
|
|
function buildAndTest() {
|
|
|
|
runSequence(
|
|
|
|
'broccoli.js.dev',
|
|
|
|
'test.unit.dev/karma-run'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
karma.server.start({configFile: __dirname + '/karma-js.conf.js'});
|
|
|
|
buildAndTest();
|
|
|
|
|
|
|
|
gulp.watch('modules/**', function() {
|
|
|
|
console.log('args', arguments);
|
|
|
|
buildAndTest();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('test.unit.dev/karma-run', function(done) {
|
|
|
|
karma.runner.run({configFile: __dirname + '/karma-js.conf.js'}, done);
|
2014-11-07 12:29:19 -05:00
|
|
|
});
|
2015-04-27 19:11:20 -04:00
|
|
|
|
|
|
|
|
2015-02-20 20:44:23 -05:00
|
|
|
gulp.task('test.unit.dart', function (done) {
|
2015-04-27 19:11:20 -04:00
|
|
|
karma.server.start({configFile: __dirname + '/karma-dart.conf.js'}, done);
|
2014-11-07 12:29:19 -05:00
|
|
|
});
|
2015-04-27 19:11:20 -04:00
|
|
|
|
2015-02-20 20:44:23 -05:00
|
|
|
gulp.task('test.unit.js/ci', function (done) {
|
2015-04-27 19:11:20 -04:00
|
|
|
karma.server.start({configFile: __dirname + '/karma-js.conf.js',
|
|
|
|
singleRun: true, reporters: ['dots'], browsers: getBrowsersFromCLI()}, done);
|
2014-11-07 12:29:19 -05:00
|
|
|
});
|
2015-04-27 19:11:20 -04:00
|
|
|
|
2015-02-20 20:44:23 -05:00
|
|
|
gulp.task('test.unit.dart/ci', function (done) {
|
2015-04-27 19:11:20 -04:00
|
|
|
karma.server.start({configFile: __dirname + '/karma-dart.conf.js',
|
2015-02-20 20:44:23 -05:00
|
|
|
singleRun: true, reporters: ['dots'], browsers: getBrowsersFromCLI()}, done);
|
2014-11-07 12:29:19 -05:00
|
|
|
});
|
2015-04-13 12:59:37 -04:00
|
|
|
|
2015-04-14 02:56:07 -04:00
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
gulp.task('test.unit.cjs/ci', function(done) {
|
|
|
|
fork('./tools/traceur-jasmine', ['dist/js/cjs/angular2/test/**/*_spec.js'], {
|
|
|
|
stdio: 'inherit'
|
|
|
|
}).on('close', function (exitCode) {
|
|
|
|
done(exitCode);
|
2015-03-17 19:43:30 -04:00
|
|
|
});
|
2015-04-26 03:31:53 -04:00
|
|
|
});
|
2015-04-14 02:56:07 -04:00
|
|
|
|
|
|
|
|
2015-04-27 03:46:48 -04:00
|
|
|
gulp.task('test.unit.cjs', ['build/clean.js'], function (done) {
|
|
|
|
function buildAndTest() {
|
|
|
|
runSequence(
|
|
|
|
'build.js.cjs',
|
|
|
|
'test.unit.cjs/ci'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildAndTest();
|
|
|
|
|
|
|
|
gulp.watch('modules/**', buildAndTest);
|
2015-03-01 16:17:36 -05:00
|
|
|
});
|
2015-02-20 20:44:23 -05:00
|
|
|
|
2015-04-24 13:15:52 -04:00
|
|
|
|
2015-04-27 02:14:52 -04:00
|
|
|
gulp.task('test.unit.tools/ci', function(done) {
|
2015-04-26 04:04:28 -04:00
|
|
|
fork('./tools/traceur-jasmine', ['dist/tools/**/*.spec.js'], {
|
2015-04-24 19:23:25 -04:00
|
|
|
stdio: 'inherit'
|
|
|
|
}).on('close', done);
|
|
|
|
});
|
2015-04-24 13:15:52 -04:00
|
|
|
|
|
|
|
|
2015-04-27 02:14:52 -04:00
|
|
|
gulp.task('test.unit.tools', function(done) {
|
2015-04-27 03:46:48 -04:00
|
|
|
rebuildTools = true;
|
|
|
|
|
2015-04-27 02:14:52 -04:00
|
|
|
function buildAndTest() {
|
|
|
|
runSequence(
|
|
|
|
'build.tools',
|
|
|
|
'test.unit.tools/ci'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildAndTest();
|
|
|
|
|
|
|
|
gulp.watch('tools/**', buildAndTest);
|
2015-04-24 13:15:52 -04:00
|
|
|
});
|
|
|
|
|
2015-04-27 03:46:48 -04:00
|
|
|
|
2015-02-20 20:44:23 -05:00
|
|
|
// ------------------
|
|
|
|
// 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
|
2015-04-26 05:40:13 -04:00
|
|
|
gulp.task('test.transpiler.unittest', function(done) {
|
|
|
|
fork('./tools/traceur-jasmine', ['tools/transpiler/unittest/**/*.js'], {
|
|
|
|
stdio: 'inherit'
|
|
|
|
}).on('close', function (exitCode) {
|
|
|
|
done(exitCode);
|
|
|
|
});
|
2015-02-04 17:59:12 -05:00
|
|
|
});
|
2014-11-07 12:29:19 -05:00
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
// -----------------
|
|
|
|
// orchestrated targets
|
2015-02-27 17:50:06 -05:00
|
|
|
|
2015-04-23 20:37:05 -04:00
|
|
|
// Pure Dart packages only contain Dart code and conform to pub package layout.
|
|
|
|
// These packages need no transpilation. All code is copied over to `dist`
|
|
|
|
// unmodified and directory structure is preserved.
|
|
|
|
//
|
|
|
|
// This task also fixes relative `dependency_overrides` paths in `pubspec.yaml`
|
|
|
|
// files.
|
|
|
|
gulp.task('build/pure-packages.dart', function() {
|
|
|
|
var through2 = require('through2');
|
|
|
|
var yaml = require('js-yaml');
|
|
|
|
var originalPrefix = '../../dist/dart/';
|
|
|
|
|
|
|
|
return gulp
|
|
|
|
.src([
|
|
|
|
'modules_dart/**/*.dart',
|
|
|
|
'modules_dart/**/pubspec.yaml',
|
|
|
|
])
|
|
|
|
.pipe(through2.obj(function(file, enc, done) {
|
|
|
|
if (file.path.endsWith('pubspec.yaml')) {
|
|
|
|
// Pure packages specify dependency_overrides relative to
|
|
|
|
// `modules_dart`, so they have to walk up and into `dist`.
|
|
|
|
//
|
|
|
|
// Example:
|
2015-04-24 16:17:36 -04:00
|
|
|
//
|
2015-04-23 20:37:05 -04:00
|
|
|
// dependency_overrides:
|
|
|
|
// angular2:
|
|
|
|
// path: ../../dist/dart/angular2
|
|
|
|
//
|
|
|
|
// When we copy a pure package into `dist` the relative path
|
|
|
|
// must be updated. The code below replaces paths accordingly.
|
|
|
|
// So the example above is turned into:
|
2015-04-24 16:17:36 -04:00
|
|
|
//
|
2015-04-23 20:37:05 -04:00
|
|
|
// dependency_overrides:
|
|
|
|
// angular2:
|
|
|
|
// path: ../angular2
|
|
|
|
//
|
|
|
|
var pubspec = yaml.safeLoad(file.contents.toString());
|
|
|
|
var overrides = pubspec['dependency_overrides'];
|
|
|
|
if (overrides) {
|
|
|
|
Object.keys(overrides).forEach(function(pkg) {
|
|
|
|
var overridePath = overrides[pkg]['path'];
|
|
|
|
if (overridePath.startsWith(originalPrefix)) {
|
|
|
|
overrides[pkg]['path'] = overridePath.replace(originalPrefix, '../');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
file.contents = new Buffer(yaml.safeDump(pubspec));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.push(file);
|
|
|
|
done();
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('dist/dart'));
|
|
|
|
});
|
|
|
|
|
2015-02-27 17:50:06 -05:00
|
|
|
// Builds all Dart packages, but does not compile them
|
|
|
|
gulp.task('build/packages.dart', function(done) {
|
2015-04-23 20:37:05 -04:00
|
|
|
runSequence(
|
|
|
|
'build/tree.dart',
|
|
|
|
// Run after 'build/tree.dart' because broccoli clears the dist/dart folder
|
|
|
|
'build/pure-packages.dart',
|
|
|
|
'build/format.dart',
|
|
|
|
done);
|
2015-02-27 17:50:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// Builds and compiles all Dart packages
|
|
|
|
gulp.task('build.dart', function(done) {
|
|
|
|
runSequence(
|
|
|
|
'build/packages.dart',
|
2015-04-10 02:17:05 -04:00
|
|
|
'build/pubspec.dart',
|
2015-02-27 17:50:06 -05:00
|
|
|
'build/analyze.dart',
|
2014-12-22 20:50:10 -05:00
|
|
|
'build/pubbuild.dart',
|
2015-02-10 18:18:16 -05:00
|
|
|
done
|
2014-12-05 19:26:30 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-04-27 02:14:52 -04:00
|
|
|
|
2015-04-27 03:46:48 -04:00
|
|
|
var rebuildTools = false;
|
|
|
|
|
2015-04-27 02:14:52 -04:00
|
|
|
gulp.task('build.tools', ['build/clean.tools'], function() {
|
2015-04-27 03:46:48 -04:00
|
|
|
if (!rebuildTools && angularBuilder.rebuildNodeTree !== throwToolsBuildMissingError) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-24 19:23:25 -04:00
|
|
|
|
2015-04-26 04:04:28 -04:00
|
|
|
var tsResult = gulp.src('tools/**/*.ts')
|
2015-04-24 18:59:13 -04:00
|
|
|
.pipe(sourcemaps.init())
|
2015-04-24 19:23:25 -04:00
|
|
|
.pipe(tsc({target: 'ES5', module: 'commonjs', reporter: tsc.reporter.nullReporter()}))
|
|
|
|
.on('error', function(error) {
|
|
|
|
// gulp-typescript doesn't propagate errors from the src stream into the js stream so we are
|
|
|
|
// forwarding the error into the merged stream
|
|
|
|
mergedStream.emit('error', error);
|
2015-04-14 14:46:01 -04:00
|
|
|
});
|
2015-04-24 18:59:13 -04:00
|
|
|
|
2015-04-26 04:04:28 -04:00
|
|
|
var destDir = gulp.dest('dist/tools/');
|
2015-04-24 18:59:13 -04:00
|
|
|
|
2015-04-27 03:46:48 -04:00
|
|
|
var mergedStream = merge2([
|
2015-04-24 18:59:13 -04:00
|
|
|
tsResult.js.pipe(sourcemaps.write('.')).pipe(destDir),
|
|
|
|
tsResult.js.pipe(destDir)
|
|
|
|
]).on('end', function() {
|
2015-04-26 04:04:28 -04:00
|
|
|
var AngularBuilder = require('./dist/tools/broccoli/angular_builder').AngularBuilder;
|
|
|
|
angularBuilder = new AngularBuilder('dist');
|
2015-04-24 18:59:13 -04:00
|
|
|
});
|
|
|
|
|
2015-04-24 19:23:25 -04:00
|
|
|
return mergedStream;
|
2015-04-10 19:45:24 -04:00
|
|
|
});
|
|
|
|
|
2015-04-26 04:04:28 -04:00
|
|
|
gulp.task('broccoli.js.dev', ['build.tools'], function() {
|
2015-04-26 03:31:53 -04:00
|
|
|
return angularBuilder.rebuildBrowserDevTree();
|
2015-04-08 11:28:12 -04:00
|
|
|
});
|
2015-04-10 14:48:37 -04:00
|
|
|
|
|
|
|
|
2015-02-10 18:18:16 -05:00
|
|
|
gulp.task('build.js.dev', function(done) {
|
|
|
|
runSequence(
|
2015-04-08 11:28:12 -04:00
|
|
|
'broccoli.js.dev',
|
2015-03-16 13:48:14 -04:00
|
|
|
'build/checkCircularDependencies',
|
2015-04-11 16:29:32 -04:00
|
|
|
'check-format',
|
2015-02-10 18:18:16 -05:00
|
|
|
done
|
2014-12-05 19:26:30 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-04-26 04:04:28 -04:00
|
|
|
gulp.task('build.js.prod', ['build.tools'], function() {
|
2015-04-26 03:31:53 -04:00
|
|
|
return angularBuilder.rebuildBrowserProdTree();
|
2015-04-09 18:56:54 -04:00
|
|
|
});
|
2015-04-26 03:31:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
var firstBuildJsCjs = true;
|
|
|
|
|
2015-04-26 04:04:28 -04:00
|
|
|
gulp.task('build.js.cjs', ['build.tools'], function() {
|
2015-04-26 03:31:53 -04:00
|
|
|
return angularBuilder.rebuildNodeTree().then(function() {
|
|
|
|
if (firstBuildJsCjs) {
|
|
|
|
firstBuildJsCjs = false;
|
|
|
|
console.log('creating node_modules symlink hack');
|
|
|
|
// linknodemodules is all sync
|
|
|
|
linknodemodules(gulp, gulpPlugins, {
|
|
|
|
dir: CONFIG.dest.js.cjs
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
});
|
2015-01-06 18:19:22 -05:00
|
|
|
});
|
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
|
2015-03-23 16:18:05 -04:00
|
|
|
var bundleConfig = {
|
|
|
|
paths: {
|
|
|
|
"*": "dist/js/prod/es6/*.es6",
|
|
|
|
"rx/*": "node_modules/rx/*.js"
|
2015-04-06 19:43:53 -04:00
|
|
|
},
|
|
|
|
meta: {
|
|
|
|
// auto-detection fails to detect properly here - https://github.com/systemjs/builder/issues/123
|
|
|
|
'rx/dist/rx.all': {
|
|
|
|
format: 'cjs'
|
|
|
|
}
|
|
|
|
}
|
2015-03-23 16:18:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// production build
|
|
|
|
gulp.task('bundle.js.prod', ['build.js.prod'], function() {
|
|
|
|
return bundler.bundle(
|
2015-04-02 22:53:11 -04:00
|
|
|
bundleConfig,
|
|
|
|
'angular2/angular2',
|
|
|
|
'./dist/build/angular2.js',
|
|
|
|
{
|
|
|
|
sourceMaps: true
|
|
|
|
});
|
2015-03-23 16:18:05 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// minified production build
|
2015-04-02 22:53:11 -04:00
|
|
|
// TODO: minify zone.js
|
2015-03-23 16:18:05 -04:00
|
|
|
gulp.task('bundle.js.min', ['build.js.prod'], function() {
|
|
|
|
return bundler.bundle(
|
2015-04-02 22:53:11 -04:00
|
|
|
bundleConfig,
|
|
|
|
'angular2/angular2',
|
|
|
|
'./dist/build/angular2.min.js',
|
|
|
|
{
|
|
|
|
sourceMaps: true,
|
|
|
|
minify: true
|
|
|
|
});
|
2015-03-23 16:18:05 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// development build
|
|
|
|
gulp.task('bundle.js.dev', ['build.js.dev'], function() {
|
2015-04-06 19:43:53 -04:00
|
|
|
var devBundleConfig = merge(true, bundleConfig);
|
|
|
|
devBundleConfig.paths =
|
|
|
|
merge(true, devBundleConfig.paths, {
|
2015-04-02 22:53:11 -04:00
|
|
|
"*": "dist/js/dev/es6/*.es6"
|
2015-04-06 19:43:53 -04:00
|
|
|
});
|
|
|
|
return bundler.bundle(
|
|
|
|
devBundleConfig,
|
2015-04-02 22:53:11 -04:00
|
|
|
'angular2/angular2',
|
|
|
|
'./dist/build/angular2.dev.js',
|
2015-04-13 19:48:04 -04:00
|
|
|
{ sourceMaps: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
// self-executing development build
|
|
|
|
// This bundle executes its main module - angular2_sfx, when loaded, without
|
|
|
|
// a corresponding System.import call. It is aimed at ES5 developers that do not
|
|
|
|
// use System loader polyfills (like system.js and es6 loader).
|
|
|
|
// see: https://github.com/systemjs/builder (SFX bundles).
|
|
|
|
gulp.task('bundle.js.sfx.dev', ['build.js.dev'], function() {
|
|
|
|
var devBundleConfig = merge(true, bundleConfig);
|
|
|
|
devBundleConfig.paths =
|
|
|
|
merge(true, devBundleConfig.paths, {
|
|
|
|
'*': 'dist/js/dev/es6/*.es6'
|
2015-04-02 22:53:11 -04:00
|
|
|
});
|
2015-04-13 19:48:04 -04:00
|
|
|
return bundler.bundle(
|
|
|
|
devBundleConfig,
|
|
|
|
'angular2/angular2_sfx',
|
|
|
|
'./dist/build/angular2.sfx.dev.js',
|
|
|
|
{ sourceMaps: true },
|
|
|
|
/* self-exectuting */ true);
|
2015-04-02 22:53:11 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('bundle.js.prod.deps', ['bundle.js.prod'], function() {
|
|
|
|
return bundler.modify(
|
|
|
|
['node_modules/zone.js/zone.js', 'dist/build/angular2.js'], 'angular2.js')
|
|
|
|
.pipe(gulp.dest('dist/bundle'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('bundle.js.min.deps', ['bundle.js.min'], function() {
|
|
|
|
return bundler.modify(
|
|
|
|
['node_modules/zone.js/zone.js', 'dist/build/angular2.min.js'], 'angular2.min.js')
|
|
|
|
.pipe(gulp.dest('dist/bundle'));
|
2015-03-23 16:18:05 -04:00
|
|
|
});
|
|
|
|
|
2015-04-28 21:17:00 -04:00
|
|
|
var JS_DEV_DEPS = ['node_modules/zone.js/zone.js',
|
|
|
|
'node_modules/zone.js/long-stack-trace-zone.js',
|
|
|
|
'node_modules/reflect-metadata/Reflect.js'];
|
2015-04-13 19:48:04 -04:00
|
|
|
|
2015-03-23 16:18:05 -04:00
|
|
|
gulp.task('bundle.js.dev.deps', ['bundle.js.dev'], function() {
|
2015-04-13 19:48:04 -04:00
|
|
|
return bundler.modify(JS_DEV_DEPS.concat(['dist/build/angular2.dev.js']), 'angular2.dev.js')
|
2015-04-28 21:17:00 -04:00
|
|
|
.pipe(insert.append('\nSystem.config({"paths":{"*":"*.js","angular2/*":"angular2/*"}});\n'))
|
2015-04-13 19:48:04 -04:00
|
|
|
.pipe(insert.append('\nzone = zone.fork(Zone.longStackTraceZone);\n'))
|
|
|
|
.pipe(gulp.dest('dist/bundle'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('bundle.js.sfx.dev.deps', ['bundle.js.sfx.dev'], function() {
|
|
|
|
return bundler.modify(JS_DEV_DEPS.concat(['dist/build/angular2.sfx.dev.js']),
|
|
|
|
'angular2.sfx.dev.js')
|
2015-04-02 22:53:11 -04:00
|
|
|
.pipe(insert.append('\nzone = zone.fork(Zone.longStackTraceZone);\n'))
|
|
|
|
.pipe(gulp.dest('dist/bundle'));
|
2015-03-23 16:18:05 -04:00
|
|
|
});
|
|
|
|
|
2015-04-13 19:48:04 -04:00
|
|
|
gulp.task('bundle.js.deps', ['bundle.js.prod.deps', 'bundle.js.dev.deps', 'bundle.js.min.deps', 'bundle.js.sfx.dev.deps']);
|
2014-12-05 19:26:30 -05:00
|
|
|
|
2015-04-13 19:48:04 -04:00
|
|
|
gulp.task('build.js', ['build.js.dev', 'build.js.prod', 'build.js.cjs', 'bundle.js.deps']);
|
2015-04-08 11:28:12 -04:00
|
|
|
|
2015-04-27 02:14:52 -04:00
|
|
|
gulp.task('clean', ['build/clean.tools', 'build/clean.js', 'build/clean.dart', 'build/clean.docs']);
|
2014-12-05 19:26:30 -05:00
|
|
|
|
2015-02-11 14:40:29 -05:00
|
|
|
gulp.task('build', ['build.js', 'build.dart']);
|
2015-02-17 14:56:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
// ------------
|
|
|
|
// angular material testing rules
|
2015-04-23 16:15:20 -04:00
|
|
|
gulp.task('build.js.material', ['build.js.dev'], function() {
|
2015-02-17 14:56:24 -05:00
|
|
|
return gulp.src('modules/*/src/**/*.scss')
|
|
|
|
.pipe(sass())
|
|
|
|
.pipe(autoprefixer())
|
|
|
|
.pipe(gulp.dest(CONFIG.dest.js.dev.es5));
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: this target is temporary until we find a way to use the SASS transformer
|
2015-04-23 16:15:20 -04:00
|
|
|
gulp.task('build.dart.material', ['build/packages.dart'], function() {
|
|
|
|
return gulp.src('dist/dart/angular2_material/src/**/*.scss')
|
2015-02-17 14:56:24 -05:00
|
|
|
.pipe(sass())
|
|
|
|
.pipe(autoprefixer())
|
|
|
|
.pipe(gulp.dest('dist/dart/angular2_material/lib/src'));
|
|
|
|
});
|
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
|
|
|
|
gulp.task('cleanup.builder', function() {
|
|
|
|
angularBuilder.cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// register cleanup listener for ctrl+c/kill used to quit any persistent task (autotest or serve tasks)
|
|
|
|
process.on('SIGINT', function() {
|
|
|
|
gulp.start('cleanup.builder');
|
|
|
|
process.exit();
|
|
|
|
});
|
|
|
|
|
|
|
|
// register cleanup listener for all non-persistent tasks
|
|
|
|
process.on('beforeExit', function() {
|
|
|
|
gulp.start('cleanup.builder');
|
|
|
|
});
|