-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
64 lines (58 loc) · 2.06 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
/* jshint node: true */
'use strict';
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var path = require('path');
// we only need to mention the ones that aren't `strophe.plugin.js`
var PLUGIN_FILES = {
caps: ['strophe.CAPS.js'],
cmds: ['src/strophe.cmds.js'],
dataforms: ['src/strophe.x.js'],
// disco has strophe.disco.js, but need to check the alternatives
'iot-control': ['strophe.control.js'],
'iot-sensordata': ['strophe.sensordata.js'],
mam: ['strophe.mam.v0.3.js'], // also has v0.2
// roster has strophe.roster.js, but need to check the alternatives
// rpc has strophe.rpc.js, but need to check the alternatives
// test-helpers contains strophe.sentinel.js which isn't even a plugin
}
module.exports = {
name: 'ember-cli-strophe-shim',
included: function(app) {
this._super.included.apply(this, arguments);
var vendor = this.treePaths.vendor;
app.import(vendor + '/strophe/strophe.js', { prepend: true });
var config = this.getConfig();
var plugins = config.plugins || [];
plugins.forEach(function(plugin) {
app.import(vendor + '/strophe/strophe.' + plugin + '.js');
});
},
getConfig: function() {
return (this.project.config(process.env.EMBER_ENV) || {}).strophe || {};
},
treeForVendor: function(vendorTree) {
var trees = [];
if (vendorTree) {
trees.push(vendorTree);
}
var nmp = path.join(__dirname, 'node_modules');
var strophePath = path.dirname(require.resolve('strophe.js'));
var strophePluginsPath = path.join(nmp, 'strophejs-plugins');
var config = this.getConfig();
var plugins = config.plugins || [];
trees.push(new Funnel(strophePath, {
destDir: 'strophe',
include: ['strophe.js'],
}));
plugins.forEach(function(plugin) {
var p = path.join(strophePluginsPath, plugin);
var includeFiles = PLUGIN_FILES[plugin] || ['strophe.' + plugin + '.js'];
trees.push(new Funnel(p, {
destDir: 'strophe',
include: includeFiles,
}));
});
return mergeTrees(trees);
},
};