forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathember-cli-build.js
423 lines (378 loc) · 11.3 KB
/
ember-cli-build.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
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
'use strict';
const MergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
const babelHelpers = require('./broccoli/babel-helpers');
const bootstrapModule = require('./broccoli/bootstrap-modules');
const concatBundle = require('./broccoli/concat-bundle');
const concat = require('broccoli-concat');
const testIndexHTML = require('./broccoli/test-index-html');
const toES5 = require('./broccoli/to-es5');
const toNamedAMD = require('./broccoli/to-named-amd');
const stripForProd = toES5.stripForProd;
const minify = require('./broccoli/minify');
const rename = require('./broccoli/rename');
const { stripIndent } = require('common-tags');
const {
routerES,
jquery,
internalLoader,
qunit,
rollupEmberGlimmerES,
handlebarsES,
rsvpES,
simpleHTMLTokenizerES,
backburnerES,
dagES,
routeRecognizerES,
emberPkgES,
emberTypescriptPkgES,
glimmerTrees,
emberTestsES: emberPkgTestsES,
nodeModuleUtils,
emberVersionES,
emberLicense,
emberFeaturesES,
nodeTests,
rollupEmberMetal,
buildEmberEnvFlagsES,
} = require('./broccoli/packages');
const SHOULD_ROLLUP = true;
const ENV = process.env.EMBER_ENV || 'development';
module.exports = function() {
let loader = internalLoader();
let license = emberLicense();
let nodeModule = nodeModuleUtils();
let emberGlimmerES = emberTypescriptPkgES('ember-glimmer');
// generate "loose" ES<latest> modules...
let combinedES = new MergeTrees([
emberVersionES(),
emberFeaturesES(),
backburnerES(),
handlebarsES(),
simpleHTMLTokenizerES(),
rsvpES(),
emberPkgES('container'),
emberPkgES('ember-application'),
emberPkgES('ember-console'),
emberPkgES('ember-debug'),
emberPkgES('ember-environment'),
emberPkgES('ember-extension-support'),
emberGlimmerES,
emberPkgES('ember-metal'),
emberPkgES('ember-routing'),
emberPkgES('ember-runtime'),
emberPkgES('ember-template-compiler'),
emberPkgES('ember-testing'),
emberPkgES('ember-utils'),
emberPkgES('ember-views'),
emberPkgES('ember'),
...dependenciesES({ includeGlimmerCompiler: true }),
]);
let es = new Funnel(combinedES, {
destDir: 'es',
});
let esMin = minify(
new Funnel(combinedES, {
destDir: 'es-min',
})
);
let emberTestsES = buildEmberTestsES();
let pkgAndTestES = new MergeTrees([combinedES, ...emberTestsES], {
overwrite: true,
});
let pkgAndTestESInAMD = toNamedAMD(pkgAndTestES);
let emberEnvFlagsDebug = toNamedAMD(buildEmberEnvFlagsES({ DEBUG: true }));
let pkgAndTestESBundleDebug = concat(
new MergeTrees([pkgAndTestESInAMD, loader, nodeModule, emberEnvFlagsDebug]),
{
headerFiles: ['loader.js'],
inputFiles: ['**/*.js'],
outputFile: 'ember-all.debug.js',
}
);
let debugFeatures = toES5(emberFeaturesES());
let version = toES5(emberVersionES());
let emberTesting = emberPkgES('ember-testing');
let emberTestingES5 = toES5(emberTesting, { annotation: 'ember-testing' });
let emberDebug = emberPkgES('ember-debug');
let emberDebugES5 = toES5(emberDebug, { annotation: 'ember-debug' });
let emberTemplateCompiler = emberPkgES('ember-template-compiler');
let emberTemplateCompilerES5 = toES5(emberTemplateCompiler, {
annotation: 'ember-template-compiler',
});
let babelDebugHelpersES5 = toES5(babelHelpers('debug'), {
annotation: 'babel helpers debug',
});
let inlineParser = toES5(handlebarsES(), { annotation: 'handlebars' });
let tokenizer = toES5(simpleHTMLTokenizerES(), { annotation: 'tokenizer' });
let rsvp = toES5(rsvpES(), { annotation: 'rsvp' });
let emberMetal = new Funnel('packages/ember-metal/lib', {
destDir: '/',
include: ['**/*.js'],
});
let emberMetalES5 = rollupEmberMetal(emberMetal);
let emberConsole = emberPkgES('ember-console', SHOULD_ROLLUP, ['ember-environment']);
let emberConsoleES5 = toES5(emberConsole, { annotation: 'ember-console' });
let emberEnvironment = emberPkgES('ember-environment', SHOULD_ROLLUP);
let emberEnvironmentES5 = toES5(emberEnvironment, {
annotation: 'ember-environment',
});
let emberUtils = emberPkgES('ember-utils', SHOULD_ROLLUP);
let emberUtilsES5 = toES5(emberUtils, { annotation: 'ember-utils' });
let container = emberPkgES('container', SHOULD_ROLLUP, [
'ember-debug',
'ember-utils',
'ember-environment',
'ember-env-flags',
'ember/features',
]);
let containerES5 = toES5(container, { annotation: 'container' });
let emberCoreES = emberES().concat(rollupEmberGlimmerES(emberGlimmerES));
let testHarness = testHarnessFiles();
let backburner = toES5(backburnerES());
// ES5
let dependenciesES5 = dependenciesES().map(toES5);
let emberES5 = emberCoreES.map(toES5);
let emberTestsES5 = emberTestsES.map(toES5);
// Bundling
let emberTestsBundle = new MergeTrees([
...emberTestsES5,
loader,
nodeModule,
license,
babelDebugHelpersES5,
]);
let emberDebugBase = [
...emberES5,
...dependenciesES5,
rsvp,
containerES5,
emberUtilsES5,
emberEnvironmentES5,
emberMetalES5,
emberConsoleES5,
emberDebugES5,
backburner,
version,
license,
loader,
nodeModule,
bootstrapModule('ember'),
];
emberTestsBundle = concatBundle(emberTestsBundle, {
outputFile: 'ember-tests.js',
hasBootstrap: false,
});
let emberDebugBundle = new MergeTrees([
...emberDebugBase,
emberTestingES5,
babelDebugHelpersES5,
inlineParser,
debugFeatures,
]);
emberDebugBundle = concatBundle(emberDebugBundle, {
outputFile: 'ember.debug.js',
});
let emberTestingBundle = new MergeTrees([
loader,
license,
emberTestingES5,
emberDebugES5,
babelDebugHelpersES5,
nodeModule,
]);
emberTestingBundle = concatBundle(emberTestingBundle, {
outputFile: 'ember-testing.js',
hasBootstrap: false,
footer: stripIndent`
var testing = requireModule('ember-testing');
Ember.Test = testing.Test;
Ember.Test.Adapter = testing.Adapter;
Ember.Test.QUnitAdapter = testing.QUnitAdapter;
Ember.setupForTesting = testing.setupForTesting;
`,
});
function templateCompiler(babelHelpers) {
return [
containerES5,
emberUtilsES5,
emberEnvironmentES5,
emberConsoleES5,
emberTemplateCompilerES5,
emberDebugES5,
// metal depends on @glimmer/reference
...glimmerTrees(['@glimmer/compiler', '@glimmer/reference']).map(toES5),
debugFeatures,
tokenizer,
inlineParser,
babelHelpers,
bootstrapModule('ember-template-compiler', 'umd'),
];
}
let trees = [];
if (ENV === 'production') {
let babelProdHelpersES5 = toES5(babelHelpers('prod'), {
environment: 'production',
});
let productionFeatures = toES5(emberFeaturesES(true), {
environment: 'production',
});
let emberMetalProd = stripForProd(rollupEmberMetal(emberMetal, { environment: 'production' }));
let emberProdES5 = [
...emberCoreES,
...dependenciesES(),
container,
emberUtils,
emberEnvironment,
emberConsole,
emberDebug,
].map(tree => {
return stripForProd(toES5(tree, { environment: 'production' }));
});
let depsProd = [backburner, rsvp].map(stripForProd);
let emberProdTestES5 = emberTestsES.map(tree => {
return stripForProd(toES5(tree, { environment: 'production' }));
});
let emberRuntimeBundle = new MergeTrees([
loader,
babelDebugHelpersES5,
emberMetalES5,
emberEnvironmentES5,
emberConsoleES5,
containerES5,
rsvp,
license,
bootstrapModule('ember-runtime', 'default'),
]);
let emberProdBundle = new MergeTrees([
...emberProdES5,
...depsProd,
emberMetalProd,
productionFeatures,
babelProdHelpersES5,
version,
license,
loader,
nodeModule,
bootstrapModule('ember'),
]);
// Note:
// We have to build custom production template compiler
// because we strip babel helpers in the prod build
let prodTemplateCompiler = new MergeTrees(templateCompiler(babelProdHelpersES5));
prodTemplateCompiler = stripForProd(prodTemplateCompiler);
prodTemplateCompiler = new MergeTrees([
nodeModule,
prodTemplateCompiler,
version,
license,
loader,
]);
prodTemplateCompiler = concatBundle(prodTemplateCompiler, {
outputFile: 'ember-template-compiler.js',
});
let emberProdTestsBundle = new MergeTrees([
...emberProdTestES5,
tokenizer,
babelProdHelpersES5,
license,
loader,
nodeModule,
]);
emberRuntimeBundle = concatBundle(emberRuntimeBundle, {
outputFile: 'ember-runtime.js',
});
emberProdBundle = concatBundle(emberProdBundle, {
outputFile: 'ember.prod.js',
});
emberProdTestsBundle = concatBundle(emberProdTestsBundle, {
outputFile: 'ember-tests.prod.js',
hasBootstrap: false,
});
let emberProdMinRename = rename(emberProdBundle, {
'ember.prod.js': 'ember.min.js',
});
let emberMinBundle = minify(emberProdMinRename);
trees.push(
emberRuntimeBundle,
emberProdBundle,
emberMinBundle,
emberProdTestsBundle,
prodTemplateCompiler
);
if (process.env.INCLUDE_ES_MIN) {
trees.push(esMin);
}
} else {
let emberTemplateCompilerBundle = new MergeTrees([
...templateCompiler(babelDebugHelpersES5),
version,
license,
loader,
nodeModule,
]);
emberTemplateCompilerBundle = concatBundle(emberTemplateCompilerBundle, {
outputFile: 'ember-template-compiler.js',
});
trees.push(emberTemplateCompilerBundle);
}
return new MergeTrees([
es,
pkgAndTestESBundleDebug,
...trees,
...testHarness,
emberTestsBundle,
emberDebugBundle,
emberTestingBundle,
nodeTests(),
]);
};
function dependenciesES(options = {}) {
let glimmerEntries = ['@glimmer/node', '@glimmer/opcode-compiler', '@glimmer/runtime'];
if (options.includeGlimmerCompiler) {
glimmerEntries.push('@glimmer/compiler');
}
if (ENV === 'development') {
let hasGlimmerDebug = true;
try {
require('@glimmer/debug'); // eslint-disable-line node/no-missing-require
} catch (e) {
hasGlimmerDebug = false;
}
if (hasGlimmerDebug) {
glimmerEntries.push('@glimmer/debug', '@glimmer/local-debug-flags');
}
}
return [dagES(), routerES(), routeRecognizerES(), ...glimmerTrees(glimmerEntries)];
}
function buildEmberTestsES() {
return [
emberPkgES('internal-test-helpers'),
emberPkgTestsES('container'),
emberPkgTestsES('ember'),
emberPkgTestsES('ember-metal'),
emberPkgTestsES('ember-template-compiler'),
emberPkgTestsES('ember-glimmer'),
emberPkgTestsES('ember-application'),
emberPkgTestsES('ember-debug'),
emberPkgTestsES('ember-runtime'),
emberPkgTestsES('ember-extension-support'),
emberPkgTestsES('ember-routing'),
emberPkgTestsES('ember-utils'),
emberPkgTestsES('ember-testing'),
emberPkgTestsES('internal-test-helpers'),
];
}
function emberES() {
return [
emberPkgES('ember-views'),
emberPkgES('ember'),
emberPkgES('ember-application'),
emberPkgES('ember-runtime'),
emberPkgES('ember-extension-support'),
emberPkgES('ember-routing'),
];
}
function testHarnessFiles() {
return [testIndexHTML(), jquery(), qunit()];
}