33const fs = require ( 'fs' ) ;
44const path = require ( 'path' ) ;
55const RSVP = require ( 'rsvp' ) ;
6+ const chalk = require ( 'chalk' ) ;
67
78const najax = require ( 'najax' ) ;
89const SimpleDOM = require ( 'simple-dom' ) ;
@@ -11,6 +12,7 @@ const debug = require('debug')('fastboot:ember-app');
1112
1213const FastBootInfo = require ( './fastboot-info' ) ;
1314const Result = require ( './result' ) ;
15+ const FastBootSchemaVersions = require ( './fastboot-schema-versions' ) ;
1416
1517/**
1618 * @private
@@ -344,39 +346,44 @@ class EmberApp {
344346 }
345347
346348 let manifest ;
349+ let schemaVersion ;
347350 let pkg ;
348351
349352 try {
350353 pkg = JSON . parse ( file ) ;
351354 manifest = pkg . fastboot . manifest ;
355+ schemaVersion = pkg . fastboot . schemaVersion ;
352356 } catch ( e ) {
353357 throw new Error ( `${ pkgPath } was malformed or did not contain a manifest. Ensure that you have a compatible version of ember-cli-fastboot.` ) ;
354358 }
355359
356- var appFiles = [ ] ;
357- if ( manifest . appFiles ) {
358- debug ( "reading array of app file paths from manifest" ) ;
359- manifest . appFiles . forEach ( function ( appFile ) {
360- appFiles . push ( path . join ( distPath , appFile ) ) ;
361- } ) ;
362- } else if ( manifest . appFile ) {
363- // TODO : remove after Fastboot 1.0
364- debug ( "reading app file path from manifest" ) ;
365- appFiles = [ path . join ( distPath , manifest . appFile ) ] ;
360+ const currentSchemaVersion = FastBootSchemaVersions . latest ;
361+ // set schema version to 1 if not defined
362+ schemaVersion = schemaVersion || FastBootSchemaVersions . base ;
363+ debug ( 'Current schemaVersion from `ember-cli-fastboot` is %s while latest schema version is %s' , ( schemaVersion , currentSchemaVersion ) ) ;
364+
365+ if ( schemaVersion > currentSchemaVersion ) {
366+ let errorMsg = chalk . bold . red ( 'An incompatible version between `ember-cli-fastboot` and `fastboot` was found. Please update the version of fastboot library that is compatible with ember-cli-fastboot.' ) ;
367+ throw new Error ( errorMsg ) ;
366368 }
367369
368- var vendorFiles = [ ] ;
369- if ( manifest . vendorFiles ) {
370- debug ( "reading array of vendor file paths from manifest" ) ;
371- manifest . vendorFiles . forEach ( function ( vendorFile ) {
372- vendorFiles . push ( path . join ( distPath , vendorFile ) ) ;
373- } ) ;
374- } else if ( manifest . vendorFile ) {
375- // TODO : remove after Fastboot 1.0
376- debug ( "reading vendor file path from manifest" ) ;
377- vendorFiles = [ path . join ( distPath , manifest . vendorFile ) ] ;
370+ if ( schemaVersion < FastBootSchemaVersions . manifestFileArrays ) {
371+ // transform app and vendor file to array of files
372+ manifest = this . transformManifestFiles ( manifest ) ;
378373 }
379374
375+ var appFiles = [ ] ;
376+ debug ( "reading array of app file paths from manifest" ) ;
377+ manifest . appFiles . forEach ( function ( appFile ) {
378+ appFiles . push ( path . join ( distPath , appFile ) ) ;
379+ } ) ;
380+
381+ var vendorFiles = [ ] ;
382+ debug ( "reading array of vendor file paths from manifest" ) ;
383+ manifest . vendorFiles . forEach ( function ( vendorFile ) {
384+ vendorFiles . push ( path . join ( distPath , vendorFile ) ) ;
385+ } ) ;
386+
380387 return {
381388 appFiles : appFiles ,
382389 vendorFiles : vendorFiles ,
@@ -386,6 +393,16 @@ class EmberApp {
386393 appConfig : pkg . fastboot . appConfig
387394 } ;
388395 }
396+
397+ /**
398+ * Function to transform the manifest app and vendor files to an array.
399+ */
400+ transformManifestFiles ( manifest ) {
401+ manifest . appFiles = [ manifest . appFile ] ;
402+ manifest . vendorFiles = [ manifest . vendorFile ] ;
403+
404+ return manifest ;
405+ }
389406}
390407
391408/*
0 commit comments