11/* eslint-env node */
22'use strict' ;
33
4- const fs = require ( 'fs' ) ;
5- const fmt = require ( 'util' ) . format ;
6- const uniq = require ( 'ember-cli-lodash-subset' ) . uniq ;
7- const merge = require ( 'ember-cli-lodash-subset' ) . merge ;
4+ const fs = require ( 'fs' ) ;
5+ const fmt = require ( 'util' ) . format ;
6+ const uniq = require ( 'ember-cli-lodash-subset' ) . uniq ;
7+ const merge = require ( 'ember-cli-lodash-subset' ) . merge ;
88const md5Hex = require ( 'md5-hex' ) ;
9- const path = require ( 'path' ) ;
9+ const path = require ( 'path' ) ;
1010const Plugin = require ( 'broccoli-plugin' ) ;
1111
1212const stringify = require ( 'json-stable-stringify' ) ;
1313
14- const LATEST_SCHEMA_VERSION = 3 ;
14+ const LATEST_SCHEMA_VERSION = 5 ;
1515
1616module . exports = class FastBootConfig extends Plugin {
1717 constructor ( inputNode , options ) {
@@ -38,24 +38,28 @@ module.exports = class FastBootConfig extends Plugin {
3838 this . htmlFile = 'index.html' ;
3939 }
4040
41+ this . prepareConfig ( ) ;
42+ this . prepareDependencies ( ) ;
4143 }
4244
43-
4445 /**
4546 * The main hook called by Broccoli Plugin. Used to build or
4647 * rebuild the tree. In this case, we generate the configuration
4748 * and write it to `package.json`.
4849 */
4950 build ( ) {
50- this . buildConfig ( ) ;
51- this . buildDependencies ( ) ;
52- this . buildManifest ( ) ;
5351 this . buildHostWhitelist ( ) ;
54-
5552 let outputPath = path . join ( this . outputPath , 'package.json' ) ;
5653 this . writeFileIfContentChanged ( outputPath , this . toJSONString ( ) ) ;
5754 }
5855
56+ get manifest ( ) {
57+ if ( ! this . _manifest ) {
58+ this . _manifest = this . buildManifest ( ) ;
59+ }
60+ return this . _manifest ;
61+ }
62+
5963 writeFileIfContentChanged ( outputPath , content ) {
6064 let previous = this . _fileToChecksumMap [ outputPath ] ;
6165 let next = md5Hex ( content ) ;
@@ -66,11 +70,11 @@ module.exports = class FastBootConfig extends Plugin {
6670 }
6771 }
6872
69- buildConfig ( ) {
73+ prepareConfig ( ) {
7074 // we only walk the host app's addons to grab the config since ideally
7175 // addons that have dependency on other addons would never define
7276 // this advance hook.
73- this . project . addons . forEach ( ( addon ) => {
77+ this . project . addons . forEach ( addon => {
7478 if ( addon . fastbootConfigTree ) {
7579 let configFromAddon = addon . fastbootConfigTree ( ) ;
7680
@@ -83,7 +87,7 @@ module.exports = class FastBootConfig extends Plugin {
8387 } ) ;
8488 }
8589
86- buildDependencies ( ) {
90+ prepareDependencies ( ) {
8791 let dependencies = { } ;
8892 let moduleWhitelist = [ ] ;
8993 let ui = this . ui ;
@@ -97,7 +101,10 @@ module.exports = class FastBootConfig extends Plugin {
97101
98102 if ( dep in dependencies ) {
99103 version = dependencies [ dep ] ;
100- ui . writeLine ( fmt ( "Duplicate FastBoot dependency %s. Versions may mismatch. Using range %s." , dep , version ) , ui . WARNING ) ;
104+ ui . writeLine (
105+ fmt ( 'Duplicate FastBoot dependency %s. Versions may mismatch. Using range %s.' , dep , version ) ,
106+ ui . WARNING
107+ ) ;
101108 return ;
102109 }
103110
@@ -129,7 +136,7 @@ module.exports = class FastBootConfig extends Plugin {
129136 }
130137
131138 updateFastBootManifest ( manifest ) {
132- this . project . addons . forEach ( addon => {
139+ this . project . addons . forEach ( addon => {
133140 if ( addon . updateFastBootManifest ) {
134141 manifest = addon . updateFastBootManifest ( manifest ) ;
135142
@@ -157,7 +164,7 @@ module.exports = class FastBootConfig extends Plugin {
157164 htmlFile : this . htmlFile
158165 } ;
159166
160- this . manifest = this . updateFastBootManifest ( manifest ) ;
167+ return this . updateFastBootManifest ( manifest ) ;
161168 }
162169
163170 buildHostWhitelist ( ) {
@@ -167,17 +174,21 @@ module.exports = class FastBootConfig extends Plugin {
167174 }
168175
169176 toJSONString ( ) {
170- return stringify ( {
171- dependencies : this . dependencies ,
172- fastboot : {
173- moduleWhitelist : this . moduleWhitelist ,
174- schemaVersion : LATEST_SCHEMA_VERSION ,
175- manifest : this . manifest ,
176- hostWhitelist : this . normalizeHostWhitelist ( ) ,
177- config : this . fastbootConfig ,
178- appName : this . appName ,
179- }
180- } , null , 2 ) ;
177+ return stringify (
178+ {
179+ name : this . appName ,
180+ dependencies : this . dependencies ,
181+ fastboot : {
182+ moduleWhitelist : this . moduleWhitelist ,
183+ schemaVersion : LATEST_SCHEMA_VERSION ,
184+ hostWhitelist : this . normalizeHostWhitelist ( ) ,
185+ config : this . fastbootConfig ,
186+ htmlEntrypoint : this . manifest . htmlFile
187+ }
188+ } ,
189+ null ,
190+ 2
191+ ) ;
181192 }
182193
183194 normalizeHostWhitelist ( ) {
@@ -194,7 +205,7 @@ module.exports = class FastBootConfig extends Plugin {
194205 }
195206 } ) ;
196207 }
197- }
208+ } ;
198209
199210function eachAddonPackage ( project , cb ) {
200211 project . addons . map ( addon => cb ( addon . pkg ) ) ;
@@ -207,7 +218,11 @@ function getFastBootDependencies(pkg) {
207218 }
208219
209220 if ( addon . fastBootDependencies ) {
210- throw new SilentError ( 'ember-addon.fastBootDependencies has been replaced with ember-addon.fastbootDependencies [addon: ' + pkg . name + ']' )
221+ throw new SilentError (
222+ 'ember-addon.fastBootDependencies has been replaced with ember-addon.fastbootDependencies [addon: ' +
223+ pkg . name +
224+ ']'
225+ ) ;
211226 }
212227
213228 return addon . fastbootDependencies ;
0 commit comments