@@ -11,7 +11,7 @@ const chalk = require('chalk');
1111
1212const fastbootAppBoot = require ( './lib/utilities/fastboot-app-boot' ) ;
1313const FastBootConfig = require ( './lib/broccoli/fastboot-config' ) ;
14- const HTMLWriter = require ( './lib/broccoli/html -writer' ) ;
14+ const BasePageWriter = require ( './lib/broccoli/base-page -writer' ) ;
1515const fastbootAppFactoryModule = require ( './lib/utilities/fastboot-app-factory-module' ) ;
1616const migrateInitializers = require ( './lib/build-utilities/migrate-initializers' ) ;
1717const SilentError = require ( 'silent-error' ) ;
@@ -61,7 +61,9 @@ module.exports = {
6161 * See: https://ember-cli.com/user-guide/#integration
6262 */
6363 included ( app ) {
64- let assetRev = this . project . addons . find ( addon => addon . name === 'broccoli-asset-rev' ) ;
64+ let assetRev = this . project . addons . find (
65+ ( addon ) => addon . name === 'broccoli-asset-rev'
66+ ) ;
6567 if ( assetRev && ! assetRev . supportsFastboot ) {
6668 throw new SilentError (
6769 'This version of ember-cli-fastboot requires a newer version of broccoli-asset-rev'
@@ -110,7 +112,10 @@ module.exports = {
110112 }
111113
112114 if ( type === 'app-boot' ) {
113- return fastbootAppBoot ( config . modulePrefix , JSON . stringify ( config . APP || { } ) ) ;
115+ return fastbootAppBoot (
116+ config . modulePrefix ,
117+ JSON . stringify ( config . APP || { } )
118+ ) ;
114119 }
115120
116121 // if the fastboot addon is installed, we overwrite the config-module so that the config can be read
@@ -135,15 +140,19 @@ module.exports = {
135140
136141 // check the ember version and conditionally patch the DOM api
137142 if ( this . _getEmberVersion ( ) . lt ( '2.10.0-alpha.1' ) ) {
138- fastbootHtmlBarsTree = this . treeGenerator ( path . resolve ( __dirname , 'fastboot-app-lt-2-9' ) ) ;
139- return tree ? new MergeTrees ( [ tree , fastbootHtmlBarsTree ] ) : fastbootHtmlBarsTree ;
143+ fastbootHtmlBarsTree = this . treeGenerator (
144+ path . resolve ( __dirname , 'fastboot-app-lt-2-9' )
145+ ) ;
146+ return tree
147+ ? new MergeTrees ( [ tree , fastbootHtmlBarsTree ] )
148+ : fastbootHtmlBarsTree ;
140149 }
141150
142151 return tree ;
143152 } ,
144153
145154 _processAddons ( addons , fastbootTrees ) {
146- addons . forEach ( addon => {
155+ addons . forEach ( ( addon ) => {
147156 this . _processAddon ( addon , fastbootTrees ) ;
148157 } ) ;
149158 } ,
@@ -183,7 +192,10 @@ module.exports = {
183192 // check the parent containing the fastboot directory
184193 const projectFastbootPath = path . join ( this . project . root , 'fastboot' ) ;
185194 // ignore the project's fastboot folder if we are an addon, as that is already handled above
186- if ( ! this . project . isEmberCLIAddon ( ) && this . existsSync ( projectFastbootPath ) ) {
195+ if (
196+ ! this . project . isEmberCLIAddon ( ) &&
197+ this . existsSync ( projectFastbootPath )
198+ ) {
187199 let fastbootTree = this . treeGenerator ( projectFastbootPath ) ;
188200 fastbootTrees . push ( fastbootTree ) ;
189201 }
@@ -196,17 +208,28 @@ module.exports = {
196208 let funneledFastbootTrees = new Funnel ( mergedFastBootTree , {
197209 destDir : appName ,
198210 } ) ;
199- const processExtraTree = p . preprocessJs ( funneledFastbootTrees , '/' , this . _name , {
200- registry : this . _appRegistry ,
201- } ) ;
211+ const processExtraTree = p . preprocessJs (
212+ funneledFastbootTrees ,
213+ '/' ,
214+ this . _name ,
215+ {
216+ registry : this . _appRegistry ,
217+ }
218+ ) ;
202219
203220 // FastBoot app factory module
204221 const writeFile = require ( 'broccoli-file-creator' ) ;
205- let appFactoryModuleTree = writeFile ( 'app-factory.js' , fastbootAppFactoryModule ( appName ) ) ;
206-
207- let newProcessExtraTree = new MergeTrees ( [ processExtraTree , appFactoryModuleTree ] , {
208- overwrite : true ,
209- } ) ;
222+ let appFactoryModuleTree = writeFile (
223+ 'app-factory.js' ,
224+ fastbootAppFactoryModule ( appName )
225+ ) ;
226+
227+ let newProcessExtraTree = new MergeTrees (
228+ [ processExtraTree , appFactoryModuleTree ] ,
229+ {
230+ overwrite : true ,
231+ }
232+ ) ;
210233
211234 function stripLeadingSlash ( filePath ) {
212235 return filePath . replace ( / ^ \/ / , '' ) ;
@@ -231,7 +254,8 @@ module.exports = {
231254
232255 let newTree = new MergeTrees ( trees ) ;
233256
234- let fastbootConfigTree = ( this . _fastbootConfigTree = this . _buildFastbootConfigTree ( newTree ) ) ;
257+ let fastbootConfigTree = ( this . _fastbootConfigTree =
258+ this . _buildFastbootConfigTree ( newTree ) ) ;
235259
236260 // Merge the package.json with the existing tree
237261 return new MergeTrees ( [ newTree , fastbootConfigTree ] , { overwrite : true } ) ;
@@ -296,15 +320,23 @@ module.exports = {
296320
297321 _buildFastbootConfigTree ( tree ) {
298322 let appConfig = this . _getHostAppConfig ( ) ;
299- let fastbootAppConfig = appConfig . fastboot ;
300323
301324 return new FastBootConfig ( tree , {
302325 project : this . project ,
303- name : this . app . name ,
304326 outputPaths : this . app . options . outputPaths ,
305327 ui : this . ui ,
306- fastbootAppConfig : fastbootAppConfig ,
307- appConfig : appConfig ,
328+ appConfig,
329+ } ) ;
330+ } ,
331+
332+ _buildHTMLWriter ( tree ) {
333+ let appConfig = this . _getHostAppConfig ( ) ;
334+
335+ return new BasePageWriter ( tree , {
336+ project : this . project ,
337+ appConfig,
338+ appJsPath : this . app . options . outputPaths . app . js ,
339+ outputPaths : this . app . options . outputPaths ,
308340 } ) ;
309341 } ,
310342
@@ -314,15 +346,7 @@ module.exports = {
314346 postprocessTree ( type , tree ) {
315347 this . _super ( ...arguments ) ;
316348 if ( type === 'all' ) {
317- let { fastbootConfig, appName, manifest } = this . _fastbootConfigTree ;
318- let fastbootHTMLTree = new HTMLWriter ( tree , {
319- annotation : 'FastBoot HTML Writer' ,
320- fastbootConfig,
321- appName,
322- manifest,
323- appJsPath : this . app . options . outputPaths . app . js ,
324- outputPaths : this . app . options . outputPaths ,
325- } ) ;
349+ let fastbootHTMLTree = this . _buildHTMLWriter ( tree ) ;
326350
327351 // Merge the package.json with the existing tree
328352 return new MergeTrees ( [ tree , fastbootHTMLTree ] , { overwrite : true } ) ;
@@ -341,8 +365,11 @@ module.exports = {
341365
342366 app . use ( ( req , resp , next ) => {
343367 const fastbootQueryParam =
344- req . query . hasOwnProperty ( 'fastboot' ) && req . query . fastboot === 'false' ? false : true ;
345- const enableFastBootServe = ! process . env . FASTBOOT_DISABLED && fastbootQueryParam ;
368+ req . query . hasOwnProperty ( 'fastboot' ) && req . query . fastboot === 'false'
369+ ? false
370+ : true ;
371+ const enableFastBootServe =
372+ ! process . env . FASTBOOT_DISABLED && fastbootQueryParam ;
346373
347374 if ( req . serveUrl && enableFastBootServe ) {
348375 // if it is a base page request, then have fastboot serve the base page
@@ -409,7 +436,10 @@ module.exports = {
409436 * TODO Allow add-ons to provide own options and merge them with the application's options.
410437 */
411438 _fastbootOptionsFor ( environment , project ) {
412- const configPath = path . join ( path . dirname ( project . configPath ( ) ) , 'fastboot.js' ) ;
439+ const configPath = path . join (
440+ path . dirname ( project . configPath ( ) ) ,
441+ 'fastboot.js'
442+ ) ;
413443
414444 if ( fs . existsSync ( configPath ) ) {
415445 return require ( configPath ) ( environment ) ;
0 commit comments