forked from glimmerjs/glimmer-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathember-cli-build.js
79 lines (67 loc) · 2.72 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
const merge = require('broccoli-merge-trees');
const funnel = require('broccoli-funnel');
const typescript = require('broccoli-typescript-compiler').default;
const buildTests = require('./build/broccoli/build-tests');
const buildPackages = require('./build/broccoli/build-packages.js');
const mergeDefinitionFiles = require('./build/broccoli/merge-definition-files');
const stripGlimmerUtilities = require('./build/broccoli/strip-glimmer-utilities');
const writeSmokeTest = require('./build/broccoli/write-smoke-test');
const PRODUCTION = process.env.EMBER_ENV === 'production';
/**
* For development, we build for ES5 AMD (browser tests) and CommonJS (Node
* tests). For production builds, we omit tests but include all target
* formats.
*/
module.exports = function() {
// First, get all of our TypeScript packages while preserving their relative
// path in the filesystem. This is important because tsconfig.json paths are
// relative to the project root and we want to use the tsconfig as-is.
let tsTree = funnel('packages/@glimmer', {
destDir: 'packages/@glimmer',
});
// Second, compile all of the TypeScript into ES2017 JavaScript. Because the
// TypeScript compiler understands the project as a whole, it's faster to do
// this once and use the transpiled JavaScript as the input to any further
// transformations.
let jsTree = typescript(tsTree);
// The TypeScript compiler doesn't emit `.d.ts` files, so we need to manually
// merge them back into our JavaScript output.
jsTree = mergeDefinitionFiles(jsTree);
// Glimmer includes a number of assertions and logging information that can be
// stripped from production builds for better runtime performance.
if (PRODUCTION) {
if (!process.env.RETAIN_FLAGS) {
jsTree = funnel(jsTree, {
exclude: ['**/**/-debug-strip.js'],
});
}
jsTree = stripGlimmerUtilities(jsTree);
}
let matrix;
if (PRODUCTION) {
matrix = [
['amd', 'es5'],
['commonjs', 'es2017'],
['commonjs', 'es5'],
['modules', 'es2017'],
['modules', 'es5'],
['types'],
];
} else {
matrix = [['amd', 'es5'], ['commonjs', 'es5'], ['modules', 'es2017'], ['types']];
}
// Third, build our module/ES combinations for each package.
let packagesTree = buildPackages(jsTree, matrix);
let output;
// Unless we're in production, bundle the tests and test harness. We'll also
// grab the AMD build of Glimmer and concatenate it into a single
// glimmer-vm.js file.
if (PRODUCTION) {
let smokeTestTree = writeSmokeTest(packagesTree);
output = [packagesTree, smokeTestTree];
} else {
let testsTree = buildTests(tsTree, jsTree, packagesTree);
output = [packagesTree, testsTree];
}
return merge(output);
};