-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
64 lines (53 loc) · 1.59 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
'use strict';
const Funnel = require('broccoli-funnel');
const MergeTrees = require('broccoli-merge-trees');
const map = require('broccoli-stew').map;
const path = require('path');
module.exports = {
name: require('./package').name,
included: function () {
this._super.included.apply(this, arguments);
this._ensureThisImport();
this.import('vendor/toastr/toastr.js');
this.import('vendor/toastr/build/toastr.css');
},
treeForVendor: function (vendorTree) {
let toastrPath = path.dirname(require.resolve('toastr'));
let trees = [];
if (vendorTree) {
trees.push(vendorTree);
}
let toastrJsTree = new Funnel(toastrPath, {
include: ['toastr.js'],
destDir: 'toastr',
});
let toastrCssTree = new Funnel(toastrPath, {
include: ['build/toastr.css'],
destDir: 'toastr',
});
// protect against usage in node since it depends on jquery
toastrJsTree = map(
toastrJsTree,
(content) => `if (typeof FastBoot === 'undefined') { ${content} }`
);
trees.push(toastrCssTree);
trees.push(toastrJsTree);
return new MergeTrees(trees, { overwrite: true });
},
_ensureThisImport: function () {
if (!this.import) {
this._findHost = function findHostShim() {
let current = this;
let app;
do {
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
return app;
};
this.import = function importShim(asset, options) {
let app = this._findHost();
app.import(asset, options);
};
}
},
};