Skip to content

Commit

Permalink
Added support for embroider build and current build (#702)
Browse files Browse the repository at this point in the history
Added support for embroider build and current build
  • Loading branch information
rwjblue committed Jun 14, 2019
2 parents dff28c1 + c468059 commit 88fab39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 252 deletions.
25 changes: 15 additions & 10 deletions index.js
Expand Up @@ -29,7 +29,9 @@ function getVersionChecker(context) {
return checker;
}


function stripLeadingSlash(filePath) {
return filePath.replace(/^\//, '');
}

/*
* Main entrypoint for the Ember CLI addon.
Expand Down Expand Up @@ -106,11 +108,6 @@ module.exports = {
return "<!-- EMBER_CLI_FASTBOOT_TITLE --><!-- EMBER_CLI_FASTBOOT_HEAD -->";
}

if (type === 'app-boot') {
const isModuleUnification = (typeof this.project.isModuleUnification === 'function') && this.project.isModuleUnification();
return fastbootAppModule(config.modulePrefix, JSON.stringify(config.APP || {}), isModuleUnification);
}

// if the fastboot addon is installed, we overwrite the config-module so that the config can be read
// from meta tag/directly for browser build and from Fastboot config for fastboot target.
if (type === 'config-module') {
Expand Down Expand Up @@ -196,10 +193,6 @@ module.exports = {
registry: this._appRegistry
});

function stripLeadingSlash(filePath) {
return filePath.replace(/^\//, '');
}

let appFilePath = stripLeadingSlash(this.app.options.outputPaths.app.js);
let finalFastbootTree = new Concat(processExtraTree, {
outputFile: appFilePath.replace(/\.js$/, '-fastboot.js')
Expand Down Expand Up @@ -334,6 +327,8 @@ module.exports = {
},

postBuild(result) {
let appFilePath = stripLeadingSlash(this.app.options.outputPaths.app.js);
this._appendAppBoot(result.directory, appFilePath);
if (this.fastboot) {
// should we reload fastboot if there are only css changes? Seems it maynot be needed.
// TODO(future): we can do a smarter reload here by running fs-tree-diff on files loaded
Expand Down Expand Up @@ -361,4 +356,14 @@ module.exports = {

return checker.for('ember', 'bower');
},

_appendAppBoot(appDir, appFilePath) {
let env = this.app.env;
let config = this.project.config(env);
const isModuleUnification = (typeof this.project.isModuleUnification === 'function') && this.project.isModuleUnification();
const appBoot = fastbootAppModule(config.modulePrefix, JSON.stringify(config.APP || {}), isModuleUnification);

appFilePath = path.resolve(appDir, appFilePath);
fs.appendFileSync(appFilePath, appBoot);
}
};
2 changes: 1 addition & 1 deletion lib/utilities/fastboot-app-module.js
Expand Up @@ -12,7 +12,7 @@ module.exports = function fastbootAppModule(prefix, configAppAsString, isModuleU
return [
"",
"if (typeof FastBoot === 'undefined') {",
" if (!runningTests) {",
" if (typeof runningTests === 'undefined') {",
" require('{{MODULE_PREFIX}}/" + appSuffix + "')['default'].create({{CONFIG_APP}});",
" }",
"}",
Expand Down

0 comments on commit 88fab39

Please sign in to comment.