-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathindex.js
More file actions
174 lines (151 loc) · 5.95 KB
/
index.js
File metadata and controls
174 lines (151 loc) · 5.95 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
'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.config.js');
const postcssOptions = {
compile: {
enabled: true,
cacheInclude: [/.*\.(css|scss|hbs)$/, /.*\/tailwind\/config\.js$/, /.*tailwind\.js$/],
plugins: [
postcssAtRulesVariables,
postcssImport({
path: ['node_modules', path.join(__dirname, 'addon/styles')],
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',
},
},
'ember-leaflet': {
excludeCSS: true,
excludeJS: true,
excludeImages: true,
},
postcssOptions,
},
treeForStyles: function () {
// Only provide styles to the root application, not to engines
// This prevents engines from trying to compile ember-ui styles
let parent = this.parent;
while (parent) {
const isEngine = parent.lazyLoading === true || (parent.lazyLoading && parent.lazyLoading.enabled === true);
if (isEngine) {
// Parent is an engine - don't provide styles
return null;
}
parent = parent.parent;
}
// Parent is the root app - provide styles normally
return this._super.treeForStyles ? this._super.treeForStyles.apply(this, arguments) : null;
},
included: function (app) {
this._super.included.apply(this, arguments);
// Check if we're being included by an engine
// If so, skip setting postcssOptions to prevent engines from trying to compile our styles
let parent = this.parent;
while (parent) {
const isEngine = parent.lazyLoading === true || (parent.lazyLoading && parent.lazyLoading.enabled === true);
if (isEngine) {
// We're in an engine - don't set postcssOptions
// The engine will inherit from the host app
return;
}
parent = parent.parent;
}
// Get Application Host (skips engines, finds root app)
app = this.findApplicationHost(app);
// PostCSS Options - only applied to the root application
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, {
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 {
// Skip engines - we want the root application, not an engine
const isEngine = current.lazyLoading === true || (current.lazyLoading && current.lazyLoading.enabled === true);
if (!isEngine) {
app = current.app || app;
}
} while (current.parent.parent && (current = current.parent));
return app;
},
isDevelopingAddon: function () {
return true;
},
};