forked from omghax/ember-novnc-shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (42 loc) · 1.39 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
'use strict';
const path = require('path');
const concat = require('broccoli-concat');
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
const replace = require('broccoli-string-replace');
module.exports = {
included() {
this._super.included.apply(this, arguments);
this._findHost().import('vendor/ember-novnc-shim.js');
},
name: require('./package').name,
treeForVendor(tree) {
const novncPath = path.join(require.resolve('@novnc/novnc/core/rfb'), '..', '..');
const babelAddon = this.addons.find(addon => addon.name === 'ember-cli-babel');
const novncTree = concat(
babelAddon.transpileTree(
replace(
new Funnel(this.treeGenerator(novncPath), {
destDir: '@novnc/novnc',
include: ['core/**/*.js', 'vendor/pako/**/*.js']
}),
{
files: ['**/*.js'],
patterns: [
{ match: /\bfrom\s+(['"])(.*?)\.js\1/g, replacement: 'from $1$2$1' },
{ match: /\bimport\s+(['"])(.*?)\.js\1/g, replacement: 'import $1$2$1' }
]
}
)
),
{ outputFile: 'ember-novnc-shim.js' }
);
if (!tree) {
return this._super.treeForVendor.call(this, novncTree);
}
const trees = mergeTrees([novncTree, tree], {
overwrite: true
});
return this._super.treeForVendor.call(this, trees);
}
};