-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.js
103 lines (83 loc) · 2.71 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
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
'use strict';
var fs = require('fs');
var path = require('path');
function injectScript(scriptName) {
var filePath = path.join(__dirname, 'lib', 'resources', scriptName);
return '<script>\n' + fs.readFileSync(filePath, { encoding: 'utf8' }) + '\n</script>';
}
module.exports = {
name: 'ember-cli-nwjs',
included: function(app) {
this._super.included(app);
if (!process.env.EMBER_CLI_NW) { return; }
app.import({ development: 'vendor/nwjs/reload.js' });
if (process.env.NW_TESTS_DEV) {
app.import({ test: 'vendor/nwjs/browser-qunit-adapter.js' });
} else {
app.import({ test: 'vendor/nwjs/tap-qunit-adapter.js' });
}
},
includedCommands: function() {
return {
'nw': require('./lib/commands/nw'),
'nw:package': require('./lib/commands/nw-package'),
'nw:test': require('./lib/commands/nw-test')
}
},
treeForVendor: function() {
return path.join(__dirname, 'client');
},
postprocessTree: function(type, tree) {
if (!process.env.EMBER_CLI_NW) {
return tree;
}
if (type === 'all' && process.env.EMBER_ENV === 'test') {
var funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var replace = require('broccoli-string-replace');
// Update the base URL in `tests/index.html`
var index = replace(tree, {
files: ['tests/index.html'],
pattern: {
match: /base href="\/"/,
replacement: 'base href="../"'
}
});
// Copy `tests/package.json` to the output directory
var testPkg = funnel('tests', {
files: ['package.json'],
destDir: '/tests'
});
var testPageOptions = process.env.NW_TEST_PAGE_OPTIONS;
if (testPageOptions) {
testPkg = replace(testPkg, {
files: ['tests/package.json'],
patterns: [{
match: /"main":\s*"(index.html\?[^\"]+)"/,
replacement: '"main": "$1&' + testPageOptions + '"'
}, {
match: /"main":\s*"index.html"/,
replacement: '"main": "index.html?' + testPageOptions + '"'
}]
});
}
return mergeTrees([tree, index, testPkg], { overwrite: true });
}
return tree;
},
contentFor: function(type) {
if (!process.env.EMBER_CLI_NW) { return; }
if (type === 'head') {
return injectScript('shim-head.js');
}
if (type === 'body-footer') {
return injectScript('shim-footer.js');
}
if (type === 'test-body' && process.env.EMBER_ENV === 'test') {
var testemServer = process.env.NW_TESTEM_SERVER_URL;
if (testemServer) {
return '<script src="' + testemServer + '/socket.io/socket.io.js"></script>';
}
}
}
};