-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
67 lines (61 loc) · 2.18 KB
/
index.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
/* jshint node: true */
'use strict';
var path = require('path');
var stringReplace = require('broccoli-string-replace');
module.exports = {
name: 'ember-esri-loader',
postprocessTree: function (type, tree) {
if (type !== 'all')
return tree;
var outputPaths = this.app.options.outputPaths;
// Create the string replace patterns for the various application files
// We will replace require and define function call by their pig-latin version
var data = {
files: [
new RegExp(path.parse(outputPaths.app.js).name + '(.*js)'),
new RegExp(path.parse(outputPaths.vendor.js).name + '(.*js)'),
new RegExp(path.parse(outputPaths.tests.js).name + '(.*js)'),
new RegExp(path.parse(outputPaths.testSupport.js.testSupport).name + '(.*js)')
],
patterns: [{
match: /([^A-Za-z0-9_#]|^|["])define(\W|["]|$)/g,
replacement: '$1efineday$2'
}, {
match: /(\W|^|["])require(\W|["]|$)/g,
replacement: '$1equireray$2'
}, {
// TODO: probably a better way to achieve this, but for now
// we use a special token "__dojoRequire" for the places in the
// esri-loader service where we want to allow nested require statements
// and this regExp will replace that token with calls to require()
match: /(\W|^|["])__dojoRequire(\W|["]|$)/g,
replacement: '$1require$2'
}]
};
var dataTree = stringReplace(tree, data);
// Special case for the test loader that is doing some funky stuff with require
// We basically decided to pig latin all require cases.
var testLoader = {
files: [
new RegExp(path.parse(outputPaths.testSupport.js.testLoader).name + '(.*js)')
],
patterns: [{
match: /(\W|^|["])define(\W|["]|$)/g,
replacement: '$1efineday$2'
}, {
match: /require([.])/g,
replacement: 'equireray.'
}, {
match: /require([(])/g,
replacement: 'equireray('
}, {
match: /require([ ])/g,
replacement: 'equireray '
}, {
match: /requirejs([.])/g,
replacement: 'equireray.'
}]
};
return stringReplace(dataTree, testLoader);
}
};