forked from dfreeman/ember-ace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (58 loc) · 1.56 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
/* eslint-env node */
'use strict';
module.exports = {
name: 'ember-ace',
options: {
nodeAssets: {
'ace-builds': function() {
return {
srcDir: 'src-noconflict',
import: calculateImports(this.aceOptions),
public: calculatePublicFiles(this.aceOptions)
};
}
}
},
included: function(parent) {
this.aceOptions = (parent.options || {}).ace || {};
this._super.included.apply(this, arguments);
},
treeForAddon: function(tree) {
var WorkerManifest = require('./lib/worker-manifest');
var manifest = new WorkerManifest({
workerPaths: calculateWorkerPaths(this.aceOptions)
});
var merged = require('broccoli-merge-trees')([tree, manifest]);
return this._super.treeForAddon.call(this, merged);
}
};
function calculateImports(options) {
var imports = ['ace.js'];
['mode', 'theme', 'ext', 'keybinding'].forEach(function(type) {
var wanted = options[type + 's'];
if (!wanted) return;
wanted.forEach(function(name) {
imports.push(type + '-' + name + '.js');
});
});
return imports;
}
function calculatePublicFiles(options) {
if (options.workers) {
return {
destDir: 'assets/ace',
include: options.workers.map(function(name) {
return 'worker-' + name + '.js';
})
};
}
}
function calculateWorkerPaths(options) {
var workers = {};
if (options.workers) {
options.workers.forEach(function(name) {
workers['ace/mode/' + name + '_worker'] = '/assets/ace/worker-' + name + '.js';
});
}
return workers;
}