1+ /* eslint-env node */
12'use strict' ;
23
3- var fs = require ( 'fs' ) ;
4- var path = require ( 'path' ) ;
4+ let fs = require ( 'fs' ) ;
5+ let path = require ( 'path' ) ;
6+
7+ const GENERATE_CONFIG_COMMAND = '`ember g flexi-config`' ;
58
69function assert ( statement , test ) {
710 if ( ! test ) {
@@ -10,23 +13,45 @@ function assert(statement, test) {
1013}
1114
1215module . exports = function ( projectRoot ) {
13- var configPath = path . join ( projectRoot , 'config' , 'flexi.js' ) ;
14- var flexiConfig = { } ;
15-
16- if ( fs . existsSync ( configPath ) ) {
17- flexiConfig = require ( configPath ) ;
18-
19- assert ( 'config/flexi.js is defined, but could not be imported' , flexiConfig ) ;
20- assert ( 'config/flexi.js is defined, but did not contain property [array] breakpoints' ,
21- flexiConfig . breakpoints instanceof Array ) ;
22- assert ( 'config/flexi.js is defined, but did not contain property [number] columns' ,
23- typeof flexiConfig . columns === 'number' ) ;
24-
25- } else {
26- assert ( `You must define a config file for flexi at '${ configPath } '.` +
27- ' To generate a new config file, run `ember g flexi-config`' ,
28- process . argv [ 2 ] === 'install' && process . argv [ 3 ] . indexOf ( 'flexi' ) !== - 1 ) ;
16+ if ( ( [ 'g' , 'generate' ] . indexOf ( process . argv [ 2 ] ) !== - 1 && process . argv [ 3 ] === 'flexi-config' )
17+ || ( process . argv [ 2 ] === 'install' && process . argv [ 3 ] . indexOf ( 'flexi' ) !== - 1 ) ) {
18+ // A flexi-config is currently being generated,
19+ // or flexi is being installed, ignore validation.
20+ return { } ;
2921 }
3022
23+ let configPath = path . join ( projectRoot , 'config' , 'flexi.js' ) ;
24+
25+ assert ( `You must define a config file for flexi at '${ configPath } '.`
26+ + ` To generate a new config file, run ${ GENERATE_CONFIG_COMMAND } ` ,
27+ fs . existsSync ( configPath ) ) ;
28+
29+ let flexiConfig = require ( configPath ) ;
30+ let actualVersion = flexiConfig . configVersion ;
31+ let expectedVersion = require ( path . join ( projectRoot ,
32+ 'node_modules' ,
33+ '@html-next' ,
34+ 'flexi-config' ,
35+ 'blueprints' ,
36+ 'flexi-config' ,
37+ 'files' ,
38+ 'config' ,
39+ 'flexi.js' ) ) . configVersion ;
40+
41+ assert ( 'config/flexi.js is defined, but could not be imported' , flexiConfig ) ;
42+ assert ( 'config/flexi.js is defined, but does not contain property [array] breakpoints,'
43+ + ` consider running ${ GENERATE_CONFIG_COMMAND } to see the default config file.` ,
44+ flexiConfig . breakpoints instanceof Array ) ;
45+ assert ( 'config/flexi.js is defined, but does not contain property [number] columns,'
46+ + ` consider running ${ GENERATE_CONFIG_COMMAND } to see the default config file.` ,
47+ typeof flexiConfig . columns === 'number' ) ;
48+ assert ( 'config/flexi.js is defined, but does not contain property [string] configVersion,'
49+ + ` consider running ${ GENERATE_CONFIG_COMMAND } to see the default config file.` ,
50+ actualVersion ) ;
51+ assert ( `config/flexi.js version does not match the latest config file. Got '${ actualVersion } ',`
52+ + ` expected '${ expectedVersion } '. Consider running ${ GENERATE_CONFIG_COMMAND } to see`
53+ + ' what your config file is missing, then update the version number to match.' ,
54+ actualVersion === expectedVersion ) ;
55+
3156 return flexiConfig ;
3257} ;
0 commit comments