From 3dd0ac1f0a5ddc0904e42478ff07fde027e46bf4 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 13 Apr 2015 10:17:51 -0700 Subject: [PATCH] chore(build): move dart broccoli tree to make-broccoli-tree --- Brocfile-dart.js | 43 --------------------------- gulpfile.js | 2 +- tools/broccoli/make-broccoli-tree.js | 44 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 44 deletions(-) delete mode 100644 Brocfile-dart.js diff --git a/Brocfile-dart.js b/Brocfile-dart.js deleted file mode 100644 index f2f220b5aa..0000000000 --- a/Brocfile-dart.js +++ /dev/null @@ -1,43 +0,0 @@ -// Brocfile to transpile sources from TypeScript to Dart using ts2dart. -var Funnel = require('broccoli-funnel'); -var stew = require('broccoli-stew'); -var ts2dart = require('./dist/broccoli/broccoli-ts2dart'); -var path = require('path'); - -// Transpile everything in 'modules'... -var modulesTree = new Funnel('modules', { - include: ['**/*.js', '**/*.ts', '**/*.dart'], // .dart file available means don't translate. - exclude: ['rtts_assert/**/*'], // ... except for the rtts_asserts (don't apply to Dart). - destDir: '/', // Remove the 'modules' prefix. -}); - -// Transpile to dart. -var dartTree = ts2dart.transpile(modulesTree); - -// Move around files to match Dart's layout expectations. -dartTree = stew.rename(dartTree, function(relativePath) { - // 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'}, - {pattern: /^example.?\//, insertion: 'web/'}, - {pattern: /^example.?\/test\//, insertion: ''}, - {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); -}); - -// Move the tree under the 'dart' folder. -module.exports = stew.mv(dartTree, 'dart'); diff --git a/gulpfile.js b/gulpfile.js index 432eff5c15..69e62b7bdb 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -374,7 +374,7 @@ gulp.task('build/transformCJSTests', function() { }); gulp.task('build/transpile.dart', ['build.broccoli.tools'], function() { - return broccoliBuild(require('./Brocfile-dart.js'), 'dart'); + return broccoliBuild(makeBroccoliTree('dart'), 'dart'); }); // ------------ diff --git a/tools/broccoli/make-broccoli-tree.js b/tools/broccoli/make-broccoli-tree.js index 48e151606e..f2e79c81fd 100644 --- a/tools/broccoli/make-broccoli-tree.js +++ b/tools/broccoli/make-broccoli-tree.js @@ -8,6 +8,7 @@ var path = require('path'); var renderLodashTemplate = require('broccoli-lodash'); var replace = require('broccoli-replace'); var stew = require('broccoli-stew'); +var ts2dart; var TraceurCompiler; var TypescriptCompiler; @@ -17,11 +18,13 @@ var projectRootDir = path.normalize(path.join(__dirname, '..', '..')); module.exports = function makeBroccoliTree(name) { if (!TraceurCompiler) TraceurCompiler = require('../../dist/broccoli/traceur'); if (!TypescriptCompiler) TypescriptCompiler = require('../../dist/broccoli/typescript'); + if (!ts2dart) ts2dart = require('../../dist/broccoli/broccoli-ts2dart'); switch (name) { case 'dev': return makeBrowserTree({name: name, typeAssertions: true}); case 'prod': return makeBrowserTree({name: name, typeAssertions: false}); case 'cjs': return makeCjsTree(); + case 'dart': return makeDartTree(); default: throw new Error('Unknown build type: ' + name); } }; @@ -219,3 +222,44 @@ function makeCjsTree() { return stew.mv(cjsTree, 'js/cjs'); } + + +function makeDartTree() { + // Transpile everything in 'modules'... + var modulesTree = new Funnel('modules', { + include: ['**/*.js', '**/*.ts', '**/*.dart'], // .dart file available means don't translate. + exclude: ['rtts_assert/**/*'], // ... except for the rtts_asserts (don't apply to Dart). + destDir: '/' // Remove the 'modules' prefix. + }); + + // Transpile to dart. + var dartTree = ts2dart.transpile(modulesTree); + + // Move around files to match Dart's layout expectations. + dartTree = stew.rename(dartTree, function(relativePath) { + // 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'}, + {pattern: /^example.?\//, insertion: 'web/'}, + {pattern: /^example.?\/test\//, insertion: ''}, + {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); + }); + + // Move the tree under the 'dart' folder. + return stew.mv(dartTree, 'dart'); +}