forked from acoustep/ember-cli-foundation-6-sass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (72 loc) · 3.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
/* jshint node: true */
'use strict';
var path = require('path');
var fs = require('fs');
var babel = require('babel-core');
var VersionChecker = require('ember-cli-version-checker');
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
module.exports = {
name: 'ember-cli-foundation-6-sass',
included: function included(app) {
this._super.included(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);
// Include the js paths
if ( !process.env.EMBER_CLI_FASTBOOT ) {
if (options && options.foundationJs) {
if ((typeof options.foundationJs === 'string') ||
(options.foundationJs instanceof String)) {
if (options.foundationJs === 'all') {
// >=6.3.0 changed some paths.
if (isGTE6_3_0) {
app.import(path.join(foundationPath, 'dist', 'js', 'foundation.js'));
} else {
app.import(path.join(foundationPath, 'foundation-sites', 'js', 'foundation.js'));
}
}
}
else if (options.foundationJs instanceof Array) {
options.foundationJs.forEach(function(componentName) {
var foundationJsPath = path.join(foundationPath, 'js');
var es5code = babel.transformFileSync(path.join(foundationJsPath, 'foundation.' + componentName + '.js'), {
'plugins': [
require.resolve('babel-plugin-transform-es2015-arrow-functions'),
require.resolve('babel-plugin-transform-es2015-block-scoped-functions'),
require.resolve('babel-plugin-transform-es2015-block-scoping'),
require.resolve('babel-plugin-transform-es2015-classes'),
require.resolve('babel-plugin-transform-es2015-destructuring'),
require.resolve('babel-plugin-transform-es2015-modules-commonjs'),
require.resolve('babel-plugin-transform-es2015-parameters'),
require.resolve('babel-plugin-transform-es2015-shorthand-properties'),
require.resolve('babel-plugin-transform-es2015-spread'),
require.resolve('babel-plugin-transform-es2015-template-literals')
]
}).code;
var filenameAndPath = path.join(foundationJsPath, 'foundation.' + componentName + '.es5.js');
fs.writeFileSync(filenameAndPath, es5code);
app.import(filenameAndPath);
});
}
}
}
}
};