forked from tildeio/router.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-cli-build.js
152 lines (124 loc) · 3.28 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
/* 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 TSLint = require('broccoli-tslinter');
const typescript = require('broccoli-typescript-compiler').default;
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 toAMD(tree) {
return new Babel(tree, {
presets: [
[
'env',
{
modules: 'amd',
targets: {
browsers: ['ie 9'],
},
},
],
],
resolveModuleSource: require('amd-name-resolver').moduleResolve,
moduleIds: true,
});
}
module.exports = function() {
let ts = 'lib';
let eslatest = new Funnel(typescript(ts), {
srcDir: 'lib',
});
let amd = toAMD(eslatest);
let cjs = new Babel(eslatest, {
presets: [
[
'env',
{
modules: 'commonjs',
targets: {
node: 4,
},
},
],
],
});
let trees = [
new Funnel(eslatest, { srcDir: 'router', destDir: 'modules' }),
new Funnel(cjs, { srcDir: 'router', destDir: 'cjs' }),
];
let lintedLib = new TSLint('lib/router', {
configuration: 'tslint.json',
});
let lintedTests = new TSLint('tests', {
configuration: 'tslint.json',
});
let tsTests = typescript('tests');
let testAMD = toAMD(tsTests);
let tests = new MergeTrees([testAMD, lintedLib, lintedTests], {
overwrite: true,
});
let concattedTests = new Concat(tests, {
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 = 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);
};