Skip to content
This repository has been archived by the owner on May 20, 2021. It is now read-only.

Commit

Permalink
Adds Fastboot 1.0.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jurecuhalev committed Jul 1, 2017
1 parent 88b5292 commit 08c0cd0
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 50 deletions.
130 changes: 81 additions & 49 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,106 @@
'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');
var fastbootTransform = require('fastboot-transform');
var esTranspiler = require('broccoli-babel-transpiler');


module.exports = {
name: 'ember-cli-foundation-6-sass',

jsFilesToInclude: [],

treeForVendor(vendorTree) {
let foundationTree;
let options = this.app.options['ember-cli-foundation-6-sass'];
let foundationPath;
let checker = new VersionChecker(this);
let isGTE6_3_0 = checker.for('foundation-sites', 'bower').satisfies('>=6.3.0');

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) {
foundationPath = path.join(this.app.bowerDirectory, 'foundation-sites', 'dist', 'js');
} else {
foundationPath = path.join(this.app.bowerDirectory, 'foundation-sites', 'js');
}
}
} else if (options.foundationJs instanceof Array) {
foundationPath = path.join(this.app.bowerDirectory, 'foundation-sites', 'js');
}
}

if ( this.jsFilesToInclude === ['foundation.js'] ) {
foundationTree = new Funnel(foundationPath, {
destDir: 'foundation-sites',
files: this.jsFilesToInclude
})
} else {
foundationTree = new Funnel(foundationPath, {
destDir: 'foundation-sites',
files: this.jsFilesToInclude
});

foundationTree = esTranspiler(foundationTree, {
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')
]
});
}

foundationTree = fastbootTransform(foundationTree);

return new mergeTrees([vendorTree, foundationTree]);
},

included: function included(app) {
this._super.included(app);
var options = app.options['ember-cli-foundation-6-sass'];

var foundationPath = path.join(app.bowerDirectory, 'foundation-sites');
var checker = new VersionChecker(this);
var isGTE6_3_0 = checker.for('foundation-sites', 'bower').satisfies('>=6.3.0');

app.options.sassOptions = app.options.sassOptions || {};
app.options.sassOptions.includePaths = app.options.sassOptions.includePaths || [];

// >=6.3.0 changed some paths.
if (isGTE6_3_0) {
foundationPath = mergeTrees([new Funnel(foundationPath, {
include: ['_vendor/**/*']
}), new Funnel(path.join(foundationPath, 'scss'), {
destDir: 'foundation-sites',
include: ['**/*']
})]);
}
foundationPath = mergeTrees([new Funnel(foundationPath, {
include: ['_vendor/**/*']
}), new Funnel(path.join(foundationPath, 'scss'), {
destDir: 'foundation-sites',
include: ['**/*']
})]);

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(app.bowerDirectory, 'foundation-sites', 'dist', 'js', 'foundation.js'));
} else {
app.import(path.join(app.bowerDirectory, 'foundation-sites', 'js', 'foundation.js'));
}
}
}
else if (options.foundationJs instanceof Array) {
options.foundationJs.forEach(function(componentName) {
var foundationJsPath = path.join(app.bowerDirectory, 'foundation-sites', '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);
});
if (options && options.foundationJs) {
if ((typeof options.foundationJs === 'string') ||
(options.foundationJs instanceof String)) {
if (options.foundationJs === 'all') {
this.jsFilesToInclude = ['foundation.js'];
app.import(path.join('vendor/foundation-sites', 'foundation.js'));
}
}
else if (options.foundationJs instanceof Array) {
options.foundationJs.forEach((componentName) => {
let filename = 'foundation.' + componentName + '.js';
this.jsFilesToInclude.push(filename);
app.import(path.join('vendor/foundation-sites', filename));
});
}
}
}

};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@
"babel-plugin-transform-es2015-spread": "^6.8.0",
"babel-plugin-transform-es2015-template-literals": "^6.8.0",
"babel-register": "^6.18.0",
"broccoli-babel-transpiler": "^6.1.1",
"broccoli-funnel": "^1.2.0",
"broccoli-merge-trees": "^2.0.0",
"ember-cli-babel": "^6.1.0",
"ember-cli-htmlbars": "^1.0.2",
"ember-cli-htmlbars-inline-precompile": "^0.4.2",
"ember-cli-sass": "^6.1.3",
"ember-cli-version-checker": "^1.3.1",
"ember-cli-htmlbars-inline-precompile": "^0.4.2"
"fastboot-transform": "^0.1.1"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down

0 comments on commit 08c0cd0

Please sign in to comment.