This repository has been archived by the owner on May 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.js
186 lines (158 loc) · 6.59 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
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
175
176
177
178
179
180
181
182
183
184
185
186
/* global require, module */
/* eslint-env node */
'use strict';
var path = require('path');
var VersionChecker = require('ember-cli-version-checker');
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var fastbootTransform = require('fastboot-transform');
var writeFile = require('broccoli-file-creator');
var Rollup = require('broccoli-rollup');
var nodeResolve = require('rollup-plugin-node-resolve');
var legacy = require('rollup-plugin-legacy');
module.exports = {
name: 'ember-cli-foundation-6-sass',
jsFilesToInclude: [],
treeForVendor(vendorTree) {
var foundationTree;
var babelAddon = this.addons.find(addon => addon.name === 'ember-cli-babel');
var options = this.app.options['ember-cli-foundation-6-sass'];
var checker = new VersionChecker(this);
var isGTE6_4_0 = checker.for('foundation-sites', 'npm').satisfies('>=6.4.0');
var foundationJSContent;
var addonPath;
if (options && options.foundationJs) {
if ((typeof options.foundationJs === 'string') ||
(options.foundationJs instanceof String)) {
if (options.foundationJs === 'all') {
addonPath = path.resolve(__dirname, 'addon');
foundationTree = new Rollup(addonPath, {
rollup: {
entry: '-private/foundation.js',
format: 'es',
dest: 'foundation-sites.js',
plugins: [
nodeResolve(),
legacy({
// 6.4
'node_modules/foundation-sites/js/entries/plugins/foundation.core.js': 'window.Foundation',
// 6.3.1
'node_modules/foundation-sites/dist/js/foundation.js': 'window.Foundation',
// 6.2.4
'node_modules/foundation-sites/dist/foundation.js': 'window.Foundation'
})
],
external: [
'jquery'
]
}
});
}
} else {
if (isGTE6_4_0) {
foundationJSContent = 'export { default } from \'foundation-sites/js/entries/plugins/foundation.core\';\n';
foundationJSContent += this.jsFilesToInclude.filter((file) => {
// Exclude foundation.core because it's imported by default;
return file !== 'foundation.core.js';
}).map(function(file) {
return 'import \'foundation-sites/js/entries/plugins/' + file.replace('.js', '') + '\';';
}).join('\n');
} else {
foundationJSContent = 'export { default } from \'foundation-sites/js/foundation.core\';\n';
foundationJSContent += this.jsFilesToInclude.filter((file) => {
// Exclude foundation.core because it's imported by default;
return file !== 'foundation.core.js';
}).map(function(file) {
return 'import \'foundation-sites/js/' + file.replace('.js', '') + '\';';
}).join('\n');
}
foundationTree = new Rollup(writeFile('foundation.js', foundationJSContent), {
rollup: {
entry: 'foundation.js',
format: 'es',
dest: 'foundation-sites.js',
plugins: [
nodeResolve(),
legacy({
// In 6.4, foundation-sites/js/entries/plugins/foundation.core doesn't export anything, so we need to use legacy to export some things.
'node_modules/foundation-sites/js/entries/plugins/foundation.core.js': {
Foundation: 'window.Foundation',
default: 'window.Foundation'
},
// 6.2.4 and 6.3.1
'node_modules/foundation-sites/js/foundation.core.js': 'window.Foundation'
})
],
external: [
'jquery'
]
}
});
}
foundationTree = babelAddon.transpileTree(foundationTree);
foundationTree = fastbootTransform(foundationTree);
return vendorTree ? new mergeTrees([vendorTree, foundationTree]) : foundationTree;
}
return vendorTree;
},
treeForPublic() {
var hasFastBoot = this.project.addons.some(addon => addon.name === 'ember-cli-fastboot');
var publicTree = this._super.treeForPublic.apply(this, arguments);
var trees = [];
if (publicTree && hasFastBoot) {
trees.push(publicTree);
}
return mergeTrees(trees);
},
updateFastBootManifest(manifest) {
manifest.vendorFiles.push('ember-cli-foundation-6-sass/fastboot-foundation.js');
return manifest;
},
included: function included(app) {
this._super.included(app);
this.app = app;
var options = app.options['ember-cli-foundation-6-sass'];
var checker = new VersionChecker(this);
var isGTE6_3_0 = checker.for('foundation-sites', 'npm').satisfies('>=6.3.0');
app.options.sassOptions = app.options.sassOptions || {};
app.options.sassOptions.includePaths = app.options.sassOptions.includePaths || [];
// Calculate the path using require.resolve which checks the whole path.
// This gives us a specific file in dist/js/npm.js hence the need to path.resolve our way back up.
var foundationPath = path.resolve(require.resolve('foundation-sites'), '../..');
// >=6.3.0 changed some paths.
if (isGTE6_3_0) {
foundationPath = path.resolve(require.resolve('foundation-sites'), '../../..'); // go deeper
var foundationFunnel = mergeTrees([new Funnel(foundationPath, {
include: ['_vendor/**/*']
}), new Funnel(path.join(foundationPath, 'scss'), {
destDir: 'foundation-sites',
include: ['**/*']
})]);
app.options.sassOptions.includePaths.push(foundationFunnel);
}
app.options.sassOptions.includePaths.push(foundationPath);
foundationPath = mergeTrees([new Funnel(foundationPath, {
include: ['_vendor/**/*']
}), new Funnel(path.join(foundationPath, 'scss'), {
destDir: 'foundation-sites',
include: ['**/*']
})]);
app.options.sassOptions.includePaths.push(foundationPath);
if (options && options.foundationJs) {
if ((typeof options.foundationJs === 'string') ||
(options.foundationJs instanceof String)) {
if (options.foundationJs === 'all') {
this.jsFilesToInclude = ['foundation.js'];
this.import('vendor/foundation-sites.js');
}
}
else if (options.foundationJs instanceof Array) {
options.foundationJs.forEach((componentName) => {
var filename = 'foundation.' + componentName + '.js';
this.jsFilesToInclude.push(filename);
});
this.import('vendor/foundation-sites.js');
}
}
}
};