-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
46 lines (34 loc) · 1.08 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
'use strict';
const caniuse = require('caniuse-api');
const defaultOptions = { themes: ['classic'] };
function buildOptions(app) {
const customOptions = app.options['ember-pickr'] || {};
return Object.assign({}, defaultOptions, customOptions);
}
module.exports = {
name: require('./package').name,
options: {
autoImport: {
alias: {}
}
},
choosePickrForTargets(targets = {}) {
let { browsers = [] } = targets;
let browserQuery = browsers.join(',');
if (caniuse.isSupported('es6-module', browserQuery)) {
return '@simonwep/pickr/dist/pickr.min.js';
}
return '@simonwep/pickr/dist/pickr.es5.min.js';
},
included: function() {
this._super.included.apply(this, arguments);
let findHost = this._findHost;
let app = findHost.call(this);
const options = buildOptions(app);
this.app = app;
options.themes.forEach(theme =>
app.import(`node_modules/@simonwep/pickr/dist/themes/${theme}.min.css`));
let targets = this.project.targets;
this.options.autoImport.alias.pickr = this.choosePickrForTargets(targets);
}
};