forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser_tree.ts
More file actions
329 lines (285 loc) · 10.4 KB
/
browser_tree.ts
File metadata and controls
329 lines (285 loc) · 10.4 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
'use strict';
var Funnel = require('broccoli-funnel');
var htmlReplace = require('../html-replace');
var jsReplace = require('../js-replace');
var path = require('path');
var stew = require('broccoli-stew');
import compileWithTypescript from '../broccoli-typescript';
import destCopy from '../broccoli-dest-copy';
import flatten from '../broccoli-flatten';
import mergeTrees from '../broccoli-merge-trees';
import replace from '../broccoli-replace';
import checkImports from '../broccoli-check-imports';
const kServedPaths = [
// Relative (to /modules) paths to benchmark directories
'benchmarks/src',
'benchmarks/src/change_detection',
'benchmarks/src/compiler',
'benchmarks/src/costs',
'benchmarks/src/di',
'benchmarks/src/element_injector',
'benchmarks/src/largetable',
'benchmarks/src/naive_infinite_scroll',
'benchmarks/src/tree',
'benchmarks/src/static_tree',
// Relative (to /modules) paths to external benchmark directories
'benchmarks_external/src',
'benchmarks_external/src/compiler',
'benchmarks_external/src/largetable',
'benchmarks_external/src/naive_infinite_scroll',
'benchmarks_external/src/tree',
'benchmarks_external/src/tree/react',
'benchmarks_external/src/static_tree',
// Relative (to /modules) paths to example directories
'playground/src/animate',
'playground/src/benchpress',
'playground/src/model_driven_forms',
'playground/src/template_driven_forms',
'playground/src/person_management',
'playground/src/order_management',
'playground/src/gestures',
'playground/src/hash_routing',
'playground/src/hello_world',
'playground/src/http',
'playground/src/jsonp',
'playground/src/key_events',
'playground/src/relative_assets',
'playground/src/routing',
'playground/src/sourcemap',
'playground/src/svg',
'playground/src/todo',
'playground/src/upgrade',
'playground/src/zippy_component',
'playground/src/async',
'playground/src/web_workers/kitchen_sink',
'playground/src/web_workers/todo',
'playground/src/web_workers/images',
'playground/src/web_workers/message_broker',
'playground/src/web_workers/router',
'playground/src/web_workers/input'
];
module.exports = function makeBrowserTree(options, destinationPath) {
const modules = options.projects;
const noTypeChecks = options.noTypeChecks;
const generateEs6 = options.generateEs6;
const sourceMaps = options.sourceMaps;
const useBundles = options.useBundles;
if (modules.angular2) {
var angular2Tree = new Funnel('modules/angular2', {
include: ['**/**'],
exclude: [
// Exclude ES6 polyfill typings when tsc target=ES6
'typings/es6-*/**',
],
destDir: '/angular2/'
});
}
if (modules.benchmarks) {
var benchmarksTree =
new Funnel('modules/benchmarks',
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchmarks/'});
}
if (modules.benchmarks_external) {
var benchmarksExternalTree = new Funnel(
'modules/benchmarks_external',
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchmarks_external/'});
}
if (modules.payload_tests) {
var payloadTestsTree =
new Funnel('modules/payload_tests',
{include: ['**/ts/**'], exclude: ['e2e_test/**'], destDir: '/payload_tests/'});
}
if (modules.playground) {
var playgroundTree =
new Funnel('modules/playground',
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/playground/'});
}
if (modules.benchpress) {
var benchpressTree =
new Funnel('modules/benchpress',
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchpress/'});
}
let externalTypings =
new Funnel('node_modules', {include: ['rxjs/**/*.d.ts', 'zone.js/**/*.d.ts']});
var modulesTree = mergeTrees([
angular2Tree,
benchmarksTree,
benchmarksExternalTree,
payloadTestsTree,
playgroundTree,
benchpressTree,
externalTypings,
]);
var es6PolyfillTypings =
new Funnel('modules', {include: ['angular2/typings/es6-*/**'], destDir: '/'});
var es5ModulesTree = mergeTrees([modulesTree, es6PolyfillTypings]);
var scriptPathPatternReplacement = {
match: '@@PATH',
replacement: function(replacement, relativePath) {
var parts = relativePath.replace(/\\/g, '/').split('/');
return parts.splice(0, parts.length - 1).join('/');
}
};
var scriptFilePatternReplacement = {
match: '@@FILENAME',
replacement: function(replacement, relativePath) {
var parts = relativePath.replace(/\\/g, '/').split('/');
return parts[parts.length - 1].replace('html', 'js');
}
};
var useBundlesPatternReplacement = {
match: '@@USE_BUNDLES',
replacement: function(replacement, relativePath) { return useBundles; }
};
// Check that imports do not break barrel boundaries
modulesTree = checkImports(modulesTree);
modulesTree = replace(modulesTree, {
files: ["playground*/**/*.js"],
patterns: [{match: /\$SCRIPTS\$/, replacement: jsReplace('SCRIPTS')}]
});
let ambientTypings = [
'angular2/typings/hammerjs/hammerjs.d.ts',
'angular2/typings/node/node.d.ts',
'node_modules/zone.js/dist/zone.js.d.ts',
'angular2/manual_typings/globals.d.ts',
'angular2/typings/es6-collections/es6-collections.d.ts',
'angular2/typings/es6-promise/es6-promise.d.ts'
];
// Use TypeScript to transpile the *.ts files to ES5
var es5Tree = compileWithTypescript(es5ModulesTree, {
declaration: false,
emitDecoratorMetadata: true,
experimentalDecorators: true,
module: 'commonjs',
moduleResolution: 'classic',
noEmitOnError: !noTypeChecks,
rootDir: './',
rootFilePaths: ambientTypings,
inlineSourceMap: sourceMaps,
inlineSources: sourceMaps,
target: 'es5'
});
var vendorScriptsTree = flatten(new Funnel('.', {
files: [
'node_modules/es6-shim/es6-shim.js',
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/base64-js/lib/b64.js',
'node_modules/reflect-metadata/Reflect.js'
]
}));
var vendorScripts_benchmark =
new Funnel('tools/build/snippets', {files: ['url_params_to_form.js'], destDir: '/'});
var vendorScripts_benchmarks_external =
new Funnel('node_modules/angular', {files: ['angular.js'], destDir: '/'});
// Get scripts for each benchmark or example
let servingTrees = kServedPaths.reduce(getServedFunnels, []);
function getServedFunnels(funnels, destDir) {
let options = {srcDir: '/', destDir: destDir};
funnels.push(new Funnel(vendorScriptsTree, options));
if (destDir.indexOf('benchmarks') > -1) {
funnels.push(new Funnel(vendorScripts_benchmark, options));
}
if (destDir.indexOf('benchmarks_external') > -1) {
funnels.push(new Funnel(vendorScripts_benchmarks_external, options));
}
return funnels;
}
if (modules.benchmarks || modules.benchmarks_external || modules.playground) {
var assetsTree = new Funnel(
modulesTree, {include: ['**/*'], exclude: ['**/*.{html,ts,dart}'], destDir: '/'});
}
var htmlTree = new Funnel(modulesTree, {
include: ['*/src/**/*.html', '**/playground/**/*.html', '**/payload_tests/**/ts/**/*.html'],
destDir: '/'
});
if (modules.playground) {
htmlTree = replace(htmlTree, {
files: ['playground*/**/*.html'],
patterns: [
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')},
scriptPathPatternReplacement,
scriptFilePatternReplacement,
useBundlesPatternReplacement
]
});
}
if (modules.benchmarks) {
htmlTree = replace(htmlTree, {
files: ['benchmarks/**'],
patterns: [
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks')},
scriptPathPatternReplacement,
scriptFilePatternReplacement,
useBundlesPatternReplacement
]
});
}
if (modules.benchmarks_external) {
htmlTree = replace(htmlTree, {
files: ['benchmarks_external/**'],
patterns: [
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks_external')},
scriptPathPatternReplacement,
scriptFilePatternReplacement,
useBundlesPatternReplacement
]
});
}
if (modules.playground) {
// We need to replace the regular angular bundle with the web-worker bundle
// for web-worker e2e tests.
htmlTree = replace(htmlTree, {
files: ['playground*/**/web_workers/**/*.html'],
patterns: [{match: "/bundle/angular2.dev.js", replacement: "/bundle/web_worker/ui.dev.js"}]
});
}
if (modules.benchmarks || modules.benchmarks_external) {
var scripts = mergeTrees(servingTrees);
}
if (modules.benchmarks_external) {
var polymerFiles = new Funnel('.', {
files: [
'bower_components/polymer/polymer.html',
'bower_components/polymer/polymer-micro.html',
'bower_components/polymer/polymer-mini.html',
'tools/build/snippets/url_params_to_form.js'
]
});
var polymer = stew.mv(flatten(polymerFiles), 'benchmarks_external/src/tree/polymer');
var reactFiles = new Funnel('.', {files: ['node_modules/react/dist/react.min.js']});
var react = stew.mv(flatten(reactFiles), 'benchmarks_external/src/tree/react');
}
if (modules.benchmarks || modules.benchmarks_external || modules.playground) {
htmlTree = mergeTrees([htmlTree, scripts, polymer, react]);
}
// this is needed only for creating a bundle
// typescript resolves dependencies automatically
if (modules.bundle_deps) {
var nodeModules = new Funnel(
'node_modules', {include: ['rxjs/**/**', 'parse5/**/**', 'css/**/**'], destDir: '/'});
}
if (generateEs6) {
// Use TypeScript to transpile the *.ts files to ES6
var es6Tree = compileWithTypescript(modulesTree, {
declaration: false,
emitDecoratorMetadata: true,
experimentalDecorators: true,
noEmitOnError: false,
rootDir: './',
rootFilePaths: [
'angular2/typings/zone.js/zone.js.d.ts',
'angular2/typings/hammerjs/hammerjs.d.ts',
'angular2/typings/node/node.d.ts',
],
inlineSourceMap: sourceMaps,
inlineSources: sourceMaps,
target: 'es6'
});
es6Tree = stew.mv(mergeTrees([es6Tree, htmlTree, assetsTree, nodeModules]), '/es6');
}
es5Tree = stew.mv(mergeTrees([es5Tree, htmlTree, assetsTree, nodeModules]), '/es5');
var mergedTree = mergeTrees([es6Tree, es5Tree]);
return destCopy(mergedTree, destinationPath);
};