forked from glimmerjs/glimmer-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-cli-build.js
312 lines (264 loc) · 7.79 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
/*jshint node:true*/
var path = require('path');
var existsSync = require('exists-sync');
var concat = require('broccoli-concat');
var merge = require('broccoli-merge-trees');
var typescript = require('broccoli-typescript-compiler');
var transpileES6 = require('emberjs-build/lib/utils/transpile-es6');
var handlebarsInlinedTrees = require('./build-support/handlebars-inliner');
var stew = require('broccoli-stew');
var TSLint = require('broccoli-tslinter');
var mv = stew.mv;
var find = stew.find;
var rename = stew.rename;
function transpile(tree, options, label) {
return transpileES6(tree, label, options);
}
function buildTSOptions(compilerOptions) {
var tsOptions = {
tsconfig: {
compilerOptions: {
target: "es2015",
inlineSourceMap: true,
inlineSources: true,
moduleResolution: "node",
/* needed to get typescript to emit the desired sourcemaps */
rootDir: '.',
mapRoot: '/'
}
}
};
Object.assign(tsOptions.tsconfig.compilerOptions, compilerOptions);
return tsOptions;
}
function buildBabelOptions(options) {
var externalHelpers = options.shouldExternalizeHelpers || false;
var stripRuntimeChecks = options.stripRuntimeChecks || false;
return {
externalHelpers: externalHelpers,
stripRuntimeChecks: stripRuntimeChecks,
sourceMaps: 'inline'
};
}
module.exports = function(_options) {
var options = _options || {};
var packages = __dirname + '/packages';
var tslintConfig = __dirname + '/tslint.json';
var bower = __dirname + '/bower_components';
var hasBower = existsSync(bower);
var babelOptions = buildBabelOptions(options);
var tsOptions = buildTSOptions();
var benchmarkTrees = [find(__dirname + '/bench', {
include: ['*.html'],
destDir: 'bench'
})];
var benchmarkPath = __dirname + '/node_modules/benchmark';
if (existsSync(benchmarkPath)) {
benchmarkTrees.push(find(benchmarkPath, {
include: ['benchmark.js'],
destDir: 'bench'
}));
}
var demos = find(__dirname + '/demos', {
include: ['*.html'],
destDir: 'demos'
});
var simpleDOMPath = path.dirname(require.resolve('simple-dom'));
var simpleDOM = find(simpleDOMPath, {
include: ['simple-dom.js']
});
/*
* ES6 Build
*/
var tokenizerPath = path.join(require.resolve('simple-html-tokenizer'), '..', '..', 'src');
// TODO: WAT, why does { } change the output so much....
var tokenizerTree = find(tokenizerPath, { });
var HTMLTokenizer = mv(tokenizerTree, "simple-html-tokenizer");
var tsTree = find(packages, {
include: ['**/*.ts'],
exclude: [
'**/*.d.ts',
'*/node_modules/**',
'@glimmer/*/node_modules/**'
]
});
var tsLintTree = new TSLint(tsTree, {
configuration: tslintConfig
});
/* tslint:enable:no-unused-variable */
var transpiledTSLintTree = typescript(tsLintTree, tsOptions);
var jsTree = typescript(tsTree, tsOptions);
var libTree = find(jsTree, {
include: ['*/index.js', '@glimmer/*/index.js', '@glimmer/*/lib/**/*.js']
});
libTree = merge([libTree, HTMLTokenizer, handlebarsInlinedTrees.compiler]);
var es6LibTree = mv(libTree, 'es6');
/*
* ES5 Named AMD Build
*/
libTree = transpile(libTree, babelOptions, 'ES5 Lib Tree');
var es5LibTree = mv(libTree, 'named-amd');
/*
* CommonJS Build
*/
tsOptions = buildTSOptions({
module: "commonjs",
target: "es5"
});
var cjsTree = typescript(tsTree, tsOptions);
// SimpleHTMLTokenizer ships as either ES6 or a single AMD-ish file, so we have to
// compile it from ES6 modules to CJS using TypeScript. broccoli-typescript-compiler
// only works with `.ts` files, so we rename the `.js` files to `.ts` first.
var simpleHTMLTokenizerLib = rename(tokenizerPath, '.js', '.ts');
var simpleHTMLTokenizerJSTree = typescript(simpleHTMLTokenizerLib, tsOptions);
var handlebarsPath = path.join(require.resolve('handlebars'), '..', '..', 'dist', 'cjs');
cjsTree = merge([cjsTree, simpleHTMLTokenizerJSTree, handlebarsPath, simpleDOM]);
// Glimmer packages require other Glimmer packages using non-relative module names
// (e.g., `glimmer-compiler` may import `glimmer-util` instead of `../glimmer-util`),
// which doesn't work with Node's module resolution strategy.
// As a workaround, naming the CommonJS directory `node_modules` allows us to treat each
// package inside as a top-level module.
cjsTree = mv(cjsTree, 'node_modules');
/*
* Anonymous AMD Build
*/
var glimmerCommon = find(libTree, {
include: [
'glimmer/**/*.js',
'@glimmer/object/**/*.js',
'@glimmer/object-model/**/*.js',
'@glimmer/object-reference/**/*.js',
'@glimmer/reference/**/*.js',
'@glimmer/util/**/*.js',
'@glimmer/wire-format/**/*.js'
]
});
var glimmerRuntime = find(libTree, {
include: ['@glimmer/runtime/**/*', '@glimmer/public-runtime/**/*']
});
var glimmerCompiler = merge([
find(libTree, {
include: [
'@glimmer/syntax/**/*.js',
'@glimmer/compiler/**/*.js',
'simple-html-tokenizer/**/*.js',
'handlebars.js',
'handlebars/**/*.js'
]
})
]);
var glimmerDemos = merge([
find(libTree, {
include: [
'@glimmer/test-helpers/**/*.js',
'glimmer-demos/**/*.js',
]
})
]);
var glimmerBenchmarks = merge([
find(libTree, {
include: [
'@glimmer/test-helpers/**/*.js',
'glimmer-benchmarks/**/*.js',
]
})
]);
var glimmerTests = merge([
transpiledTSLintTree,
find(jsTree, { include: ['*/tests/**/*.js', '@glimmer/*/tests/**/*.js'], exclude: ['@glimmer/node/tests/**/*.js'] }),
find(jsTree, { include: ['@glimmer/test-helpers/**/*.js'] })
]);
glimmerTests = transpile(glimmerTests, babelOptions, 'glimmer-tests');
// Test Assets
var testHarnessTrees = [
find(__dirname + '/tests', {
srcDir: '/',
files: [ 'index.html' ],
destDir: '/tests'
})
];
if (hasBower) {
testHarnessTrees.push(find(bower, {
srcDir: '/qunit/qunit',
destDir: '/tests'
}));
}
var testHarness = merge(testHarnessTrees);
glimmerCommon = concat(glimmerCommon, {
inputFiles: ['**/*.js'],
outputFile: '/amd/glimmer-common.amd.js',
sourceMapConfig: {
enabled: true,
cache: null,
sourceRoot: '/'
}
});
glimmerCompiler = concat(glimmerCompiler, {
inputFiles: ['**/*.js'],
outputFile: '/amd/glimmer-compiler.amd.js',
sourceMapConfig: {
enabled: true,
cache: null,
sourceRoot: '/'
}
});
glimmerRuntime = concat(glimmerRuntime, {
inputFiles: ['**/*.js'],
outputFile: '/amd/glimmer-runtime.amd.js',
sourceMapConfig: {
enabled: true,
cache: null,
sourceRoot: '/'
}
});
glimmerDemos = concat(glimmerDemos, {
inputFiles: ['**/*.js'],
outputFile: '/amd/glimmer-demos.amd.js',
sourceMapConfig: {
enabled: true,
cache: null,
sourceRoot: '/'
}
});
glimmerBenchmarks = concat(glimmerBenchmarks, {
inputFiles: ['**/*.js'],
outputFile: '/amd/glimmer-benchmarks.amd.js',
sourceMapConfig: {
enabled: true,
cache: null,
sourceRoot: '/'
}
});
glimmerTests = concat(glimmerTests, {
inputFiles: ['**/*.js'],
outputFile: '/amd/glimmer-tests.amd.js',
sourceMapConfig: {
enabled: true,
cache: null,
sourceRoot: '/'
}
});
var finalTrees = [
testHarness,
demos,
merge(benchmarkTrees),
glimmerCommon,
glimmerCompiler,
glimmerRuntime,
glimmerTests,
glimmerDemos,
glimmerBenchmarks,
cjsTree,
es5LibTree,
es6LibTree
];
if (hasBower) {
var loader = find(__dirname + '/node_modules', {
srcDir: '/loader.js/lib/loader',
files: [ 'loader.js' ],
destDir: '/assets'
});
finalTrees.push(loader);
}
return merge(finalTrees);
};