Skip to content
This repository has been archived by the owner on Nov 4, 2019. It is now read-only.

Adds Ember CLI Fastboot 1.0.0 compatibility #2

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,69 @@
const path = require('path');
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');

function isFastboot() {
return process.env.EMBER_CLI_FASTBOOT === 'true';
}
const map = require('broccoli-stew').map;

module.exports = {
name: 'ember-medium-editor',

included(parent) {
this._super.included.apply(this, arguments);

// exit from hook in the fastboot mode
if (isFastboot()) { return; }

let options = this.getConfig(parent);
included(app) {
if (typeof app.import !== 'function' && app.app) {
app = app.app;
}
this.app = app;
this.addonConfig = this.getConfig();

// Setup paths
let vendorPath = this.treePaths.vendor;
let jsPath = path.join(vendorPath, 'medium-editor', 'js');
let stylesPath = path.join(vendorPath, 'medium-editor', 'css');

// import js
// Import js
this.import({
development: path.join(jsPath, 'medium-editor.js'),
production: path.join(jsPath, 'medium-editor.min.js')
});
this.import(path.join(vendorPath, 'shims', 'medium-editor.js'));

// import styles
if (!options.excludeStyles) {
// Import styles
if (!this.addonConfig.excludeStyles) {
let theme = this.addonConfig.theme;
this.import({
development: path.join(stylesPath, 'medium-editor.css'),
production: path.join(stylesPath, 'medium-editor.min.css')
});
this.import({
development: path.join(stylesPath, 'themes', `${options.theme}.css`),
production: path.join(stylesPath, 'themes', `${options.theme}.min.css`)
development: path.join(stylesPath, 'themes', `${theme}.css`),
production: path.join(stylesPath, 'themes', `${theme}.min.css`)
});
}

return this._super.included.apply(this, arguments);
},

treeForVendor(vendorTree) {
// do not include assets in the fastboot mode
if (isFastboot()) { return vendorTree; }
let moduleName = 'medium-editor';
let modulePath = path.join(require.resolve(moduleName), '..', '..');

let distPath = path.join(require.resolve('medium-editor'), '..', '..');
let meTree = new Funnel(distPath, {
include: ['**/*'],
destDir: 'medium-editor'
let jsTree = new Funnel(modulePath, {
include: ['js/**/*'],
destDir: moduleName
});

return mergeTrees([vendorTree, meTree]);
jsTree = map(jsTree, (content) => `if (typeof FastBoot === 'undefined') { ${content} }`);

let cssTree = new Funnel(modulePath, {
include: ['css/**/*'],
destDir: moduleName
});

return mergeTrees([vendorTree, jsTree, cssTree]);
},

getConfig(parent) {
let defaultConfig = {
getConfig() {
return Object.assign({
excludeStyles: false,
theme: 'default'
};

return Object.assign(defaultConfig, parent.options.mediumEditor);
}, this.app.options.mediumEditor);
}
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"broccoli-funnel": "^1.1.0",
"broccoli-merge-trees": "^2.0.0",
"broccoli-stew": "^1.5.0",
"ember-cli-babel": "^6.0.0-beta.3",
"medium-editor": "^5.23.0"
},
Expand All @@ -35,6 +36,7 @@
"ember-cli": "~2.13.0-beta.2",
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-eslint": "^3.0.0",
"ember-cli-fastboot": "1.0.0-rc.2",
"ember-cli-htmlbars": "^1.1.1",
"ember-cli-htmlbars-inline-precompile": "^0.4.0-beta.2",
"ember-cli-inject-live-reload": "^1.4.1",
Expand Down
Loading