-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #876 from Automattic/try/config-overrides
Framework: Cascading Configs
- Loading branch information
Showing
17 changed files
with
324 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"discover_blog_id": 53424024 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
NODE_BIN := $(shell npm bin) | ||
MOCHA ?= $(NODE_BIN)/mocha | ||
BASE_DIR := $(NODE_BIN)/../.. | ||
NODE_PATH := ../:$(BASE_DIR)/client | ||
COMPILERS ?= js:babel/register | ||
REPORTER ?= spec | ||
UI ?= bdd | ||
|
||
test: | ||
@NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers $(COMPILERS) --reporter $(REPORTER) --ui $(UI) | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/***** WARNING: ES5 code only here. Used by un-transpiled script! *****/ | ||
|
||
/** | ||
* Module dependencies | ||
*/ | ||
const fs = require( 'fs' ), | ||
path = require( 'path' ), | ||
assign = require( 'lodash/object/assign' ), | ||
debug = require( 'debug' )( 'config' ); | ||
|
||
function getDataFromFile( file ) { | ||
var fileData = {}; | ||
|
||
if ( fs.existsSync( file ) ) { | ||
debug( 'getting data from config file: %o', file ); | ||
fileData = JSON.parse( fs.readFileSync( file, 'utf8' ) ); | ||
} else { | ||
debug( 'skipping config file; not found: %o', file ); | ||
} | ||
|
||
return fileData; | ||
} | ||
|
||
module.exports = function( configPath, defaultOpts ) { | ||
var opts = assign( { | ||
env: 'development', | ||
includeSecrets: false, | ||
}, defaultOpts ), | ||
data = {}, | ||
configFiles = [ | ||
path.resolve( configPath, '_shared.json' ), | ||
path.resolve( configPath, opts.env + '.json' ), | ||
path.resolve( configPath, opts.env + '.local.json' ) | ||
], | ||
realSecretsPath, | ||
emptySecretsPath, | ||
secretsPath, | ||
enabledFeatures = opts.enabledFeatures ? opts.enabledFeatures.split( ',' ) : [], | ||
disabledFeatures = opts.disabledFeatures ? opts.disabledFeatures.split( ',' ) : []; | ||
|
||
if ( opts.includeSecrets ) { | ||
realSecretsPath = path.resolve( configPath, 'secrets.json' ); | ||
emptySecretsPath = path.resolve( configPath, 'empty-secrets.json' ); | ||
secretsPath = fs.existsSync( realSecretsPath ) ? realSecretsPath : emptySecretsPath; | ||
|
||
configFiles.push( secretsPath ); | ||
} | ||
|
||
configFiles.forEach( function( file ) { | ||
assign( data, getDataFromFile( file ) ); | ||
} ); | ||
|
||
if ( data.hasOwnProperty( 'features' ) ) { | ||
enabledFeatures.forEach( function( feature ) { | ||
data.features[ feature ] = true; | ||
debug( 'overriding feature %s to true', feature ); | ||
} ); | ||
disabledFeatures.forEach( function( feature ) { | ||
data.features[ feature ] = false; | ||
debug( 'overriding feature %s to false', feature ); | ||
} ); | ||
} | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env node | ||
/***** WARNING: ES5 code only here. Not transpiled! *****/ | ||
|
||
/** | ||
* Module dependencies/ | ||
*/ | ||
var fs = require( 'fs' ), | ||
path = require( 'path' ), | ||
configPath = path.resolve( __dirname, '..', '..', 'config' ), | ||
keysPath = path.resolve( configPath, 'client.json' ), | ||
keys = JSON.parse( fs.readFileSync( keysPath, 'utf8' ) ), | ||
config = require( './' ), | ||
data = require( './parser' )( configPath, { | ||
env: process.env.CALYPSO_ENV || 'development', | ||
includeSecrets: false, | ||
enabledFeatures: process.env.ENABLE_FEATURES, | ||
disabledFeatures: process.env.DISABLE_FEATURES | ||
} ), | ||
obj = {}; | ||
|
||
keys.forEach( function( key ) { | ||
if ( key in data ) { | ||
obj[ key ] = data[ key ]; | ||
} | ||
} ); | ||
|
||
console.log( '/* This file is automatically generated. Do not edit manually. */' ); | ||
console.log(); | ||
console.log( 'var data = %s;', JSON.stringify( obj, null, 2 ) ); | ||
console.log( config.toString() ); | ||
console.log( config.isEnabled.toString() ); | ||
console.log( config.anyEnabled.toString() ); | ||
console.log( 'module.exports = config;' ); | ||
console.log( 'module.exports.isEnabled = isEnabled;' ); | ||
console.log( 'module.exports.anyEnabled = anyEnabled;' ); |
Oops, something went wrong.