2015-04-13 19:22:23 -04:00
|
|
|
/// <reference path="../../typings/node/node.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-04-13 19:22:23 -04:00
|
|
|
var glob = require('glob');
|
|
|
|
var mergeTrees = require('broccoli-merge-trees');
|
2015-04-13 19:39:47 -04:00
|
|
|
var path = require('path');
|
2015-04-13 19:22:23 -04:00
|
|
|
var renderLodashTemplate = require('broccoli-lodash');
|
2015-04-13 19:39:47 -04:00
|
|
|
var replace = require('broccoli-replace');
|
|
|
|
var stew = require('broccoli-stew');
|
|
|
|
var ts2dart = require('../broccoli-ts2dart');
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
function replaceScriptTagInHtml(content: string, relativePath: string): string {
|
|
|
|
var scriptTags = '';
|
|
|
|
if (relativePath.match(/^benchmarks/)) {
|
|
|
|
scriptTags += '<script src="url_params_to_form.js" type="text/javascript"></script>\n';
|
|
|
|
}
|
|
|
|
var scriptName = relativePath.replace(/.*\/([^/]+)\.html$/, '$1.dart');
|
|
|
|
scriptTags += '<script src="' + scriptName + '" type="application/dart"></script>\n' +
|
|
|
|
'<script src="packages/browser/dart.js" type="text/javascript"></script>';
|
|
|
|
return content.replace('$SCRIPTS$', scriptTags);
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
var tsInputTree = modulesFunnel(['**/*.js', '**/*.ts', '**/*.dart'], ['rtts_assert/**/*']);
|
|
|
|
var transpiled = ts2dart.transpile(tsInputTree);
|
|
|
|
// 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.
|
|
|
|
var htmlSrcsTree = stew.map(modulesFunnel(['*/src/**/*.html']), replaceScriptTagInHtml);
|
|
|
|
// 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.
|
|
|
|
// Lodash insists on dropping one level of extension, so first artificially rename the yaml
|
|
|
|
// files to .yaml.template.
|
|
|
|
var pubspecs = stew.rename(modulesFunnel(['**/pubspec.yaml']), '.yaml', '.yaml.template');
|
|
|
|
// Then render the templates.
|
|
|
|
return renderLodashTemplate(
|
|
|
|
pubspecs,
|
|
|
|
{files: ['**/pubspec.yaml.template'], context: {'packageJson': COMMON_PACKAGE_JSON}});
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-26 03:31:53 -04:00
|
|
|
module.exports = function makeDartTree(destinationPath) {
|
2015-04-13 19:22:23 -04:00
|
|
|
var sourceTree = mergeTrees([getSourceTree(), getHtmlSourcesTree()]);
|
|
|
|
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-04 18:38:08 -04:00
|
|
|
// TODO(iminar): tree differ seems to have issues with trees created by mergeTrees, investigate!
|
|
|
|
// ENOENT error is thrown while doing fs.readdirSync on inputRoot
|
|
|
|
// in the meantime, we just do noop mv to create a new tree
|
|
|
|
dartTree = stew.mv(dartTree, '');
|
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
return destCopy(dartTree, destinationPath);
|
2015-04-13 19:39:47 -04:00
|
|
|
};
|