-
Notifications
You must be signed in to change notification settings - Fork 1
/
ember-cli-build.js
132 lines (119 loc) · 4.48 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
/*jshint node:true*/
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-app'),
Funnel = require('broccoli-funnel'),
mergeTrees = require('broccoli-merge-trees'),
packageNames = require('./config/package-names'),
AssetRev = require('broccoli-asset-rev');
// TODO: future API for packagin
// var emberApp = EmberAppWithPackages({
// sharedConfig: {},
// mainAppConfig: {},
// packagesConfig: {}
// });
// return emberApp.toTree();
module.exports = function(defaults) {
var env = process.env.EMBER_ENV,
commonConfig = {
// Instructions: Add your custom shared config for packages and the boot app
hinting: false,
fingerprint: {
// Disabling here since we do it at the end for *all* the assets
enabled: false,
}
},
bootAppConfig = {
// Instructions: Add your custom config for the boot app here
},
bootApp, packagesApplications, bootAppTree, movedPackagesApplicationTrees;
bootApp = new EmberApp(defaults, commonConfig, bootAppConfig);
// bootApp.import('only-import-dependencies-to-boot-NOT-to-packages');
bootAppTree = bootApp.toTree();
// packages subsequent calls to EmberApp() constructor must come after the main app.toTree
// in order for the addons to run postprocessTree correctly
packagesApplications = packageNames.map(function(packageName) {
// packages export their own js file and are intended to distribute the code-base.
var packageConfig = {
// Instructions: Add your custom config for packages here
name: packageName,
// TODO: re-enable jshint once it's actually working fine, for now it just slows down the build
// when running `ember test` it only jshints boot, but not this one. We'll rely on grunt for now
tests: false,
outputPaths: {
app: {
js: '/assets/' + packageName + '.js'
}
},
trees: {
app: mergeTrees([
// The index.html is required, so we funnel it here, but return it unmodified
// below (see package.index) to avoid running ConfigReplace
new Funnel('app', { files: ['index.html'] }),
new Funnel('packages/' + packageName)
]),
styles: new Funnel('packages/' + packageName + '/styles'),
templates: new Funnel('packages/' + packageName + '/templates')
},
vendorFiles: {
// Avoids serving the same dependency twice. List extracted from ember-cli/lib/broccoli/ember-app.js#_initVendorFiles
'jquery.js': null,
'handlebars.js': null,
'ember.js': null,
'loader.js': null,
// We need to leave this as is.
// 'ember-testing.js': null,
'app-shims.js': null,
'ember-resolver.js': null,
'ember-data': null, // do this for boot as well if you don't use ember-data
'ember-cli-app-version': null,
'vendor-suffix': null,
'ember-load-initializers.js': null,
'ember-debug-handlers-polyfill': null,
'ember-cli-deprecation-workflow': null,
'ic-ajax': null
}
},
package = new EmberApp(defaults, commonConfig, packageConfig);
// Prevent packages from creating their own Ember Application
package.contentFor = function(config, match, type) {
if (type === 'app-boot' || type === 'app-config') {
return '';
} else {
return EmberApp.prototype.contentFor.call(this, config, match, type);
}
};
package.index = function () {
var htmlName = this.options.outputPaths.app.html;
var files = ['index.html'];
var index = new Funnel(this.trees.app, {
files: files,
getDestinationPath: function(relativePath) {
if (relativePath === 'index.html') {
relativePath = htmlName;
}
return relativePath;
},
annotation: 'Funnel: index.html'
});
return index;
};
// Only boot includes addon's code
package.addonTreesFor = function(type) {
if (type === 'app') {
return [];
} else {
return EmberApp.prototype.addonTreesFor.call(this, type);
}
};
return package;
});
movedPackagesApplicationTrees = packagesApplications.map(function(package) {
var packageTree = package.toTree();
return new Funnel(packageTree);
});
var allTrees = mergeTrees(movedPackagesApplicationTrees.concat([bootAppTree/*, publicVendorFiles*/]), { overwrite: true });
if (env === 'production') {
allTrees = new AssetRev(allTrees);
}
return allTrees;
};