forked from emberjs/ember-inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrocfile.js
321 lines (271 loc) · 8.2 KB
/
Brocfile.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var ES6Modules = require('broccoli-es6modules');
var mergeTrees = require('broccoli-merge-trees');
var wrapFiles = require('broccoli-wrap');
var pickFiles = require('broccoli-static-compiler');
var concatFiles = require('broccoli-concat');
var removeFile = require('broccoli-file-remover');
var path = require('path');
var jsStringEscape = require('js-string-escape');
var eslint = require('broccoli-lint-eslint');
var mv = require('broccoli-stew').mv;
var writeFile = require('broccoli-file-creator');
var replace = require('broccoli-replace');
var esTranspiler = require('broccoli-babel-transpiler');
var packageJson = require('./package.json');
/*global process */
var options = {
fingerprint: {
enabled: false
},
babel: {
// async/await
optional: ['es7.asyncFunctions']
},
eslint: {
testGenerator: eslintTestGenerator
}
};
function renderErrors(errors) {
if (!errors) { return ''; };
return errors.map(function(error) {
return error.line + ':' + error.column + ' ' +
' - ' + error.message + ' (' + error.ruleId +')';
}).join('\n');
}
function eslintTestGenerator(relativePath, errors) {
var pass = !errors || errors.length === 0;
return "import { module, test } from 'qunit';\n" +
"module('ESLINT - " + path.dirname(relativePath) + "');\n" +
"test('" + relativePath + " should pass eslint', function(assert) {\n" +
" assert.ok(" + pass + ", '" + relativePath + " should pass eslint." +
jsStringEscape("\n" + renderErrors(errors)) + "');\n" +
"});\n";
}
// Firefox requires non-minified assets for review :(
options.minifyJS = { enabled: false };
options.minifyCSS = { enabled: false };
var app = new EmberApp(options);
var env = process.env.EMBER_ENV;
if (env !== 'production') {
// To be able to compile htmlbars templates in tests
app.import('bower_components/ember/ember-template-compiler.js');
}
app.import('vendor/babel-polyfill.js', { prepend: true });
// Ember Debug
var emberDebug = 'ember_debug';
emberDebug = pickFiles(emberDebug, {
srcDir: '/',
files: ['**/*.js'],
destDir: '/ember-debug'
});
emberDebug = removeFile(emberDebug, {
files: [
'ember-debug/vendor/source-map.js',
]
});
emberDebug = removeFile(emberDebug, {
files: [
'ember-debug/vendor/startup-wrapper.js',
'ember-debug/vendor/loader.js'
]
});
if (env === 'test') {
var linted = eslint(emberDebug, {
testGenerator: eslintTestGenerator,
options: {
configFile: './ember_debug/.eslintrc',
rulePaths: ['./']
}
});
emberDebug = mergeTrees([emberDebug, linted]);
}
emberDebug = new ES6Modules(emberDebug, {
esperantoOptions: {
absolutePaths: true,
strict: true
}
});
emberDebug = esTranspiler(emberDebug);
var previousEmberVersionsSupportedString = '[' + packageJson.previousEmberVersionsSupported.map(function(item) {
return "'" + item + "'";
}).join(',') + ']';
var emberVersionsSupportedString = '[' + packageJson.emberVersionsSupported.map(function(item) {
return "'" + item + "'";
}).join(',') + ']';
var startupWrapper = pickFiles('ember_debug', {
srcDir: '/vendor',
files: ['startup-wrapper.js'],
destDir: '/'
});
startupWrapper = replace(startupWrapper, {
files: ['startup-wrapper.js'],
patterns: [{
match: /{{EMBER_VERSIONS_SUPPORTED}}/,
replacement: emberVersionsSupportedString
}]
});
var sourceMap = pickFiles('ember_debug', {
srcDir: '/vendor',
files: ['source-map.js'],
destDir: '/'
});
var loader = pickFiles('ember_debug', {
srcDir: '/vendor',
files: ['loader.js'],
destDir: '/'
});
sourceMap = wrapFiles(sourceMap, {
wrapper: ["(function() {\n", "\n}());"]
});
emberDebug = mergeTrees([loader, startupWrapper, sourceMap, emberDebug]);
emberDebug = concatFiles(emberDebug, {
inputFiles: ['loader.js', '**/*.js'],
outputFile: '/ember_debug.js',
wrapInFunction: false
});
var emberDebugs = [];
['basic', 'chrome', 'firefox', 'bookmarklet', 'websocket'].forEach(function(dist) {
emberDebugs[dist] = wrapFiles(emberDebug, {
wrapper: ["(function(adapter, env) {\n", "\n}('" + dist + "', '" + env + "'));"]
});
});
var tree = app.toTree();
var emberInspectorVersionPattern = [{
match: /{{EMBER_INSPECTOR_VERSION}}/g,
replacement: packageJson.version
}];
tree = replace(tree, {
files: ['**/*.js'],
patterns: emberInspectorVersionPattern
});
var minimumVersion = packageJson.emberVersionsSupported[0].replace(/\./g, '-');
var chromeRoot = 'panes-' + minimumVersion;
var firefoxRoot = 'data/' + chromeRoot;
var bookmarkletRoot = chromeRoot;
var firefoxAndChromeExtra = pickFiles('shared', {
srcDir: '/',
files: ['in-page-script.js'],
destDir: '/'
});
var replacementPattern = [{
match: /{{env}}/,
replacement: env === 'development' ? ' [DEV]' : ''
}, {
match: /{{PANE_ROOT}}/g,
replacement: 'panes-' + minimumVersion
}, {
match: /{{PREVIOUS_EMBER_VERSIONS_SUPPORTED}}/g,
replacement: previousEmberVersionsSupportedString
}, {
match: /{{EMBER_VERSIONS_SUPPORTED}}/g,
replacement: emberVersionsSupportedString
}];
replacementPattern = replacementPattern.concat(emberInspectorVersionPattern);
var skeletonChrome = replace('skeletons/chrome', {
files: ['*'],
patterns: replacementPattern
});
var skeletonFirefox = replace('skeletons/firefox', {
files: ['*', '*/**'],
patterns: replacementPattern
});
var skeletonBookmarklet = replace('skeletons/bookmarklet', {
files: ['*'],
patterns: replacementPattern
});
var firefox = mergeTrees([
mv(mergeTrees([tree, emberDebugs.firefox]), firefoxRoot),
skeletonFirefox
]);
var chrome = mergeTrees([
mv(mergeTrees([tree, emberDebugs.chrome]), chromeRoot),
skeletonChrome
]);
var bookmarklet = mergeTrees([
mv(mergeTrees([tree, emberDebugs.bookmarklet]), chromeRoot),
skeletonBookmarklet
]);
packageJson.previousEmberVersionsSupported.forEach(function(version) {
version = version.replace(/\./g, '-');
if (env === 'production') {
var prevDist = 'dist_prev/' + env;
bookmarklet = mergeTrees([
mv(prevDist + '/bookmarklet/panes-' + version, 'panes-' + version),
bookmarklet
]);
firefox = mergeTrees([
mv(prevDist + '/firefox/panes-' + version, 'data/panes-' + version),
firefox
]);
chrome = mergeTrees([
mv(prevDist + '/chrome/panes-' + version, 'panes-' + version),
chrome
]);
} else {
var file = writeFile('index.html', "This Ember version is not supported in development environment.");
var emberDebugFile = writeFile('ember_debug.js', 'void(0);');
chrome = mergeTrees([mv(file, 'panes-' + version), chrome]);
firefox = mergeTrees([mv(file, 'data/panes-' + version), mv(emberDebugFile, 'data/panes-' + version), firefox]);
bookmarklet = mergeTrees([mv(file, 'panes-' + version), mv(emberDebugFile, 'panes-' + version), bookmarklet]);
}
});
firefox = mergeTrees([
mv(firefoxAndChromeExtra, 'data/scripts'),
firefox
]);
chrome = mergeTrees([
mv(firefoxAndChromeExtra, 'scripts'),
chrome
]);
// Pass the current dist to the Ember Inspector app.
// EMBER DIST
var dists = {
chrome: chrome,
firefox: firefox,
bookmarklet: bookmarklet,
websocket: mergeTrees([tree, emberDebugs.websocket]),
basic: mergeTrees([tree, emberDebugs.basic])
};
Object.keys(dists).forEach(function(key) {
dists[key] = replace(dists[key], {
files: ['**/*.js'],
patterns: [{
match: /{{EMBER_DIST}}/g,
replacement: key
}]
});
});
// Add {{ remote-port }} to the head
// so that the websocket addon can replace it.
dists.websocket = replace(dists.websocket, {
files: ['index.html'],
patterns: [{
match: /<head>/,
replacement: '<head>\n{{ remote-port }}\n'
}]
});
var output;
if (env === 'test') {
// `ember test` expects the index.html file to be in the
// output directory.
output = dists.basic;
} else {
// Change base tag for running tests in development env.
dists.basic = replace(dists.basic, {
files: ['tests/index.html'],
patterns: [{
match: /<base.*\/>/,
replacement: '<base href="../" />'
}]
});
output = mergeTrees([
mv(dists.bookmarklet, 'bookmarklet'),
mv(dists.firefox, 'firefox'),
mv(dists.chrome, 'chrome'),
mv(dists.websocket, 'websocket'),
mv(dists.basic, 'testing')
]);
}
module.exports = output;