forked from RobbieTheWagner/ember-flatpickr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
92 lines (73 loc) · 2.48 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
'use strict';
module.exports = {
name: require('./package').name,
included() {
let app;
// If the addon has the _findHost() method (in ember-cli >= 2.7.0), we'll just
// use that.
if (typeof this._findHost === 'function') {
app = this._findHost();
} else {
// Otherwise, we'll use this implementation borrowed from the _findHost()
// method in ember-cli.
let current = this;
do {
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
}
const vendorPath = 'vendor/flatpickr';
this.import(`${vendorPath}/flatpickr.js`);
if (app.options && app.options.flatpickr && app.options.flatpickr.theme) {
this.import(`${vendorPath}/themes/${app.options.flatpickr.theme}.css`);
} else {
this.import(`${vendorPath}/flatpickr.css`);
}
let locales = [];
if (app.options && app.options.flatpickr && app.options.flatpickr.locales) {
locales = app.options.flatpickr.locales;
const localePaths = Array.isArray(locales)
? locales.map((locale) => `l10n/${locale}.js`)
: [];
localePaths.forEach((locale) => {
this.import(`${vendorPath}/${locale}`);
});
}
this._super.included.apply(this, arguments);
},
treeForVendor(defaultTree) {
const map = require('broccoli-stew').map;
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
const path = require('path');
const distPath = path.dirname(require.resolve('flatpickr'));
let browserVendorLib = new Funnel(distPath, {
destDir: 'flatpickr',
files: ['flatpickr.js'],
});
browserVendorLib = map(
browserVendorLib,
(content) => `if (typeof FastBoot === 'undefined') { ${content} }`
);
let browserVendorLocales = new Funnel(path.join(distPath, '/l10n'), {
destDir: 'flatpickr/l10n',
include: ['*.js'],
});
browserVendorLocales = map(
browserVendorLocales,
(content) => `if (typeof FastBoot === 'undefined') { ${content} }`
);
let defaultCSS = new Funnel(distPath, {
destDir: 'flatpickr',
include: ['flatpickr.css'],
});
let themes = new Funnel(path.join(distPath, '/themes'), {
destDir: 'flatpickr/themes',
include: ['*.css'],
});
let nodes = [browserVendorLib, browserVendorLocales, defaultCSS, themes];
if (defaultTree) {
nodes.unshift(defaultTree);
}
return new mergeTrees(nodes);
},
};