@@ -11,7 +11,7 @@ const chalk = require('chalk');
11
11
12
12
const fastbootAppBoot = require ( './lib/utilities/fastboot-app-boot' ) ;
13
13
const FastBootConfig = require ( './lib/broccoli/fastboot-config' ) ;
14
- const HTMLWriter = require ( './lib/broccoli/html -writer' ) ;
14
+ const BasePageWriter = require ( './lib/broccoli/base-page -writer' ) ;
15
15
const fastbootAppFactoryModule = require ( './lib/utilities/fastboot-app-factory-module' ) ;
16
16
const migrateInitializers = require ( './lib/build-utilities/migrate-initializers' ) ;
17
17
const SilentError = require ( 'silent-error' ) ;
@@ -61,7 +61,9 @@ module.exports = {
61
61
* See: https://ember-cli.com/user-guide/#integration
62
62
*/
63
63
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
+ ) ;
65
67
if ( assetRev && ! assetRev . supportsFastboot ) {
66
68
throw new SilentError (
67
69
'This version of ember-cli-fastboot requires a newer version of broccoli-asset-rev'
@@ -110,7 +112,10 @@ module.exports = {
110
112
}
111
113
112
114
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
+ ) ;
114
119
}
115
120
116
121
// if the fastboot addon is installed, we overwrite the config-module so that the config can be read
@@ -135,15 +140,19 @@ module.exports = {
135
140
136
141
// check the ember version and conditionally patch the DOM api
137
142
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 ;
140
149
}
141
150
142
151
return tree ;
143
152
} ,
144
153
145
154
_processAddons ( addons , fastbootTrees ) {
146
- addons . forEach ( addon => {
155
+ addons . forEach ( ( addon ) => {
147
156
this . _processAddon ( addon , fastbootTrees ) ;
148
157
} ) ;
149
158
} ,
@@ -183,7 +192,10 @@ module.exports = {
183
192
// check the parent containing the fastboot directory
184
193
const projectFastbootPath = path . join ( this . project . root , 'fastboot' ) ;
185
194
// 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
+ ) {
187
199
let fastbootTree = this . treeGenerator ( projectFastbootPath ) ;
188
200
fastbootTrees . push ( fastbootTree ) ;
189
201
}
@@ -196,17 +208,28 @@ module.exports = {
196
208
let funneledFastbootTrees = new Funnel ( mergedFastBootTree , {
197
209
destDir : appName ,
198
210
} ) ;
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
+ ) ;
202
219
203
220
// FastBoot app factory module
204
221
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
+ ) ;
210
233
211
234
function stripLeadingSlash ( filePath ) {
212
235
return filePath . replace ( / ^ \/ / , '' ) ;
@@ -231,7 +254,8 @@ module.exports = {
231
254
232
255
let newTree = new MergeTrees ( trees ) ;
233
256
234
- let fastbootConfigTree = ( this . _fastbootConfigTree = this . _buildFastbootConfigTree ( newTree ) ) ;
257
+ let fastbootConfigTree = ( this . _fastbootConfigTree =
258
+ this . _buildFastbootConfigTree ( newTree ) ) ;
235
259
236
260
// Merge the package.json with the existing tree
237
261
return new MergeTrees ( [ newTree , fastbootConfigTree ] , { overwrite : true } ) ;
@@ -296,15 +320,23 @@ module.exports = {
296
320
297
321
_buildFastbootConfigTree ( tree ) {
298
322
let appConfig = this . _getHostAppConfig ( ) ;
299
- let fastbootAppConfig = appConfig . fastboot ;
300
323
301
324
return new FastBootConfig ( tree , {
302
325
project : this . project ,
303
- name : this . app . name ,
304
326
outputPaths : this . app . options . outputPaths ,
305
327
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 ,
308
340
} ) ;
309
341
} ,
310
342
@@ -314,15 +346,7 @@ module.exports = {
314
346
postprocessTree ( type , tree ) {
315
347
this . _super ( ...arguments ) ;
316
348
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 ) ;
326
350
327
351
// Merge the package.json with the existing tree
328
352
return new MergeTrees ( [ tree , fastbootHTMLTree ] , { overwrite : true } ) ;
@@ -341,8 +365,11 @@ module.exports = {
341
365
342
366
app . use ( ( req , resp , next ) => {
343
367
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 ;
346
373
347
374
if ( req . serveUrl && enableFastBootServe ) {
348
375
// if it is a base page request, then have fastboot serve the base page
@@ -409,7 +436,10 @@ module.exports = {
409
436
* TODO Allow add-ons to provide own options and merge them with the application's options.
410
437
*/
411
438
_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
+ ) ;
413
443
414
444
if ( fs . existsSync ( configPath ) ) {
415
445
return require ( configPath ) ( environment ) ;
0 commit comments