2015-04-13 19:22:23 -04:00
|
|
|
/// <reference path="../../typings/node/node.d.ts" />
|
2015-05-28 18:54:54 -04:00
|
|
|
/// <reference path="../angular_builder.d.ts" />
|
2015-04-13 19:39:47 -04:00
|
|
|
'use strict';
|
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
import {MultiCopy} from './../multi_copy';
|
2015-05-04 11:19:25 -04:00
|
|
|
import destCopy from '../broccoli-dest-copy';
|
2015-04-13 19:39:47 -04:00
|
|
|
var Funnel = require('broccoli-funnel');
|
2015-05-21 12:07:52 -04:00
|
|
|
import mergeTrees from '../broccoli-merge-trees';
|
2015-04-13 19:39:47 -04:00
|
|
|
var path = require('path');
|
2015-06-09 13:35:58 -04:00
|
|
|
import renderLodashTemplate from '../broccoli-lodash';
|
2015-04-13 19:39:47 -04:00
|
|
|
var stew = require('broccoli-stew');
|
2015-05-08 13:46:38 -04:00
|
|
|
import ts2dart from '../broccoli-ts2dart';
|
2015-05-28 18:54:54 -04:00
|
|
|
import dartfmt from '../broccoli-dartfmt';
|
2015-06-08 14:05:32 -04:00
|
|
|
import replace from '../broccoli-replace';
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-04-13 19:22:23 -04:00
|
|
|
/**
|
|
|
|
* A funnel starting at modules, including the given filters, and moving into the root.
|
|
|
|
* @param include Include glob filters.
|
|
|
|
*/
|
|
|
|
function modulesFunnel(include: string[], exclude?: string[]) {
|
|
|
|
return new Funnel('modules', {include, destDir: '/', exclude});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces $SCRIPT$ in .html files with actual <script> tags.
|
|
|
|
*/
|
2015-06-08 22:01:22 -04:00
|
|
|
function replaceScriptTagInHtml(placeholder: string, relativePath: string): string {
|
2015-04-13 19:22:23 -04:00
|
|
|
var scriptTags = '';
|
|
|
|
if (relativePath.match(/^benchmarks/)) {
|
|
|
|
scriptTags += '<script src="url_params_to_form.js" type="text/javascript"></script>\n';
|
|
|
|
}
|
2015-06-25 10:56:59 -04:00
|
|
|
var scriptName = relativePath.replace(/\\/g, '/').replace(/.*\/([^/]+)\.html$/, '$1.dart');
|
2015-04-13 19:22:23 -04:00
|
|
|
scriptTags += '<script src="' + scriptName + '" type="application/dart"></script>\n' +
|
|
|
|
'<script src="packages/browser/dart.js" type="text/javascript"></script>';
|
2015-06-08 22:01:22 -04:00
|
|
|
return scriptTags;
|
2015-04-13 19:22:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function stripModulePrefix(relativePath: string): string {
|
|
|
|
if (!relativePath.match(/^modules\//)) {
|
|
|
|
throw new Error('Expected path to root at modules/: ' + relativePath);
|
|
|
|
}
|
|
|
|
return relativePath.replace(/^modules\//, '');
|
|
|
|
}
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-04-13 19:22:23 -04:00
|
|
|
function getSourceTree() {
|
|
|
|
// Transpile everything in 'modules' except for rtts_assertions.
|
2015-04-29 02:07:55 -04:00
|
|
|
var tsInputTree = modulesFunnel(['**/*.js', '**/*.ts', '**/*.dart'],
|
|
|
|
// TODO(jeffbcross): add http when lib supports dart
|
|
|
|
[
|
|
|
|
'rtts_assert/**/*',
|
|
|
|
'examples/e2e_test/http/**/*',
|
|
|
|
'examples/src/http/**/*',
|
|
|
|
'angular2/src/http/**/*',
|
|
|
|
'angular2/test/http/**/*',
|
|
|
|
'angular2/http.ts'
|
|
|
|
]);
|
2015-06-11 21:50:41 -04:00
|
|
|
var transpiled = ts2dart(tsInputTree, {
|
|
|
|
generateLibraryName: true,
|
|
|
|
generateSourceMap: false,
|
|
|
|
translateBuiltins: true,
|
|
|
|
});
|
2015-04-13 19:22:23 -04:00
|
|
|
// Native sources, dart only examples, etc.
|
2015-05-12 12:33:07 -04:00
|
|
|
var dartSrcs = modulesFunnel(['**/*.dart', '**/*.ng_meta.json', '**/css/**']);
|
2015-04-13 19:22:23 -04:00
|
|
|
return mergeTrees([transpiled, dartSrcs]);
|
|
|
|
}
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-04-13 19:22:23 -04:00
|
|
|
function fixDartFolderLayout(sourceTree) {
|
2015-04-13 19:39:47 -04:00
|
|
|
// Move around files to match Dart's layout expectations.
|
2015-04-13 19:22:23 -04:00
|
|
|
return stew.rename(sourceTree, function(relativePath) {
|
2015-04-13 19:39:47 -04:00
|
|
|
// If a file matches the `pattern`, insert the given `insertion` as the second path part.
|
|
|
|
var replacements = [
|
|
|
|
{pattern: /^benchmarks\/test\//, insertion: ''},
|
|
|
|
{pattern: /^benchmarks\//, insertion: 'web'},
|
|
|
|
{pattern: /^benchmarks_external\/test\//, insertion: ''},
|
|
|
|
{pattern: /^benchmarks_external\//, insertion: 'web'},
|
2015-04-13 19:22:23 -04:00
|
|
|
{pattern: /^examples\/test\//, insertion: ''},
|
|
|
|
{pattern: /^examples\//, insertion: 'web/'},
|
2015-04-13 19:39:47 -04:00
|
|
|
{pattern: /^[^\/]*\/test\//, insertion: ''},
|
|
|
|
{pattern: /^./, insertion: 'lib'}, // catch all.
|
|
|
|
];
|
|
|
|
|
|
|
|
for (var i = 0; i < replacements.length; i++) {
|
|
|
|
var repl = replacements[i];
|
|
|
|
if (relativePath.match(repl.pattern)) {
|
|
|
|
var parts = relativePath.split('/');
|
|
|
|
parts.splice(1, 0, repl.insertion);
|
|
|
|
return path.join.apply(path, parts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new Error('Failed to match any path: ' + relativePath);
|
|
|
|
});
|
2015-04-13 19:22:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getHtmlSourcesTree() {
|
|
|
|
// Replace $SCRIPT$ markers in HTML files.
|
2015-06-08 22:01:22 -04:00
|
|
|
var htmlSrcsTree = modulesFunnel(['*/src/**/*.html']);
|
|
|
|
htmlSrcsTree = replace(
|
|
|
|
htmlSrcsTree,
|
|
|
|
{files: ['*/**'], patterns: [{match: '$SCRIPTS$', replacement: replaceScriptTagInHtml}]});
|
|
|
|
|
2015-04-13 19:22:23 -04:00
|
|
|
// Copy a url_params_to_form.js for each benchmark html file.
|
|
|
|
var urlParamsToFormTree = new MultiCopy('', {
|
|
|
|
srcPath: 'tools/build/snippets/url_params_to_form.js',
|
|
|
|
targetPatterns: ['modules/benchmarks*/src/*', 'modules/benchmarks*/src/*/*'],
|
|
|
|
});
|
|
|
|
urlParamsToFormTree = stew.rename(urlParamsToFormTree, stripModulePrefix);
|
|
|
|
return mergeTrees([htmlSrcsTree, urlParamsToFormTree]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getTemplatedPubspecsTree() {
|
|
|
|
// The JSON structure for templating pubspec.yaml files.
|
2015-04-26 04:04:28 -04:00
|
|
|
var BASE_PACKAGE_JSON = require('../../../../package.json');
|
2015-04-13 19:22:23 -04:00
|
|
|
var COMMON_PACKAGE_JSON = {
|
|
|
|
version: BASE_PACKAGE_JSON.version,
|
|
|
|
homepage: BASE_PACKAGE_JSON.homepage,
|
|
|
|
bugs: BASE_PACKAGE_JSON.bugs,
|
|
|
|
license: BASE_PACKAGE_JSON.license,
|
|
|
|
contributors: BASE_PACKAGE_JSON.contributors,
|
|
|
|
dependencies: BASE_PACKAGE_JSON.dependencies,
|
|
|
|
devDependencies: {
|
|
|
|
"yargs": BASE_PACKAGE_JSON.devDependencies['yargs'],
|
|
|
|
"gulp-sourcemaps": BASE_PACKAGE_JSON.devDependencies['gulp-sourcemaps'],
|
|
|
|
"gulp-traceur": BASE_PACKAGE_JSON.devDependencies['gulp-traceur'],
|
|
|
|
"gulp": BASE_PACKAGE_JSON.devDependencies['gulp'],
|
|
|
|
"gulp-rename": BASE_PACKAGE_JSON.devDependencies['gulp-rename'],
|
|
|
|
"through2": BASE_PACKAGE_JSON.devDependencies['through2']
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// Generate pubspec.yaml from templates.
|
2015-06-09 13:35:58 -04:00
|
|
|
var pubspecs = modulesFunnel(['**/pubspec.yaml']);
|
2015-04-13 19:22:23 -04:00
|
|
|
// Then render the templates.
|
2015-06-09 13:35:58 -04:00
|
|
|
return renderLodashTemplate(pubspecs, {context: {'packageJson': COMMON_PACKAGE_JSON}});
|
2015-04-13 19:22:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getDocsTree() {
|
|
|
|
// LICENSE files
|
|
|
|
var licenses = new MultiCopy('', {
|
|
|
|
srcPath: 'LICENSE',
|
|
|
|
targetPatterns: ['modules/*'],
|
|
|
|
exclude: ['*/rtts_assert'], // Not in dart.
|
|
|
|
});
|
|
|
|
licenses = stew.rename(licenses, stripModulePrefix);
|
|
|
|
|
|
|
|
// Documentation.
|
|
|
|
// Rename *.dart.md -> *.dart.
|
|
|
|
var mdTree = stew.rename(modulesFunnel(['**/*.dart.md']),
|
|
|
|
relativePath => relativePath.replace(/\.dart\.md$/, '.md'));
|
|
|
|
// Copy all assets, ignore .js. and .dart. (handled above).
|
2015-02-17 14:56:24 -05:00
|
|
|
var docs = modulesFunnel(['**/*.md', '**/*.png', '**/*.html', '**/*.css', '**/*.scss'],
|
2015-04-13 19:22:23 -04:00
|
|
|
['**/*.js.md', '**/*.dart.md']);
|
|
|
|
return mergeTrees([licenses, mdTree, docs]);
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:54:54 -04:00
|
|
|
module.exports = function makeDartTree(options: AngularBuilderOptions) {
|
|
|
|
var dartSources = dartfmt(getSourceTree(), {dartSDK: options.dartSDK, logs: options.logs});
|
|
|
|
var sourceTree = mergeTrees([dartSources, getHtmlSourcesTree()]);
|
2015-04-13 19:22:23 -04:00
|
|
|
sourceTree = fixDartFolderLayout(sourceTree);
|
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
var dartTree = mergeTrees([sourceTree, getTemplatedPubspecsTree(), getDocsTree()]);
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-05-28 18:54:54 -04:00
|
|
|
return destCopy(dartTree, options.outputPath);
|
2015-04-13 19:39:47 -04:00
|
|
|
};
|