|
|
const fs = require( 'fs' ); |
|
|
const path = require( 'path' ); |
|
|
const chalk = require( 'chalk' ); |
|
|
|
|
|
|
|
|
const configRoot = path.resolve( __dirname, '../config' ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const readConfigFile = ( filename ) => |
|
|
fs.readFileSync( path.join( configRoot, filename ), { encoding: 'utf8' } ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const parseConfig = ( filename ) => JSON.parse( readConfigFile( filename ) ); |
|
|
|
|
|
|
|
|
const environmentKeys = fs |
|
|
.readdirSync( configRoot, { encoding: 'utf8' } ) |
|
|
.filter( ( filename ) => /\.json$/.test( path.basename( filename ) ) ) |
|
|
.filter( ( filename ) => '_shared.json' !== filename ) |
|
|
.filter( ( filename ) => 'client.json' !== filename ) |
|
|
.filter( ( filename ) => ! /secrets/g.test( filename ) ) |
|
|
.map( ( filename ) => [ filename, Object.keys( parseConfig( filename ) ) ] ); |
|
|
|
|
|
|
|
|
const sharedConfig = parseConfig( '_shared.json' ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
environmentKeys.forEach( ( [ filename, keys ] ) => { |
|
|
keys.forEach( ( key ) => { |
|
|
if ( ! sharedConfig.hasOwnProperty( key ) ) { |
|
|
console.error( |
|
|
`${ chalk.red( 'Configuration Error' ) }\n` + |
|
|
`Key ${ chalk.blue( key ) } defined in ${ chalk.blue( filename ) } ` + |
|
|
`but not in ${ chalk.blue( '_shared.json' ) }\n` + |
|
|
`Please add a default value in ${ chalk.blue( '_shared.json' ) } ` + |
|
|
'before adding overrides in the environment-specific config files.' |
|
|
); |
|
|
|
|
|
process.exit( 1 ); |
|
|
} |
|
|
} ); |
|
|
} ); |
|
|
|