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')();
|
2014-10-28 06:45:48 -04:00
|
|
|
var runSequence = require('run-sequence');
|
2014-12-05 19:26:30 -05:00
|
|
|
var merge = require('merge');
|
|
|
|
var gulpTraceur = require('./tools/transpiler/gulp-traceur');
|
2014-10-08 16:15:38 -04:00
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
var clean = require('./tools/build/clean');
|
|
|
|
var deps = require('./tools/build/deps');
|
|
|
|
var transpile = require('./tools/build/transpile');
|
|
|
|
var html = require('./tools/build/html');
|
|
|
|
var benchpress = require('./tools/build/benchpress');
|
|
|
|
var pubspec = require('./tools/build/pubspec');
|
|
|
|
var dartanalyzer = require('./tools/build/dartanalyzer');
|
|
|
|
var jsserve = require('./tools/build/jsserve');
|
|
|
|
var pubserve = require('./tools/build/pubserve');
|
|
|
|
var DART_SDK = require('./tools/build/dartdetect')(gulp);
|
|
|
|
// -----------------------
|
|
|
|
// configuration
|
2014-09-18 17:56:38 -04:00
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
var _COMPILER_CONFIG_JS_DEFAULT = {
|
2014-10-30 13:52:32 -04:00
|
|
|
sourceMaps: true,
|
2014-09-24 23:20:59 -04:00
|
|
|
annotations: true, // parse annotations
|
|
|
|
types: true, // parse types
|
|
|
|
script: false, // parse as a module
|
2014-11-07 12:31:51 -05:00
|
|
|
memberVariables: true, // parse class fields
|
2014-12-05 19:26:30 -05:00
|
|
|
modules: 'instantiate'
|
2014-09-24 23:20:59 -04:00
|
|
|
};
|
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
var _HTLM_DEFAULT_SCRIPTS_JS = [
|
|
|
|
{src: '/deps/traceur-runtime.js', mimeType: 'text/javascript'},
|
|
|
|
{src: '/rtts_assert/lib/rtts_assert.js', mimeType: 'text/javascript'},
|
|
|
|
{src: '/deps/es6-module-loader-sans-promises.src.js', mimeType: 'text/javascript'},
|
2014-12-10 13:48:37 -05:00
|
|
|
{src: '/deps/zone.js', mimeType: 'text/javascript'},
|
2014-12-05 19:26:30 -05:00
|
|
|
{src: '/deps/system.src.js', mimeType: 'text/javascript'},
|
|
|
|
{src: '/deps/extension-register.js', mimeType: 'text/javascript'},
|
|
|
|
{src: '/deps/runtime_paths.js', mimeType: 'text/javascript'},
|
|
|
|
{
|
|
|
|
inline: 'System.import(\'$MODULENAME$\').then(function(m) { m.main(); }, console.log.bind(console))',
|
|
|
|
mimeType: 'text/javascript'
|
2014-12-03 09:21:57 -05:00
|
|
|
}
|
2014-12-05 19:26:30 -05:00
|
|
|
];
|
2014-09-25 17:04:46 -04:00
|
|
|
|
2014-09-18 17:56:38 -04:00
|
|
|
|
2014-12-05 19:26:30 -05:00
|
|
|
var CONFIG = {
|
|
|
|
commands: {
|
|
|
|
pub: process.platform === 'win32' ? 'pub.bat' : 'pub',
|
|
|
|
dartanalyzer: process.platform === "win32" ? "dartanalyzer.bat" : "dartanalyzer"
|
2014-09-18 17:56:38 -04:00
|
|
|
},
|
2014-12-05 19:26:30 -05:00
|
|
|
dest: {
|
|
|
|
js: {
|
|
|
|
all: 'dist/js',
|
|
|
|
dev: 'dist/js/dev',
|
|
|
|
prod: 'dist/js/prod'
|
|
|
|
},
|
|
|
|
dart: 'dist/dart'
|
|
|
|
},
|
|
|
|
srcFolderMapping: {
|
|
|
|
'default': 'lib',
|
|
|
|
// need a tmp folder as benchpress does not support
|
|
|
|
// inplace generation of the benchmarks...
|
2014-12-08 14:14:05 -05:00
|
|
|
'**/benchmark*/**': 'perf_tmp',
|
|
|
|
'**/example*/**': 'web'
|
2014-12-05 19:26:30 -05:00
|
|
|
},
|
|
|
|
deps: {
|
|
|
|
js: [
|
|
|
|
gulpTraceur.RUNTIME_PATH,
|
|
|
|
"node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js",
|
|
|
|
"node_modules/systemjs/dist/system.src.js",
|
|
|
|
"node_modules/systemjs/lib/extension-register.js",
|
2014-12-10 13:48:37 -05:00
|
|
|
"node_modules/zone.js/zone.js",
|
2014-12-05 19:26:30 -05:00
|
|
|
"tools/build/runtime_paths.js",
|
|
|
|
"node_modules/angular/angular.js"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
transpile: {
|
|
|
|
src: {
|
|
|
|
js: ['modules/**/*.js', 'modules/**/*.es6'],
|
|
|
|
dart: ['modules/**/*.js']
|
|
|
|
},
|
|
|
|
copy: {
|
|
|
|
js: ['modules/**/*.es5'],
|
|
|
|
dart: ['modules/**/*.dart']
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
js: {
|
|
|
|
dev: merge(true, _COMPILER_CONFIG_JS_DEFAULT, {
|
|
|
|
typeAssertionModule: 'rtts_assert/rtts_assert',
|
|
|
|
typeAssertions: true
|
|
|
|
}),
|
|
|
|
prod: merge(true, _COMPILER_CONFIG_JS_DEFAULT, {
|
|
|
|
typeAssertions: false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
dart: {
|
|
|
|
sourceMaps: true,
|
|
|
|
annotations: true, // parse annotations
|
|
|
|
types: true, // parse types
|
|
|
|
script: false, // parse as a module
|
|
|
|
memberVariables: true, // parse class fields
|
|
|
|
outputLanguage: 'dart'
|
2014-10-02 15:27:01 -04:00
|
|
|
}
|
2014-12-05 19:26:30 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
html: {
|
|
|
|
src: {
|
|
|
|
js: ['modules/*/src/**/*.html'],
|
|
|
|
dart: ['modules/*/src/**/*.html']
|
|
|
|
},
|
|
|
|
scriptsPerFolder: {
|
|
|
|
js: {
|
|
|
|
default: _HTLM_DEFAULT_SCRIPTS_JS,
|
|
|
|
'benchmarks_external/**':
|
|
|
|
[{ src: '/deps/angular.js', mimeType: 'text/javascript' }].concat(_HTLM_DEFAULT_SCRIPTS_JS)
|
|
|
|
},
|
|
|
|
dart: {
|
|
|
|
default: [
|
|
|
|
{src: '$MODULENAME_WITHOUT_PATH$.dart', mimeType: 'application/dart'},
|
|
|
|
{src: 'packages/browser/dart.js', mimeType: 'text/javascript'}
|
|
|
|
]
|
2014-10-02 15:27:01 -04:00
|
|
|
}
|
2014-12-05 19:26:30 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
benchpress: {
|
|
|
|
configFile: {
|
|
|
|
content: 'module.exports=function(){};\n',
|
|
|
|
name: 'bp.conf.js'
|
|
|
|
},
|
|
|
|
mainHtmls: '*/perf_tmp/**/main.html',
|
|
|
|
outputFolderName: 'web'
|
|
|
|
},
|
|
|
|
pubspec: {
|
|
|
|
src: 'modules/*/pubspec.yaml'
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
}));
|
|
|
|
|
|
|
|
// ------------
|
|
|
|
// deps
|
|
|
|
|
|
|
|
gulp.task('build/deps.js.dev', deps(gulp, gulpPlugins, {
|
|
|
|
src: CONFIG.deps.js,
|
|
|
|
dest: CONFIG.dest.js.dev
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('build/deps.js.prod', deps(gulp, gulpPlugins, {
|
|
|
|
src: CONFIG.deps.js,
|
|
|
|
dest: CONFIG.dest.js.prod
|
|
|
|
}));
|
|
|
|
|
|
|
|
// ------------
|
|
|
|
// transpile
|
|
|
|
|
|
|
|
gulp.task('build/transpile.js.dev', transpile(gulp, gulpPlugins, {
|
|
|
|
src: CONFIG.transpile.src.js,
|
|
|
|
copy: CONFIG.transpile.copy.js,
|
|
|
|
dest: CONFIG.dest.js.dev,
|
|
|
|
outputExt: 'js',
|
|
|
|
options: CONFIG.transpile.options.js.dev,
|
|
|
|
srcFolderMapping: CONFIG.srcFolderMapping
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('build/transpile.js.prod', transpile(gulp, gulpPlugins, {
|
|
|
|
src: CONFIG.transpile.src.js,
|
|
|
|
copy: CONFIG.transpile.copy.js,
|
|
|
|
dest: CONFIG.dest.js.prod,
|
|
|
|
outputExt: 'js',
|
|
|
|
options: CONFIG.transpile.options.js.prod,
|
|
|
|
srcFolderMapping: CONFIG.srcFolderMapping
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('build/transpile.dart', transpile(gulp, gulpPlugins, {
|
|
|
|
src: CONFIG.transpile.src.dart,
|
|
|
|
copy: CONFIG.transpile.copy.dart,
|
|
|
|
dest: CONFIG.dest.dart,
|
|
|
|
outputExt: 'dart',
|
|
|
|
options: CONFIG.transpile.options.dart,
|
|
|
|
srcFolderMapping: CONFIG.srcFolderMapping
|
|
|
|
}));
|
|
|
|
|
|
|
|
// ------------
|
|
|
|
// html
|
|
|
|
|
|
|
|
gulp.task('build/html.js.dev', html(gulp, gulpPlugins, {
|
|
|
|
src: CONFIG.html.src.js,
|
|
|
|
dest: CONFIG.dest.js.dev,
|
|
|
|
srcFolderMapping: CONFIG.srcFolderMapping,
|
|
|
|
scriptsPerFolder: CONFIG.html.scriptsPerFolder.js
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('build/html.js.prod', html(gulp, gulpPlugins, {
|
|
|
|
src: CONFIG.html.src.js,
|
|
|
|
dest: CONFIG.dest.js.prod,
|
|
|
|
srcFolderMapping: CONFIG.srcFolderMapping,
|
|
|
|
scriptsPerFolder: CONFIG.html.scriptsPerFolder.js
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('build/html.dart', html(gulp, gulpPlugins, {
|
|
|
|
src: CONFIG.html.src.dart,
|
|
|
|
dest: CONFIG.dest.dart,
|
|
|
|
srcFolderMapping: CONFIG.srcFolderMapping,
|
|
|
|
scriptsPerFolder: CONFIG.html.scriptsPerFolder.dart
|
|
|
|
}));
|
|
|
|
|
|
|
|
// ------------
|
|
|
|
// benchpress
|
|
|
|
|
|
|
|
gulp.task('build/benchpress.js.dev', benchpress(gulp, gulpPlugins, {
|
|
|
|
mainHtmls: CONFIG.benchpress.mainHtmls,
|
|
|
|
configFile: CONFIG.benchpress.configFile,
|
|
|
|
buildDir: CONFIG.dest.js.dev,
|
|
|
|
outputFolderName: CONFIG.benchpress.outputFolderName
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('build/benchpress.js.prod', benchpress(gulp, gulpPlugins, {
|
|
|
|
mainHtmls: CONFIG.benchpress.mainHtmls,
|
|
|
|
configFile: CONFIG.benchpress.configFile,
|
|
|
|
buildDir: CONFIG.dest.js.prod,
|
|
|
|
outputFolderName: CONFIG.benchpress.outputFolderName
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('build/benchpress.dart', benchpress(gulp, gulpPlugins, {
|
|
|
|
mainHtmls: CONFIG.benchpress.mainHtmls,
|
|
|
|
configFile: CONFIG.benchpress.configFile,
|
|
|
|
buildDir: CONFIG.dest.dart,
|
|
|
|
outputFolderName: CONFIG.benchpress.outputFolderName
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
// ------------
|
|
|
|
// pubspec
|
|
|
|
|
|
|
|
gulp.task('build/pubspec.dart', pubspec(gulp, gulpPlugins, {
|
|
|
|
src: CONFIG.pubspec.src,
|
|
|
|
dest: CONFIG.dest.dart,
|
|
|
|
command: DART_SDK.PUB
|
|
|
|
}));
|
|
|
|
|
|
|
|
// ------------
|
|
|
|
// pubspec
|
|
|
|
|
|
|
|
gulp.task('build/analyze.dart', dartanalyzer(gulp, gulpPlugins, {
|
|
|
|
dest: CONFIG.dest.dart,
|
|
|
|
command: DART_SDK.ANALYZER,
|
|
|
|
srcFolderMapping: CONFIG.srcFolderMapping
|
|
|
|
}));
|
2014-10-08 16:15:38 -04:00
|
|
|
|
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, {
|
|
|
|
path: CONFIG.dest.js.dev
|
|
|
|
}));
|
|
|
|
|
|
|
|
gulp.task('serve.js.prod', jsserve(gulp, gulpPlugins, {
|
|
|
|
path: CONFIG.dest.js.prod
|
|
|
|
}));
|
|
|
|
|
|
|
|
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');
|
|
|
|
gulp.task('docs/dgeni', function() {
|
|
|
|
try {
|
|
|
|
var dgeni = new Dgeni([require('./docs/dgeni-package')]);
|
|
|
|
return dgeni.generate();
|
|
|
|
} catch(x) {
|
|
|
|
console.log(x.stack);
|
|
|
|
throw x;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var bower = require('bower');
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('docs/assets', ['docs/bower'], function() {
|
|
|
|
return gulp.src('docs/bower_components/**/*')
|
2014-12-05 19:26:30 -05:00
|
|
|
.pipe(gulp.dest('dist/docs/lib'));
|
2014-12-04 09:02:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('docs/app', function() {
|
|
|
|
return gulp.src('docs/app/**/*')
|
2014-12-05 19:26:30 -05:00
|
|
|
.pipe(gulp.dest('dist/docs'));
|
2014-12-04 09:02:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('docs', ['docs/assets', 'docs/app', 'docs/dgeni']);
|
2014-12-06 05:41:07 -05:00
|
|
|
gulp.task('docs/watch', function() {
|
|
|
|
return gulp.watch('docs/app/**/*', ['docs/app']);
|
2014-12-04 09:02:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
var jasmine = require('gulp-jasmine');
|
|
|
|
gulp.task('docs/test', function () {
|
|
|
|
return gulp.src('docs/**/*.spec.js')
|
2014-12-06 05:41:07 -05:00
|
|
|
.pipe(jasmine({
|
|
|
|
includeStackTrace: true
|
|
|
|
}));
|
2014-12-04 09:02:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
var webserver = require('gulp-webserver');
|
|
|
|
gulp.task('docs/serve', function() {
|
2014-12-05 19:26:30 -05:00
|
|
|
gulp.src('dist/docs/')
|
2014-12-04 09:02:03 -05:00
|
|
|
.pipe(webserver({
|
|
|
|
fallback: 'index.html'
|
|
|
|
}));
|
|
|
|
});
|
2014-12-05 19:26:30 -05:00
|
|
|
|
|
|
|
// -----------------
|
|
|
|
// orchestrated targets
|
|
|
|
gulp.task('build.dart', function() {
|
|
|
|
return runSequence(
|
|
|
|
['build/transpile.dart', 'build/html.dart', 'build/pubspec.dart'],
|
|
|
|
'build/benchpress.dart',
|
|
|
|
'build/analyze.dart'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build.js.dev', function() {
|
|
|
|
return runSequence(
|
|
|
|
['build/deps.js.dev', 'build/transpile.js.dev', 'build/html.js.dev'],
|
|
|
|
'build/benchpress.js.dev'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build.js.prod', function() {
|
|
|
|
return runSequence(
|
|
|
|
['build/deps.js.prod', 'build/transpile.js.prod', 'build/html.js.prod'],
|
2014-12-08 14:44:44 -05:00
|
|
|
'build/benchpress.js.prod'
|
2014-12-05 19:26:30 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build.js', ['build.js.dev', 'build.js.prod']);
|
|
|
|
|
|
|
|
gulp.task('clean', ['build/clean.js', 'build/clean.dart']);
|
|
|
|
|
|
|
|
gulp.task('build', ['build.js', 'build.dart']);
|