-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
140 lines (120 loc) · 4.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict';
const { name } = require('./package');
const Funnel = require('broccoli-funnel');
const MergeTrees = require('broccoli-merge-trees');
const resolve = require('resolve');
const path = require('path');
const postcssImport = require('postcss-import');
const postcssPresetEnv = require('postcss-preset-env');
const postcssEach = require('postcss-each');
const postcssMixins = require('postcss-mixins');
const postcssConditionals = require('postcss-conditionals-renewed');
const postcssAtRulesVariables = require('postcss-at-rules-variables');
const autoprefixer = require('autoprefixer');
const tailwind = require('tailwindcss');
const tailwindConfigPath = path.resolve(__dirname, 'tailwind.js');
const postcssOptions = {
compile: {
enabled: true,
cacheInclude: [/.*\.(css|scss|hbs)$/, /.*\/tailwind\/config\.js$/, /.*tailwind\.js$/],
plugins: [
postcssAtRulesVariables,
postcssImport({
path: ['node_modules'],
plugins: [postcssAtRulesVariables, postcssImport],
}),
postcssMixins,
postcssPresetEnv({ stage: 1 }),
postcssEach,
tailwind(tailwindConfigPath),
autoprefixer,
],
},
filter: {
enabled: true,
plugins: [postcssAtRulesVariables, postcssMixins, postcssEach, postcssConditionals, tailwind(tailwindConfigPath)],
},
};
module.exports = {
name,
options: {
autoImport: {
publicAssetsURL: '/assets',
alias: {
libphonenumber: 'intl-tel-input/build/js/utils.js',
},
},
postcssOptions,
},
included: function (app) {
this._super.included.apply(this, arguments);
// Get Application Host
app = this.findApplicationHost(app);
// PostCSS Options
app.options = app.options || {};
app.options.postcssOptions = postcssOptions;
// Import leaflet-src
this.import('node_modules/leaflet/dist/leaflet-src.js');
this.import('node_modules/leaflet/dist/leaflet.css');
// Import the `intlTelInput.min.css` file and append it to the parent application's `vendor.css`
this.import('node_modules/intl-tel-input/build/css/intlTelInput.min.css');
},
treeForLeaflet: function () {
const leafletImagesPath = path.join(this.pathBase('leaflet'), 'dist', 'images');
const trees = [
new Funnel(leafletImagesPath, {
srcDir: '/',
destDir: '/assets/images',
allowEmpty: true,
}),
];
return trees;
},
treeForIntlTelInput: function () {
const intlTelInputPath = path.dirname(require.resolve('intl-tel-input')).replace(/build\/js$/, '');
const trees = [
new Funnel(`${intlTelInputPath}/build/js`, {
include: ['utils.js'],
destDir: 'assets/libphonenumber',
allowEmpty: true,
}),
new Funnel(`${intlTelInputPath}/build/img`, {
destDir: 'img',
overwrite: false,
allowEmpty: true,
}),
new Funnel(path.join(__dirname, 'assets'), {
destDir: '/',
allowEmpty: true,
}),
];
return trees;
},
mergeWithPublicTree: function (publicTree) {
const intlTelInputTree = this.treeForIntlTelInput();
const leafletTree = this.treeForLeaflet();
const addonTree = [...intlTelInputTree, ...leafletTree];
return publicTree ? new MergeTrees([publicTree, ...addonTree], { overwrite: true }) : new MergeTrees([...addonTree], { overwrite: true });
},
treeForPublic: function () {
const publicTree = this._super.treeForPublic.apply(this, arguments);
return this.mergeWithPublicTree(publicTree);
},
pathBase(packageName) {
return path.dirname(resolve.sync(packageName + '/package.json', { basedir: __dirname }));
},
findApplicationHost(app) {
let current = this;
do {
if (current.lazyLoading === true || (current.lazyLoading && current.lazyLoading.enabled === true)) {
app = current;
break;
}
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
return app;
},
isDevelopingAddon: function () {
return true;
},
};