From 57eee8a44fb17c554f2535bfb3171cfa40208b42 Mon Sep 17 00:00:00 2001 From: m4recek Date: Mon, 26 Sep 2016 01:49:59 +0200 Subject: [PATCH] feat(core) add support for specifying environment context from command line --- .eslintrc | 3 ++- config/environments.js | 16 ++++++++++++++++ config/index.js | 12 ++++++++++++ package.json | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 053179ffe..88259ce7a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -16,7 +16,8 @@ "__DEV__" : false, "__TEST__" : false, "__PROD__" : false, - "__COVERAGE__" : false + "__COVERAGE__" : false, + "__CONTEXT__" : false }, "rules": { "key-spacing" : 0, diff --git a/config/environments.js b/config/environments.js index 327957a4a..daf16f023 100644 --- a/config/environments.js +++ b/config/environments.js @@ -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' // ====================================================== @@ -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 : './' }) } diff --git a/config/index.js b/config/index.js index f9532194a..4d8072f50 100644 --- a/config/index.js +++ b/config/index.js @@ -10,6 +10,7 @@ debug('Creating default configuration.') // ======================================================== const config = { env : process.env.NODE_ENV || 'development', + env_context: argv.env_context || false, // ---------------------------------- // Project Structure @@ -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', @@ -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 diff --git a/package.json b/package.json index bc1cb61b4..ea48b95ea 100644 --- a/package.json +++ b/package.json @@ -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": {