-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
63 lines (50 loc) · 1.82 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
'use strict';
const path = require('path');
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
const resolve = require('resolve');
module.exports = {
name: 'ember-cli-bootstrap-colorpicker',
included(app) {
this.app = app;
this._super.included(app);
app.import('vendor/ember-cli-bootstrap-colorpicker/bs-colorpicker.css');
let vendorPath = path.join('vendor', 'bootstrap-colorpicker');
app.import(path.join(vendorPath, 'bootstrap-colorpicker.css'));
app.import(path.join(vendorPath, 'bootstrap-colorpicker.js'));
},
resolvePackagePath(pkgPath) {
let parts = pkgPath.split('/');
let pkg = parts[0];
let root = '';
// when an engine is building, this.app is undefined...
// but this.project seems to be consistently defined.
if (this.project && this.project.root) {
root = this.project.root;
} else {
console.error(`ember-cli-bootstrap-colorpicker unable to locate the project root!`); // eslint-disable-line no-console
}
let result = path.dirname(resolve.sync(`${pkg}/package.json`, { basedir: root }));
// add sub folders to path
if (parts.length > 1) {
let args = parts.map((part, i) => i === 0 ? result : part);
result = path.join.apply(path, args);
}
return result;
},
treeForVendor(tree) {
let trees = tree ? [tree] : [];
trees.push(new Funnel(this.resolvePackagePath('bootstrap-colorpicker/dist/css'), {
destDir: 'bootstrap-colorpicker'
}));
trees.push(new Funnel(this.resolvePackagePath('bootstrap-colorpicker/dist/js'), {
destDir: 'bootstrap-colorpicker'
}));
return mergeTrees(trees, { overwrite: true });
},
treeForPublic() {
return new Funnel(this.resolvePackagePath('bootstrap-colorpicker/dist/img'), {
destDir: 'img'
});
},
};