From 7d318978de3a29f0e06bff1f1fc0b1ba7788b816 Mon Sep 17 00:00:00 2001 From: Krati Ahuja Date: Tue, 8 Nov 2016 18:36:29 -0800 Subject: [PATCH 1/2] [WIP]: Refactor fastboot build per ember-cli changes (only run build once) --- index.js | 28 +++++++++++++--------------- lib/utilities/fastboot-app-module.js | 1 + 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index ffc34711c..72cb04dcb 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ 'use strict'; var path = require('path'); +var fs = require('fs'); var EventEmitter = require('events').EventEmitter; var mergeTrees = require('broccoli-merge-trees'); @@ -55,12 +56,6 @@ module.exports = { patchEmberApp(app); }, - config: function() { - if (this.app && this.app.options.__is_building_fastboot__) { - return { APP: { autoboot: false } }; - } - }, - /** * Inserts placeholders into index.html that are used by the FastBoot server * to insert the rendered content into the right spot. Also injects a module @@ -79,15 +74,18 @@ module.exports = { return fastbootAppModule(config.modulePrefix); } - if (type === 'config-module' && this.app.options.__is_building_fastboot__) { - var linesToRemove = contents.length; - while(linesToRemove) { - // Clear out the default config from ember-cli - contents.pop(); - linesToRemove--; - } - - return 'return FastBoot.config();'; + // if the fastboot addon is installed, we overwrite the config-module so that the config can be read + // from meta tag for browser build and from Fastboot config for fastboot target + if (type === 'config-module') { + var emberCliPath = path.join(this.app.project.nodeModulesPath, 'ember-cli'); + contents.splice(0, contents.length); + contents.push('if (typeof FastBoot !== \'undefined\') {'); + contents.push('return FastBoot.config();'); + contents.push('} else {'); + contents.push('var prefix = \'' + config.modulePrefix + '\';'); + contents.push(fs.readFileSync(path.join(emberCliPath, 'lib/broccoli/app-config-from-meta.js'))); + contents.push('}'); + return; } }, diff --git a/lib/utilities/fastboot-app-module.js b/lib/utilities/fastboot-app-module.js index a707382cc..a3535c191 100644 --- a/lib/utilities/fastboot-app-module.js +++ b/lib/utilities/fastboot-app-module.js @@ -11,6 +11,7 @@ function fastbootAppModule(prefix) { "define('~fastboot/app-factory', ['{{MODULE_PREFIX}}/app', '{{MODULE_PREFIX}}/config/environment'], function(App, config) {", " App = App['default'];", " config = config['default'];", + " config.APP['autoboot'] = false;", "", " return {", " 'default': function() {", From 2bef4aa9adfcdd09d4c1ef75ceabc8374412cc97 Mon Sep 17 00:00:00 2001 From: Krati Ahuja Date: Thu, 10 Nov 2016 11:15:08 -0800 Subject: [PATCH 2/2] [WIP]: Prepare for Fastboot 1.0 in ember-cli-fastboot This PR primarily addresses the following issues: 1. Double fastboot builds [issue](https://github.com/ember-fastboot/ember-cli-fastboot/issues/264). Corresponding ember-cli changes are in this [PR](https://github.com/ember-cli/ember-cli/pull/6395) 2. Removes the monkey patching introduced with fastboot build. Related [issue](https://github.com/ember-fastboot/ember-cli-fastboot/issues/276) 3. Updates generated package.json to take in an array of app files (containing app.js and app-fastboot.js). Addresses this [issue](https://github.com/ember-fastboot/ember-cli-fastboot/issues/270) Once the ember-cli [PR](https://github.com/ember-cli/ember-cli/pull/6395) and this [issue](https://github.com/ember-fastboot/ember-cli-fastboot/issues/274) is fixed, we can kill the `ember fastboot` command itself. --- .../{browser => }/clear-double-boot.js | 20 ++- index.js | 155 ++++++++++++------ lib/broccoli/fastboot-build.js | 147 ----------------- lib/broccoli/fastboot-config.js | 49 ++++-- lib/commands/fastboot-build.js | 27 --- lib/commands/fastboot.js | 4 +- lib/ext/patch-ember-app.js | 40 ----- lib/tasks/fastboot-server.js | 1 + lib/utilities/fastboot-app-module.js | 11 +- package.json | 3 +- 10 files changed, 166 insertions(+), 291 deletions(-) rename app/instance-initializers/{browser => }/clear-double-boot.js (54%) delete mode 100644 lib/broccoli/fastboot-build.js delete mode 100644 lib/commands/fastboot-build.js delete mode 100644 lib/ext/patch-ember-app.js diff --git a/app/instance-initializers/browser/clear-double-boot.js b/app/instance-initializers/clear-double-boot.js similarity index 54% rename from app/instance-initializers/browser/clear-double-boot.js rename to app/instance-initializers/clear-double-boot.js index 2fa097dfa..5dd979e61 100644 --- a/app/instance-initializers/browser/clear-double-boot.js +++ b/app/instance-initializers/clear-double-boot.js @@ -13,16 +13,18 @@ export default { name: "clear-double-boot", initialize: function(instance) { - var originalDidCreateRootView = instance.didCreateRootView; + if (typeof FastBoot === 'undefined') { + var originalDidCreateRootView = instance.didCreateRootView; - instance.didCreateRootView = function() { - let elements = document.querySelectorAll(instance.rootElement + ' .ember-view'); - for (let i = 0; i < elements.length; i++) { - let element = elements[i]; - element.parentNode.removeChild(element); - } + instance.didCreateRootView = function() { + let elements = document.querySelectorAll(instance.rootElement + ' .ember-view'); + for (let i = 0; i < elements.length; i++) { + let element = elements[i]; + element.parentNode.removeChild(element); + } - originalDidCreateRootView.apply(instance, arguments); - }; + originalDidCreateRootView.apply(instance, arguments); + }; + } } } diff --git a/index.js b/index.js index 72cb04dcb..579f17fb1 100644 --- a/index.js +++ b/index.js @@ -2,58 +2,112 @@ 'use strict'; var path = require('path'); -var fs = require('fs'); +var fs = require('fs-extra'); +var existsSync = require('exists-sync'); var EventEmitter = require('events').EventEmitter; var mergeTrees = require('broccoli-merge-trees'); var VersionChecker = require('ember-cli-version-checker'); -var patchEmberApp = require('./lib/ext/patch-ember-app'); var fastbootAppModule = require('./lib/utilities/fastboot-app-module'); var filterInitializers = require('fastboot-filter-initializers'); -var FastBootBuild = require('./lib/broccoli/fastboot-build'); +var FastBootConfig = require('./lib/broccoli/fastboot-config'); + +var FASTBOOT_DIR = 'fastboot/app'; /* * Main entrypoint for the Ember CLI addon. */ - module.exports = { name: 'ember-cli-fastboot', - init() { - this._super.init && this._super.init.apply(this, arguments); - - this.emitter = new EventEmitter(); - }, - includedCommands: function() { return { 'fastboot': require('./lib/commands/fastboot')(this), - - /* fastboot:build is deprecated and will be removed in a future version */ - 'fastboot:build': require('./lib/commands/fastboot-build') }; }, + // TODO remove this after serve issues are fixed correctly + init() { + this._super.init && this._super.init.apply(this, arguments); + + this.emitter = new EventEmitter(); + }, + + // TODO remove this after serve issues are fixed correctly on: function() { this.emitter.on.apply(this.emitter, arguments); }, + // TODO remove this after serve issues are fixed correctly emit: function() { this.emitter.emit.apply(this.emitter, arguments); }, - /** - * Called at the start of the build process to let the addon know it will be - * used. At this point, we can rely on the EMBER_CLI_FASTBOOT environment - * variable being set. - * - * Once we've determined which mode we're in (browser build or FastBoot build), - * we mixin additional Ember addon hooks appropriate to the current build target. - */ + // TODO remove this after serve issues are fixed correctly + postBuild: function() { + this.emit('postBuild'); + }, + included: function(app) { - patchEmberApp(app); + // set autoRun to false since we will conditionally include creating app when app files + // is eval'd in app-boot + app.options.autoRun = false; + // move fastboot initializers out of app namespace + // TODO remove this before Fastboot 1.0 GAs + this.moveFastbootInitializers(); + }, + + // Function to move fastboot specific initializers and instance initializers from app/ to fastboot/app + // Should we move fastboot/[initializers-*]/browser too? It may need a code change of no-op the initializer in fastboot environment + // should we just throw a deprecation warning for fastboot/[initializers-*]/browser files instead? + moveFastbootInitializers: function() { + var deprecate = this.project.ui.writeDeprecateLine.bind(this.project.ui); + var nodeModulesPath = this.project.nodeModulesPath; + var fastbootInitializerTypes = [ 'initializers', 'instance-initializers']; + this.project.addons.forEach(function(addon) { + var currentAddonPath = path.join(nodeModulesPath, addon.name); + + // check to see if it is a fastboot complaint addon + var isFastbootAddon = fastbootInitializerTypes.some(function(fastbootInitializerType) { + var fastbootPath = path.join(currentAddonPath, 'app', fastbootInitializerType, 'fastboot'); + + return existsSync(fastbootPath); + }); + + if (isFastbootAddon) { + deprecate('Having fastboot specific code in app directory of ' + addon.name + ' is deprecated. Please move it to fastboot/app directory.'); + var fastbootDirPath = path.join(currentAddonPath, FASTBOOT_DIR); + // check if fastboot/app exists + if(!existsSync(fastbootDirPath)) { + fs.mkdirsSync(fastbootDirPath); + } + + // copy over app/initializers/fastboot and app/instance/initializers/fastboot + fastbootInitializerTypes.forEach(function(fastbootInitializerType) { + var srcFastbootPath = path.join(currentAddonPath, 'app', fastbootInitializerType, 'fastboot'); + + if (existsSync(srcFastbootPath)) { + var destFastbootPath = path.join(fastbootDirPath, fastbootInitializerType); + if (!existsSync(destFastbootPath)) { + fs.mkdirSync(destFastbootPath); + } + + // fastboot initializer type exists so we need to move this fastboot/app + var fastbootFiles = fs.readdirSync(srcFastbootPath); + fastbootFiles.forEach(function(fastbootFile) { + var srcPath = path.join(srcFastbootPath, fastbootFile); + var destPath = path.join(destFastbootPath, fastbootFile); + fs.copySync(srcPath, destPath); + + // delete the original path files so that there are no two initializers with the same name + fs.unlinkSync(srcPath); + }); + }; + }); + } + }); }, /** @@ -71,7 +125,7 @@ module.exports = { } if (type === 'app-boot') { - return fastbootAppModule(config.modulePrefix); + return fastbootAppModule(config.modulePrefix, JSON.stringify(config.APP || {})); } // if the fastboot addon is installed, we overwrite the config-module so that the config can be read @@ -89,53 +143,56 @@ module.exports = { } }, - treeForApp: function(defaultTree) { - var trees = [defaultTree]; + // todo replace this with tree for fastboot app + treeForFastbootApp: function(tree) { + var trees = []; + if (tree) { + trees = [tree]; + } if (this._getEmberVersion().lt('2.10.0-alpha.1')) { trees.push(this.treeGenerator(path.resolve(this.root, 'app-lt-2-9'))); } - return mergeTrees(trees, { overwrite: true }); - }, - - /** - * Filters out initializers and instance initializers that should only run in - * browser mode. - */ - preconcatTree: function(tree) { - return filterInitializers(tree, this.app.name); + return mergeTrees(trees.filter(Boolean), { overwrite: true }); }, /** * After the entire Broccoli tree has been built for the `dist` directory, - * adds the `fastboot-config.json` file to the root. + * adds the `package.json` file to the root. */ postprocessTree: function(type, tree) { if (type === 'all') { - var fastbootTree = this.buildFastBootTree(); + var fastbootConfigTree = this.buildFastbootConfigTree(tree); // Merge the package.json with the existing tree - return mergeTrees([tree, fastbootTree], {overwrite: true}); + return mergeTrees([tree, fastbootConfigTree], {overwrite: true}); } return tree; }, - buildFastBootTree: function() { - var fastbootBuild = new FastBootBuild({ - ui: this.ui, + buildFastbootConfigTree : function(tree) { + var env = this.app.env; + var config = this.project.config(env); + var fastbootConfig = config.fastboot; + if (config.hasOwnProperty('APP')) { + config['APP']['autoboot'] = false; + } else { + config['APP'] = { + 'autoboot': false + }; + } + + return new FastBootConfig(tree, { assetMapPath: this.assetMapPath, project: this.project, - app: this.app, - parent: this.parent + name: this.app.name, + outputPaths: this.app.options.outputPaths, + ui: this.ui, + fastbootAppConfig: fastbootConfig, + appConfig: config }); - - return fastbootBuild.toTree(); - }, - - postBuild: function() { - this.emit('postBuild'); }, _getEmberVersion: function() { @@ -148,6 +205,6 @@ module.exports = { } return checker.for('ember-source', 'npm'); - }, + } }; diff --git a/lib/broccoli/fastboot-build.js b/lib/broccoli/fastboot-build.js deleted file mode 100644 index 15385cc65..000000000 --- a/lib/broccoli/fastboot-build.js +++ /dev/null @@ -1,147 +0,0 @@ -var Funnel = require('broccoli-funnel'); -var Plugin = require('broccoli-plugin'); -var defaults = require('lodash.defaults'); - -// The EmptyTree just returns a broccoli tree with no files -// into it so broccoli doesn't try to read a tree from -// undefined. -EmptyTree.prototype = Object.create(Plugin.prototype); -EmptyTree.prototype.constructor = EmptyTree; -function EmptyTree(inputNodes, options) { - options = options || {}; - this.persistentOutput = options.persistentOutput = true; - Plugin.call(this, inputNodes, options); - this.options = options; -} - -EmptyTree.prototype.build = function() { }; - -function FastBootBuild(options) { - this.project = options.project; - var defaultAssetMapPath = 'assets/assetMap.json'; - var assetRev = this.project.addons.filter(function(addon) { - return addon.name === 'broccoli-asset-rev'; - })[0]; - - if (assetRev && assetRev.options) { - this.assetMapEnabled = !!(assetRev.options.enabled && assetRev.options.assetMapPath); - - if (assetRev.options.assetMapPath) { - this.assetMapPath = assetRev.options.assetMapPath; - } - - if (assetRev.options.fingerprintAssetMap) { - defaultAssetMapPath = 'assets/assetMap-*.json' - } - } - - this.assetMapPath = this.assetMapPath || options.assetMapPath || defaultAssetMapPath; - this.ui = options.ui; - this.options = options; - this.app = options.app; - this.name = this.app.name; - this.parent = options.parent; -} - -/** - * Creates a new EmberApp instance (from Ember CLI) and configures it to build - * for FastBoot. This tree for the FastBoot build is returned and later merged - * with the initial browser build. - */ -FastBootBuild.prototype.toTree = function() { - var env = process.env; - - // This method will be called again when we create the new EmberApp below. - // This is to prevent infinite recursion. - if (this.app.options.__is_building_fastboot__) { - return new EmptyTree([]); - } - - // Set the EMBER_CLI_FASTBOOT environment variable. This serves as a hint - // for other addons that they should build their trees configured for the - // FastBoot build. - // - // In the future, ideally we can remove this environment variable and there - // would be a more explicit way to tell addons what the build target is. - env.EMBER_CLI_FASTBOOT = true; - - var options = this.appOptions(); - - // re-require with env.EMBER_CLI_FASTBOOT on - var path = require('path'); - var emberBuildFile = path.join(this.project.root, 'ember-cli-build.js'); - var emberApp = require(emberBuildFile)(options); - - // Because this will be merged with the browser build, move the FastBoot - // build's assets to the fastboot directory. - // - var stew = require('broccoli-stew'); - - var fastbootTree = new Funnel(emberApp, { - srcDir: '/', - include: ['assets/**/*.js', '**/*.json'] - }); - - fastbootTree = stew.mv(fastbootTree, this.assetMapPath, '/fastbootAssetMap.json'); - fastbootTree = stew.mv(fastbootTree, 'assets/*.*', 'fastboot/'); - - delete env.EMBER_CLI_FASTBOOT; - - var configTree = this.buildConfigTree(fastbootTree); - var merge = require('broccoli-merge-trees'); - - return merge([fastbootTree, configTree], {overwrite: true}); -}; - -/** - * Builds the options passed to the EmberApp constructor. Most importantly, it - * disables the autorun and overrides the project to provide a config that is - * FastBoot compatible. - */ -FastBootBuild.prototype.appOptions = function() { - return defaults({ - autoRun: false, - fingerprint: { - generateAssetMap: true - }, - project: this.buildFastBootProject(), - __is_building_fastboot__: true, - }); -}; - -FastBootBuild.prototype.buildConfigTree = function(tree) { - var FastBootConfig = require('./fastboot-config'); - var env = this.app.env; - var config = this.project.config(env); - var fastbootConfig = config.fastboot; - - // Create a new Broccoli tree that writes the FastBoot app's - // `package.json`. - return new FastBootConfig(tree, { - project: this.project, - name: this.app.name, - assetMapEnabled: this.assetMapEnabled, - outputPaths: this.app.options.outputPaths, - ui: this.ui, - fastbootAppConfig: fastbootConfig, - appConfig: config - }); -}; - -/** - * Because the config information is not read until build time, the - * EMBER_CLI_FASTBOOT environment variable is not set when the FastBoot - * build actually happens. - * - * To get around this, we give the FastBoot tree a reference to a project - * that is modified to always return a FastBoot-compatible config. - */ -FastBootBuild.prototype.buildFastBootProject = function() { - var Project = require('ember-cli/lib/models/project'); - var oldProject = this.project; - var project = new Project(oldProject.root, oldProject.pkg, oldProject.ui, oldProject.cli); - - return this.project = project; -}; - -module.exports = FastBootBuild; diff --git a/lib/broccoli/fastboot-config.js b/lib/broccoli/fastboot-config.js index 3555edd75..0cb36bc6c 100644 --- a/lib/broccoli/fastboot-config.js +++ b/lib/broccoli/fastboot-config.js @@ -10,6 +10,29 @@ function FastBootConfig(inputNode, options) { annotation: "Generate: FastBoot package.json" }); + this.project = options.project; + // what if app does not set generateAssetMap option? + var defaultAssetMapPath = 'assets/assetMap.json'; + var assetRev = this.project.addons.filter(function(addon) { + // what happens when broccoli-asset-rev is not included explicitly? ember-cli does not assume + // consuming app will have this. + return addon.name === 'broccoli-asset-rev'; + })[0]; + + if (assetRev && assetRev.options) { + this.assetMapEnabled = !!(assetRev.options.enabled && assetRev.options.generateAssetMap); + + if (assetRev.options.assetMapPath) { + this.assetMapPath = assetRev.options.assetMapPath; + } + + if (assetRev.options.fingerprintAssetMap) { + defaultAssetMapPath = 'assets/assetMap-*.json' + } + } + + this.assetMapPath = this.assetMapPath || options.assetMapPath || defaultAssetMapPath; + this.project = options.project; this.name = options.name; this.ui = options.ui; @@ -99,7 +122,7 @@ FastBootConfig.prototype.buildDependencies = function() { FastBootConfig.prototype.readAssetManifest = function() { var ui = this.ui; - var assetMapPath = path.join(this.inputPaths[0], 'fastbootAssetMap.json'); + var assetMapPath = path.join(this.inputPaths[0], this.assetMapPath); var assetMapEnabled = this.assetMapEnabled; try { @@ -113,13 +136,12 @@ FastBootConfig.prototype.readAssetManifest = function() { }; FastBootConfig.prototype.buildManifest = function() { - var appFileName = path.basename(this.outputPaths.app.js).split('.')[0]; - var appFile = 'fastboot/' + appFileName + '.js'; - var vendorFileName = path.basename(this.outputPaths.vendor.js).split('.')[0]; - var vendorFile = 'fastboot/' + vendorFileName + '.js'; + var appFile = this.outputPaths.app.js.split('/').splice(1).join('/'); + var appFastbootFile = this.outputPaths.fastboot.app.split('/').splice(1).join('/'); + var vendorFile = this.outputPaths.vendor.js.split('/').splice(1).join('/'); var manifest = { - appFile: appFile, + appFiles: [appFile, appFastbootFile], vendorFile: vendorFile, htmlFile: this.htmlFile }; @@ -129,18 +151,17 @@ FastBootConfig.prototype.buildManifest = function() { if (rewrittenAssets) { var assets = {}; - // Because the assetMap was written before the files in the - // `asset` folder were moved to the `fastboot` folder, - // we have to rewrite them here. for (var key in rewrittenAssets.assets) { - var rewrittenKey = assetToFastboot(key); - assets[rewrittenKey] = assetToFastboot(rewrittenAssets.assets[key]); + assets[key] = rewrittenAssets.assets[key]; } - ['appFile', 'vendorFile'].forEach(function(file) { - // Update package.json with the fingerprinted file. - manifest[file] = assets[manifest[file]]; + var rewrittenAppFiles = []; + manifest['appFiles'].forEach(function(file) { + rewrittenAppFiles.push(assets[file]); }); + + manifest['appFiles'] = rewrittenAppFiles; + manifest['vendorFile'] = assets[manifest['vendorFile']]; } this.manifest = manifest; diff --git a/lib/commands/fastboot-build.js b/lib/commands/fastboot-build.js deleted file mode 100644 index 033e0e742..000000000 --- a/lib/commands/fastboot-build.js +++ /dev/null @@ -1,27 +0,0 @@ -var path = require('path'); -var fs = require('fs'); - -module.exports = { - name: 'fastboot:build', - description: 'Build your assets for FastBoot.', - - availableOptions: [ - { name: 'environment', type: String, default: 'development', aliases: ['e',{'dev' : 'development'}, {'prod' : 'production'}] }, - { name: 'output-path', type: String, default: 'fastboot-dist' } - ], - - run: function(options) { - var deprecate = this.project.ui.writeDeprecateLine.bind(this.project.ui); - var BuildTask = this.tasks.Build; - - var buildTask = new BuildTask({ - ui: this.ui, - analytics: this.analytics, - project: this.project - }); - - deprecate("Use of ember fastboot:build is deprecated. Please use ember build instead."); - - return buildTask.run(options); - }, -}; diff --git a/lib/commands/fastboot.js b/lib/commands/fastboot.js index 13bb313b5..9ddcc709d 100644 --- a/lib/commands/fastboot.js +++ b/lib/commands/fastboot.js @@ -8,6 +8,8 @@ const SilentError = require('silent-error'); const blockForever = () => (new RSVP.Promise(() => {})); const noop = function() { }; +// TODO: kill this command once https://github.com/ember-cli/ember-cli/pull/6395 lands and +// https://github.com/ember-fastboot/ember-cli-fastboot/issues/274 is fixed module.exports = function(addon) { return { name: 'fastboot', @@ -18,7 +20,7 @@ module.exports = function(addon) { { name: 'watch', type: Boolean, default: true, aliases: ['w'] }, { name: 'environment', type: String, default: 'development', aliases: ['e',{'dev' : 'development'}, {'prod' : 'production'}] }, { name: 'serve-assets', type: Boolean, default: false }, - { name: 'host', type: String, default: '::' }, + { name: 'host', type: String, default: 'localhost' }, { name: 'port', type: Number, default: 3000 }, { name: 'output-path', type: String, default: 'dist' }, { name: 'assets-path', type: String, default: 'dist' } diff --git a/lib/ext/patch-ember-app.js b/lib/ext/patch-ember-app.js deleted file mode 100644 index 1ea22049f..000000000 --- a/lib/ext/patch-ember-app.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Monkeypatches the EmberApp instance from Ember CLI to contain the hooks we - * need to filter environment-specific initializers. Hopefully we can upstream - * similar hooks to Ember CLI and eventually remove these patches. - */ -function patchEmberApp(emberApp) { - // App was already patched - if (emberApp.addonPreconcatTree) { return; } - - // Save off original implementation of the `concatFiles` hook - var originalConcatFiles = emberApp.concatFiles; - - // Install method to invoke `preconcatTree` hook on each addon - emberApp.addonPreconcatTree = addonPreconcatTree; - - // Install patched `concatFiles` method. This checks options passed to it - // and, if it detects that it's a concat for the app tree, invokes our - // preconcat hook. Afterwards, we invoke the original implementation to - // return a tree concating the files. - emberApp.concatFiles = function(tree, options) { - if (options.annotation === 'Concat: App') { - tree = this.addonPreconcatTree(tree); - } - return originalConcatFiles.apply(this, arguments); - }; -} - -function addonPreconcatTree(tree) { - var workingTree = tree; - - this.project.addons.forEach(function(addon) { - if (addon.preconcatTree) { - workingTree = addon.preconcatTree(workingTree); - } - }); - - return workingTree; -} - -module.exports = patchEmberApp; diff --git a/lib/tasks/fastboot-server.js b/lib/tasks/fastboot-server.js index 6f44ce132..395bdbaf1 100644 --- a/lib/tasks/fastboot-server.js +++ b/lib/tasks/fastboot-server.js @@ -8,6 +8,7 @@ const http = require('http'); const path = require('path'); const parseStackTrace = require('../utilities/parse-stack-trace'); +// TODO delete this task once module.exports = CoreObject.extend({ exec, diff --git a/lib/utilities/fastboot-app-module.js b/lib/utilities/fastboot-app-module.js index a3535c191..a09bfaf48 100644 --- a/lib/utilities/fastboot-app-module.js +++ b/lib/utilities/fastboot-app-module.js @@ -5,13 +5,18 @@ // The module defined here is prefixed with a `~` to make it less // likely to collide with user code, since it is not possible to // define a module with a name like this in the file system. -function fastbootAppModule(prefix) { +function fastbootAppModule(prefix, configAppAsString) { return [ + "", + "if (typeof FastBoot === 'undefined') {", + " if (!runningTests) {", + " require('{{MODULE_PREFIX}}/app')['default'].create({{CONFIG_APP}});", + " }", + "}", "", "define('~fastboot/app-factory', ['{{MODULE_PREFIX}}/app', '{{MODULE_PREFIX}}/config/environment'], function(App, config) {", " App = App['default'];", " config = config['default'];", - " config.APP['autoboot'] = false;", "", " return {", " 'default': function() {", @@ -20,7 +25,7 @@ function fastbootAppModule(prefix) { " };", "});", "" - ].join("\n").replace(/\{\{MODULE_PREFIX\}\}/g, prefix); + ].join("\n").replace(/\{\{MODULE_PREFIX\}\}/g, prefix).replace(/\{\{CONFIG_APP\}\}/g, configAppAsString); } module.exports = fastbootAppModule; diff --git a/package.json b/package.json index 35522417d..77379ca2e 100644 --- a/package.json +++ b/package.json @@ -42,11 +42,12 @@ "ember-load-initializers": "^0.5.1", "ember-resolver": "^2.0.3", "exists-sync": "0.0.3", - "fs-extra": "^0.24.0", + "fs-extra": "^1.0.0", "fs-promise": "^0.3.1", "glob": "^7.0.0", "loader.js": "^4.0.1", "mocha": "^2.2.4", + "mkdirp": "0.5.1", "request": "^2.55.0", "sinon": "^1.17.4", "symlink-or-copy": "^1.0.1",