forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Brocfile-js_cjs.js
74 lines (65 loc) · 2.97 KB
/
Brocfile-js_cjs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var stew = require('broccoli-stew');
var TraceurCompiler = require('./dist/broccoli/traceur');
var TypescriptCompiler = require('./dist/broccoli/typescript');
var renderLodashTemplate = require('broccoli-lodash');
var modulesTree = new Funnel(
'modules', {include: ['**/**'], exclude: ['angular2/src/core/zone/vm_turn_zone.es6']});
// Use Traceur to transpile original sources to ES5
var traceurOpts = {
sourceMaps: true,
annotations: true, // parse annotations
types: true, // parse types
script: false, // parse as a module
memberVariables: true, // parse class fields
typeAssertionModule: 'rtts_assert/rtts_assert',
// Don't use type assertions since this is partly transpiled by typescript
typeAssertions: false,
modules: 'commonjs'
};
var cjsTree = new TraceurCompiler(modulesTree, '.js', '.map', traceurOpts);
// Add the LICENSE file in each module
['angular2', 'benchmarks', 'benchmarks_external', 'benchpress', 'examples', 'rtts_assert'].forEach(
function(destDir) {
cjsTree = mergeTrees([cjsTree, new Funnel('.', {files: ['LICENSE'], destDir: destDir})]);
});
extras = new Funnel(modulesTree, {include: ['**/*.md', '**/*.png'], exclude: ['**/*.dart.md']});
extras = stew.rename(extras, 'README.js.md', 'README.md');
var BASE_PACKAGE_JSON = require('./package.json');
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']
}
};
// Add a .template extension since renderLodashTemplate strips one extension
var packageJsons =
stew.rename(new Funnel(modulesTree, {include: ['**/package.json']}), '.json', '.json.template');
packageJsons = renderLodashTemplate(
packageJsons, {files: ["**/**"], context: {'packageJson': COMMON_PACKAGE_JSON}});
var typescriptTree = new TypescriptCompiler(modulesTree, {
target: 'ES5',
sourceMap: true,
mapRoot: '', /* force sourcemaps to use relative path */
module: /*system.js*/'commonjs',
allowNonTsExtensions: false,
typescript: require('typescript'),
//declarationFiles: true,
noEmitOnError: true,
outDir: 'angular2'
});
// For now, we just overwrite the Traceur-compiled files with their Typescript equivalent
cjsTree = mergeTrees([cjsTree, typescriptTree], { overwrite: true });
cjsTree = mergeTrees([cjsTree, extras, packageJsons]);
module.exports = stew.mv(cjsTree, 'js/cjs');