|
| 1 | +// Brocfile to transpile sources from TypeScript to Dart using ts2dart. |
| 2 | +var Funnel = require('broccoli-funnel'); |
| 3 | +var stew = require('broccoli-stew'); |
| 4 | +var ts2dart = require('./dist/broccoli/broccoli-ts2dart'); |
| 5 | +var path = require('path'); |
| 6 | + |
| 7 | +// Transpile everything in 'modules'... |
| 8 | +var modulesTree = new Funnel('modules', { |
| 9 | + include: ['**/*.js', '**/*.ts', '**/*.dart'], // .dart file available means don't translate. |
| 10 | + exclude: ['rtts_assert/**/*'], // ... except for the rtts_asserts (don't apply to Dart). |
| 11 | + destDir: '/', // Remove the 'modules' prefix. |
| 12 | +}); |
| 13 | + |
| 14 | +// Transpile to dart. |
| 15 | +var dartTree = ts2dart.transpile(modulesTree); |
| 16 | + |
| 17 | +// Move around files to match Dart's layout expectations. |
| 18 | +dartTree = stew.rename(dartTree, function(relativePath) { |
| 19 | + // If a file matches the `pattern`, insert the given `insertion` as the second path part. |
| 20 | + var replacements = [ |
| 21 | + {pattern: /^benchmarks\/test\//, insertion: ''}, |
| 22 | + {pattern: /^benchmarks\//, insertion: 'web'}, |
| 23 | + {pattern: /^benchmarks_external\/test\//, insertion: ''}, |
| 24 | + {pattern: /^benchmarks_external\//, insertion: 'web'}, |
| 25 | + {pattern: /^example.?\//, insertion: 'web/'}, |
| 26 | + {pattern: /^example.?\/test\//, insertion: ''}, |
| 27 | + {pattern: /^[^\/]*\/test\//, insertion: ''}, |
| 28 | + {pattern: /^./, insertion: 'lib'}, // catch all. |
| 29 | + ]; |
| 30 | + |
| 31 | + for (var i = 0; i < replacements.length; i++) { |
| 32 | + var repl = replacements[i]; |
| 33 | + if (relativePath.match(repl.pattern)) { |
| 34 | + var parts = relativePath.split('/'); |
| 35 | + parts.splice(1, 0, repl.insertion); |
| 36 | + return path.join.apply(path, parts); |
| 37 | + } |
| 38 | + } |
| 39 | + throw new Error('Failed to match any path', relativePath); |
| 40 | +}); |
| 41 | + |
| 42 | +// Move the tree under the 'dart' folder. |
| 43 | +module.exports = stew.mv(dartTree, 'dart'); |
0 commit comments