-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
97 lines (75 loc) · 2.43 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'use strict';
const Funnel = require('broccoli-funnel');
const path = require('path');
const componentDependencies = {
'uni-auth-modal': ['uni-modal'],
'uni-autocomplete': ['uni-autocomplete-no-results'],
'uni-checkbox': ['uni-input-container'],
'uni-country': ['uni-autocomplete'],
'uni-datepicker-input': ['uni-datepicker'],
'uni-file-upload': ['uni-button'],
'uni-form': ['uni-button'],
// @TODO: Check if 'uni-info-card' is still used in any platform
// If not, kill it with fire.
'uni-info-card': ['uni-modal'],
'uni-mobile-number': ['uni-select', 'uni-tooltip'],
'uni-modal': ['uni-title'],
'uni-multi-selector': ['uni-selector-button'],
'uni-radio-button': ['uni-input-container'],
'uni-textarea': ['uni-tooltip'],
'uni-title': ['uni-subtitle']
}
module.exports = {
name: require('./package').name,
included() {
this._super.included.apply(this, arguments);
this.app = this._findHost();
this.emberCliUniqOptions = Object.assign({}, this.app.options[this.name]);
this.whitelist = this.generateWhitelist(this.emberCliUniqOptions.only);
},
treeForAddon() {
let tree = this._super.treeForAddon.apply(this, arguments);
return this.filterComponents(tree);
},
treeForAddonTemplates() {
let tree = this._super.treeForAddonTemplates.apply(this, arguments);
return this.filterComponents(tree);
},
filterComponents(tree) {
const whitelist = this.whitelist;
if (this.whitelist.length === 0) {
return tree;
}
return new Funnel(tree, {
exclude: [(name) => this.excludeComponent(name, whitelist)]
});
},
excludeComponent(name, whitelist) {
let regex = /(templates\/)?components\//;
let isComponent = regex.test(name);
if (!isComponent) {
return false;
}
let baseName = path.basename(name);
baseName = baseName.split('.').shift();
let isWhitelisted = whitelist.indexOf(baseName) !== -1;
return !isWhitelisted;
},
// https://github.com/kaliber5/ember-bootstrap/blob/master/index.js#L325
generateWhitelist(whitelist) {
let whitelisted = [];
if (!whitelist) {
return whitelisted;
}
function _addToWhitelist(item) {
if (whitelisted.indexOf(item) === -1) {
whitelisted.push(item);
if (componentDependencies[item]) {
componentDependencies[item].forEach(_addToWhitelist);
}
}
}
whitelist.forEach(_addToWhitelist);
return whitelisted;
}
};