-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathindex.js
73 lines (63 loc) · 2.05 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
68
69
70
71
72
73
const fs = require('fs');
const path = require('path');
const replace = require('broccoli-string-replace');
function injectScript(scriptName) {
let dirname = __dirname || process.cwd();
let filePath = path.join(dirname, 'lib', 'resources', scriptName);
let fileContent = fs.readFileSync(filePath, { encoding: 'utf8' });
return `<script>\n${fileContent}</script>`;
}
module.exports = {
name: require('./package').name,
includedCommands() {
return {
'electron': require('./lib/commands/electron'),
'electron:test': require('./lib/commands/test'),
'electron:build': require('./lib/commands/build'),
'electron:package': require('./lib/commands/package'),
'electron:make': require('./lib/commands/make'),
};
},
included(app) {
this._super.included.apply(this, arguments);
app.import('vendor/wrap-require.js', {
type: 'vendor',
});
},
contentFor(type) {
const { env: { EMBER_CLI_ELECTRON } } = process;
if (EMBER_CLI_ELECTRON) {
let script = {
'head': 'shim-head.js',
'test-head': 'shim-test-head.js',
'body-footer': 'shim-footer.js',
}[type];
if (script) {
return injectScript(script);
}
}
},
postprocessTree(type, node) {
if (type === 'all' && process.env.EMBER_CLI_ELECTRON) {
node = replace(node, {
files: [ 'tests/index.html' ],
pattern: {
match: /(src|href)="([^"]+)"/g,
replacement(match, attr, value) {
if (value.endsWith('testem.js')) {
// Replace testem script source so our test main process code can
// recognize and redirect requests to the testem server
value = 'http://testemserver/testem.js';
} else if (!value.includes(':/')) {
// Since we're loading from the filesystem, asset URLs in
// tests/index.html need to be prepended with '../'
value = `../${value}`;
}
return `${attr}="${value}"`;
}
}
});
}
return node;
}
};