1 | function injectScript(scriptName) {
|
2 | return `<script src="/ember-electron/${scriptName}"></script>`;
|
3 | }
|
4 |
|
5 | module.exports = {
|
6 | name: require('./package').name,
|
7 |
|
8 | includedCommands() {
|
9 | return {
|
10 | electron: require('./lib/commands/electron'),
|
11 | 'electron:test': require('./lib/commands/test'),
|
12 | 'electron:build': require('./lib/commands/build'),
|
13 | 'electron:package': require('./lib/commands/package'),
|
14 | 'electron:make': require('./lib/commands/make'),
|
15 | };
|
16 | },
|
17 |
|
18 | included(app) {
|
19 | this._super.included.apply(this, arguments);
|
20 |
|
21 | app.import('vendor/wrap-require.js', {
|
22 | type: 'vendor',
|
23 | });
|
24 | },
|
25 |
|
26 | contentFor(type) {
|
27 | const {
|
28 | env: { EMBER_CLI_ELECTRON },
|
29 | } = process;
|
30 |
|
31 | if (EMBER_CLI_ELECTRON) {
|
32 | switch (type) {
|
33 | case 'head':
|
34 | return injectScript('shim-head.js');
|
35 | case 'test-head':
|
36 | // shim-test-head.js does some testem setup, and we need to set the
|
37 | // base to `..` so the base URL of assets loaded from
|
38 | // `tests/index.html` will be the same as the base URL of assets
|
39 | // loaded from `index.html`, and the assets will load correctly (see
|
40 | // https://ember-electron.js.org/versions/v3.0.0-beta.5/docs/faq/routing-and-asset-loading)
|
41 | return [injectScript('shim-test-head.js'), '<base href="..">'].join(
|
42 | '\n'
|
43 | );
|
44 | case 'test-body':
|
45 | // testem.js needs to load over HTTP because of how testem works. We
|
46 | // have main process code to intercept `http://testemserver` requests
|
47 | // and redirect them to the actual testem server URL. We don't have a
|
48 | // good embroider-safe way of rewriting the script tag that already
|
49 | // exists in `tests/index.html`, so we just leave it there harmlessly
|
50 | // no-op'ing, and add another script tag that will load testem.js via
|
51 | // `http://testemserver`.
|
52 | return '<script src="http://testemserver/testem.js"></script>';
|
53 | case 'body-footer':
|
54 | return injectScript('shim-footer.js');
|
55 | }
|
56 | }
|
57 | },
|
58 | };
|