-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathember-app.js
170 lines (141 loc) · 4.91 KB
/
ember-app.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
/*jshint node:true*/
/* global require, module */
'use strict';
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var EOL = require('os').EOL;
var Funnel = require('broccoli-funnel');
var upstreamMergeTrees = require('broccoli-merge-trees');
var mergeTrees = function(inputTree, options) {
options = options || {};
options.description = options.annotation;
var tree = upstreamMergeTrees(inputTree, options);
tree.description = options && options.description;
return tree;
};
/**
* @class: EmberApp
* @desc: Extending the Ember app to support multiple bundles
*
* Available init options: see: ember-cli/lib/broccoli/ember-app
- bundles: [
{
fileName: "index"
pattern: ["** /index.js", "** /index.hbs"]
}
]
*
*/
var EmberAppBundle = function(){
EmberApp.apply(this,arguments);
var options;
if(arguments.length == 2){
options = arguments[1]
}else if(arguments.length == 1) {
options = arguments[0]
}else {
options = {}
}
this.bundleCofig = options.bundles ? options.bundles : {}
};
EmberAppBundle.prototype = Object.create(EmberApp.prototype);
EmberAppBundle.prototype.constructor = EmberAppBundle;
EmberAppBundle.prototype.javascript = function(){
var deprecate = this.project.ui.writeDeprecateLine.bind(this.project.ui);
var applicationJs = this.appAndDependencies();
var appOutputPath = this.options.outputPaths.app.js;
var appJs = applicationJs;
// Note: If ember-cli-babel is installed we have already performed the transpilation at this point
if (!this._addonInstalled('ember-cli-babel')) {
appJs = new Babel(
new Funnel(applicationJs, {
include: [escapeRegExp(this.name + '/') + '**/*.js'],
annotation: 'Funnel: App JS Files'
}),
merge(this._prunedBabelOptions())
);
}
var bundleFiles = Object.keys(this.bundleCofig)
.filter(function(key){
var bundle = this.bundleCofig[key];
if(bundle && bundle.files && bundle.files.length > 0){
return true
}
},this)
.map(function(key){
var bundle = this.bundleCofig[key];
bundle["name"] = key;
var bundleJS = new Funnel(applicationJs, {
include: bundle.files,
getDestinationPath: function(relativePath) {
return relativePath;
}
});
return {config: bundle, tree: bundleJS};
},this).map(function(bundleTree){
return this.concatFiles(bundleTree.tree, {
inputFiles: [this.name + '/**/*.js'],
outputFile: appOutputPath.replace(".js", "."+bundleTree.config.name.toLowerCase() + ".bundle.js") ,
annotation: 'Concat: App-Index'
});
},this);
/**
* Exclude the bundle files from the main file
* #
*/
var excludedFiles = Object.keys(this.bundleCofig).map(function(key){
return this.bundleCofig[key].files;
},this);
//Flattern array
excludedFiles = [].concat.apply([],excludedFiles);
appJs = new Funnel(applicationJs, {
exclude: excludedFiles,
getDestinationPath: function(relativePath) {
return relativePath;
}
});
appJs = mergeTrees([
appJs,
this._processedEmberCLITree()
], {
annotation: 'TreeMerger (appJS & processedEmberCLITree)',
overwrite: true
});
appJs = this.concatFiles(appJs, {
inputFiles: [this.name + '/**/*.js'],
headerFiles: [
'vendor/ember-cli/app-prefix.js'
],
footerFiles: [
'vendor/ember-cli/app-suffix.js',
'vendor/ember-cli/app-config.js',
'vendor/ember-cli/app-boot.js'
],
outputFile: appOutputPath,
annotation: 'Concat: App'
});
if (this.legacyFilesToAppend.length > 0) {
deprecate('Usage of EmberApp.legacyFilesToAppend is deprecated. Please use EmberApp.import instead for the following files: \'' + this.legacyFilesToAppend.join('\', \'') + '\'');
this.legacyFilesToAppend.forEach(function(legacyFile) {
this.import(legacyFile);
}.bind(this));
}
this.import('vendor/ember-cli/vendor-prefix.js', {prepend: true});
this.import('vendor/addons.js');
this.import('vendor/ember-cli/vendor-suffix.js');
var vendorFiles = [];
for (var outputFile in this._scriptOutputFiles) {
var inputFiles = this._scriptOutputFiles[outputFile];
vendorFiles.push(
this.concatFiles(applicationJs, {
inputFiles: inputFiles,
outputFile: outputFile,
separator: EOL + ';',
annotation: 'Concat: Vendor ' + outputFile
})
);
}
return mergeTrees(vendorFiles.concat(appJs).concat(bundleFiles), {
annotation: 'TreeMerger (vendor & appJS)'
});
}
module.exports = EmberAppBundle;