Skip to content
This repository has been archived by the owner on Sep 11, 2018. It is now read-only.

feat(core) add support for specifying environment context from command line #1022

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"__DEV__" : false,
"__TEST__" : false,
"__PROD__" : false,
"__COVERAGE__" : false
"__COVERAGE__" : false,
"__CONTEXT__" : false
},
"rules": {
"key-spacing" : 0,
Expand Down
16 changes: 16 additions & 0 deletions config/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ module.exports = {
compiler_public_path : `http://${config.server_host}:${config.server_port}/`
}),

// ======================================================
// Overrides when NODE_ENV === 'development' and context === 'qa'
// ======================================================
development_qa : (config) => ({
server_port: 3001,
compiler_public_path : `http://${config.server_host}:3001/`
}),

// ======================================================
// Overrides when NODE_ENV === 'production'
// ======================================================
Expand All @@ -25,5 +33,13 @@ module.exports = {
chunkModules : true,
colors : true
}
}),

// ======================================================
// Overrides when NODE_ENV === 'production' and context === 'qa'
// ======================================================
production_qa : (config) => ({
server_port: 3001,
compiler_public_path : './'
})
}
12 changes: 12 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ debug('Creating default configuration.')
// ========================================================
const config = {
env : process.env.NODE_ENV || 'development',
env_context: argv.env_context || false,

// ----------------------------------
// Project Structure
Expand Down Expand Up @@ -78,6 +79,7 @@ config.globals = {
'NODE_ENV' : JSON.stringify(config.env)
},
'NODE_ENV' : config.env,
'__CONTEXT__' : JSON.stringify(config.env_context),
'__DEV__' : config.env === 'development',
'__PROD__' : config.env === 'production',
'__TEST__' : config.env === 'test',
Expand Down Expand Up @@ -128,4 +130,14 @@ if (overrides) {
debug('No environment overrides found, defaults will be used.')
}

// ========================================================
// Context Configuration
// ========================================================
const context = config.env + '_' + config.env_context
const contextOverrides = environments[context]
if (contextOverrides) {
debug(`Found context overrides for "${context}", applying.`)
Object.assign(config, contextOverrides(config))
}

module.exports = config
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"lint:fix": "npm run lint -- --fix",
"start": "better-npm-run start",
"dev": "better-npm-run dev",
"dev:qa": "better-npm-run dev --env_context=qa",
"test": "better-npm-run test",
"test:dev": "npm run test -- --watch",
"deploy": "better-npm-run deploy",
"deploy:dev": "better-npm-run deploy:dev",
"deploy:prod": "better-npm-run deploy:prod",
"deploy:prod:qa": "better-npm-run deploy:prod -- -- --env_context=qa",
"codecov": "cat coverage/*/lcov.info | codecov"
},
"betterScripts": {
Expand Down