forked from tildeio/router.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-cli-build.js
151 lines (123 loc) · 3.69 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
/* eslint-env node */
const path = require('path');
const Funnel = require('broccoli-funnel');
const MergeTrees = require('broccoli-merge-trees');
const Babel = require('broccoli-babel-transpiler');
const Concat = require('broccoli-concat');
const typescript = require('broccoli-typescript-compiler').default;
const ensurePosix = require('ensure-posix-path');
const moduleResolver = require('amd-name-resolver').resolveModules({
throwOnRootAccess: false,
});
function findLib(name, libPath) {
let packagePath = path.join(name, 'package');
let packageRoot = path.dirname(require.resolve(packagePath));
libPath = libPath || getLibPath(packagePath);
return path.resolve(packageRoot, libPath);
}
function getLibPath(packagePath) {
let packageJson = require(packagePath);
return path.dirname(packageJson['module'] || packageJson['main']);
}
function getRelativeModulePath(modulePath) {
return ensurePosix(path.relative(process.cwd(), modulePath));
}
getRelativeModulePath.baseDir = () => __dirname;
function resolveRelativeModulePath(name, child) {
return moduleResolver(name, getRelativeModulePath(child));
}
resolveRelativeModulePath.baseDir = () => __dirname;
function toAMD(tree) {
const isProduction = process.env.EMBER_ENV === 'production';
const isDebug = !isProduction;
return new Babel(tree, {
moduleIds: true,
getModuleId: getRelativeModulePath,
plugins: [
['module-resolver', { resolvePath: resolveRelativeModulePath }],
['@babel/plugin-transform-modules-amd', { noInterop: true }],
[
'babel-plugin-debug-macros',
{
flags: [
{
source: '@glimmer/env',
flags: { DEBUG: isDebug, CI: !!process.env.CI },
},
],
},
'@glimmer/env inlining',
],
],
});
}
module.exports = function () {
let ts = 'lib';
let eslatest = new Funnel(typescript(ts), {
srcDir: 'lib',
});
let amd = toAMD(eslatest);
let cjs = new Babel(eslatest, {
plugins: [['@babel/plugin-transform-modules-commonjs']],
});
let trees = [
new Funnel(eslatest, { srcDir: 'router', destDir: 'modules' }),
new Funnel(cjs, { srcDir: 'router', destDir: 'cjs' }),
];
let tsTests = typescript('tests');
let testAMD = toAMD(tsTests);
let concattedTests = new Concat(testAMD, {
inputFiles: ['**/*.js'],
outputFile: 'tests/tests.js',
});
let concattedAMD = new Concat(amd, {
inputFiles: ['**/*.js'],
// putting this in test to avoid publishing
outputFile: 'tests/router.amd.js',
});
let rsvp = new Funnel(findLib('rsvp'), {
files: ['rsvp.es.js'],
getDestinationPath() {
return 'rsvp.js';
},
});
let rsvpAMD = toAMD(rsvp);
let rr = new Funnel(findLib('route-recognizer'), {
files: ['route-recognizer.es.js'],
getDestinationPath() {
return 'route-recognizer.js';
},
});
let rrAMD = toAMD(rr);
let backburner = new Funnel(findLib('backburner.js', 'dist/es6'), {
files: ['backburner.js'],
annotation: 'backburner es',
});
let backburnerAMD = toAMD(backburner);
let vendorTree = new MergeTrees([rsvpAMD, rrAMD, backburnerAMD]);
let vendor = new Concat(vendorTree, {
inputFiles: '**/*.js',
outputFile: 'vendor/vendor.js',
});
trees = trees.concat([
concattedAMD,
// dependencies
new Funnel(findLib('loader.js'), {
destDir: 'vendor',
annotation: 'loader.js',
}),
new Funnel(findLib('qunit'), {
files: ['qunit.js', 'qunit.css'],
destDir: 'vendor',
annotation: 'qunit',
}),
vendor,
// tests
new Funnel('tests', {
files: ['index.html'],
destDir: 'tests',
}),
concattedTests,
]);
return new MergeTrees(trees);
};