-
Notifications
You must be signed in to change notification settings - Fork 10
/
ember-cli-build.js
205 lines (170 loc) · 5.23 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
/* global require, module */
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const Plugin = require('broccoli-plugin');
const mergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
const concat = require('broccoli-concat');
const writeFile = require('broccoli-file-creator');
const path = require('path');
const assetRev = require('broccoli-asset-rev');
const stew = require('broccoli-stew');
const DEBUG = false;
EmberApp.env = function() { return 'development'; }
function StubApp(options) {
return Reflect.construct(EmberApp, [options], StubApp);
}
Reflect.setPrototypeOf(StubApp.prototype, EmberApp.prototype);
Reflect.setPrototypeOf(StubApp, EmberApp);
// We don't want any of the default legacy files. But we *do* still
// want to let addons stick their own imports into the
// legacyFilesToAppend list.
StubApp.prototype.populateLegacyFiles = function() {};
let importedJsFiles = [];
let importedCssFiles = [];
let filesToExclude = [
'loader.js',
'legacy-shims.js',
'app-shims.js',
'deprecations.js',
'jquery.js'
];
// Files included via app.import need to end up in addon.js
StubApp.prototype.import = function(assetPath, options) {
options = options || {};
if (typeof assetPath === 'object') {
assetPath = assetPath[this.env];
}
if (filesToExclude.filter(file => assetPath.indexOf(file) !== -1).length === 0) {
if (DEBUG) {
console.log(assetPath);
}
let ext = path.extname(assetPath);
let isCss = ext === '.css';
let isJs = ext === '.js';
if (isCss) {
if (options.prepend) {
importedCssFiles.unshift(assetPath);
} else {
importedCssFiles.push(assetPath);
}
} else if (isJs) {
if (options.prepend) {
importedJsFiles.unshift(assetPath);
} else {
importedJsFiles.push(assetPath);
}
}
}
EmberApp.prototype.import.call(this, assetPath, options);
};
class EmptyTree extends Plugin {
constructor(names = []) {
super([], {});
this.names = names;
}
build() {
this.names.forEach(name => {
if (path.dirname(name)) {
this.output.mkdirSync(path.dirname(name), { recursive: true });
}
this.output.writeFileSync(name, '');
});
}
}
module.exports = function() {
let app = new StubApp({
name: 'twiddle',
sourcemaps: {
enabled: false
},
minifyCSS: {
enabled: false,
},
minifyJS: {
enabled: false
},
trees: {
app: new EmptyTree(),
styles: new EmptyTree(['app.css', 'app.scss']),
templates: new EmptyTree(),
public: new EmptyTree()
}
});
let origAddonTree = new Funnel(app.addonTree(), {
exclude: ['*/ember-load-initializers/**/*.js', '*/ember-resolver/**/*.js']
});
if (DEBUG) {
origAddonTree = stew.debug(origAddonTree, { name: 'origAddonTree' });
}
let addonTree = concat(mergeTrees([origAddonTree, app.addonSrcTree()]), {
inputFiles: '**/*.js',
outputFile: 'vendor/addons.js'
});
let addonTestSupportTree = concat(app.addonTestSupportTree(), {
inputFiles: '**/*.js',
outputFile: 'vendor/addon-test-support.js',
allowNone: true
});
let fullTree = mergeTrees([
app.getAddonTemplates(),
app.getStyles(),
app.getTests(),
app.getExternalTree(),
app.getSrc(),
app.getAppJavascript(false),
addonTree,
addonTestSupportTree
].filter(Boolean), { overwrite: true });
fullTree = new Funnel(fullTree, {
exclude: ['*/ember-load-initializers/**/*.js', '*/ember-resolver/**/*.js']
});
let templates = writeFile('twiddle/templates/.gitkeep', '');
fullTree = mergeTrees([fullTree, templates]);
if (DEBUG) {
fullTree = stew.debug(fullTree, { name: 'fullTree' });
}
let processedTree = mergeTrees([
new EmptyTree(['assets/vendor.js', 'assets/test-support.js']),
app._defaultPackager.processAppAndDependencies(fullTree),
app._defaultPackager.packageStyles(fullTree)
], { overwrite: true });
if (DEBUG) {
processedTree = stew.debug(processedTree, { name: 'processedTree' });
}
let postProcessedTree = app.addonPostprocessTree('all', processedTree);
if (DEBUG) {
postProcessedTree = stew.debug(postProcessedTree, { name: 'postProcessedTree' });
}
let headerFiles = importedJsFiles
.concat(app.legacyFilesToAppend || [])
.concat(['vendor/addons.js', 'vendor/addon-test-support.js']);
let cssTree = concat(postProcessedTree, {
headerFiles: importedCssFiles,
inputFiles: ['**/*.css'],
outputFile: '/addon.css',
allowNone: false,
sourceMapConfig: { enabled: false },
annotation: 'Concat: Addon CSS'
});
let publicTree = new Funnel(app.getPublic(), {
srcDir:'assets',
destDir:'.',
allowEmpty:true
});
let jsTree = concat(postProcessedTree, {
headerFiles: headerFiles,
inputFiles: ['assets/vendor.js', 'assets/test-support.js', 'twiddle/**/*.js'],
outputFile: '/addon.js',
allowNone: true,
sourceMapConfig: { enabled: false },
annotation: 'Concat: Addon JS'
});
let mergedTree = mergeTrees([cssTree, publicTree, jsTree]);
if (DEBUG) {
mergedTree = stew.debug(mergedTree, { name: 'mergedTree' });
}
let fingerprintedTree = new assetRev(mergedTree, {
generateAssetMap: true
});
return fingerprintedTree;
};