From 58bca26a53304ab1090c23de292f8c06e5aed26b Mon Sep 17 00:00:00 2001 From: nagpalkaran95 Date: Tue, 21 Jul 2020 13:18:09 +0530 Subject: [PATCH 1/5] Make config management developer friendly --- .env.production | 5 +++++ .gitignore | 2 ++ bin/helpers/config.js | 20 +++++++++----------- package.json | 1 + 4 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 .env.production diff --git a/.env.production b/.env.production new file mode 100644 index 00000000..f8246c19 --- /dev/null +++ b/.env.production @@ -0,0 +1,5 @@ +APP_ENV=production +UPLOAD_URL=https://api-cloud.browserstack.com/automate-frameworks/cypress/upload +RAILS_HOST=https://api.browserstack.com +DASHBOARD_URL=https://automate.browserstack.com/dashboard/v2/builds/ +USAGE_REPORTING_URL=https://eds.browserstack.com:443/send_event_cy_internal diff --git a/.gitignore b/.gitignore index 7d2b45e1..ab1bc00a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ specs tests.zip package-lock.json .nyc_output/ +.env.* +!.env.production diff --git a/bin/helpers/config.js b/bin/helpers/config.js index 4f94d0a9..6dd92274 100644 --- a/bin/helpers/config.js +++ b/bin/helpers/config.js @@ -1,18 +1,16 @@ var config = {}; -config.env = "prod"; -var hosts = { - prod: { - uploadUrl: `https://api-cloud.browserstack.com/automate-frameworks/cypress/upload`, - rails_host: `https://api.browserstack.com` - } -}; -config.uploadUrl = hosts[config.env].uploadUrl; -config.rails_host = hosts[config.env].rails_host; +config.env = process.env.NODE_ENV || "production"; + +// load config based on env +require('custom-env').env(config.env) + +config.uploadUrl = process.env.UPLOAD_URL; +config.rails_host = process.env.RAILS_HOST; config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`; config.buildUrl = `${config.cypress_v1}/builds/`; config.buildStopUrl = `${config.cypress_v1}/builds/stop/`; -config.dashboardUrl = `https://automate.browserstack.com/dashboard/v2/builds/`; -config.usageReportingUrl = `https://eds.browserstack.com:443/send_event_cy_internal`; +config.dashboardUrl = process.env.DASHBOARD_URL; +config.usageReportingUrl = process.env.USAGE_REPORTING_URL; config.fileName = "tests.zip"; module.exports = config; diff --git a/package.json b/package.json index 6238d93a..07342e6e 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "devDependencies": { "chai": "^4.2.0", "chai-as-promised": "^7.1.1", + "custom-env": "^2.0.1", "mocha": "^7.1.2", "nyc": "^15.0.1", "proxyquire": "^2.1.3", From 2ae1f6f81ba49642f0d1142d69470a5e28d3a7b3 Mon Sep 17 00:00:00 2001 From: nagpalkaran95 Date: Mon, 10 Aug 2020 13:39:52 +0530 Subject: [PATCH 2/5] fix default config issue --- bin/helpers/config.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/bin/helpers/config.js b/bin/helpers/config.js index 6dd92274..1d9cf3a9 100644 --- a/bin/helpers/config.js +++ b/bin/helpers/config.js @@ -1,16 +1,25 @@ var config = {}; config.env = process.env.NODE_ENV || "production"; -// load config based on env -require('custom-env').env(config.env) +if(config.env === "production") { + config.uploadUrl = 'https://api-cloud.browserstack.com/automate-frameworks/cypress/upload'; + config.rails_host = 'https://api.browserstack.com'; + config.dashboardUrl = 'https://automate.browserstack.com/dashboard/v2/builds/'; + config.usageReportingUrl = 'https://eds.browserstack.com:443/send_event_cy_internal'; +} else { + + // load config based on env + require('custom-env').env(config.env); + + config.uploadUrl = process.env.UPLOAD_URL; + config.rails_host = process.env.RAILS_HOST; + config.dashboardUrl = process.env.DASHBOARD_URL; + config.usageReportingUrl = process.env.USAGE_REPORTING_URL; +} -config.uploadUrl = process.env.UPLOAD_URL; -config.rails_host = process.env.RAILS_HOST; config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`; config.buildUrl = `${config.cypress_v1}/builds/`; config.buildStopUrl = `${config.cypress_v1}/builds/stop/`; -config.dashboardUrl = process.env.DASHBOARD_URL; -config.usageReportingUrl = process.env.USAGE_REPORTING_URL; config.fileName = "tests.zip"; module.exports = config; From 2631e9b5fc6bd948e9b85530a46d263940fd5d5c Mon Sep 17 00:00:00 2001 From: nagpalkaran95 Date: Mon, 10 Aug 2020 13:40:54 +0530 Subject: [PATCH 3/5] remove .env.production --- .env.production | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .env.production diff --git a/.env.production b/.env.production deleted file mode 100644 index f8246c19..00000000 --- a/.env.production +++ /dev/null @@ -1,5 +0,0 @@ -APP_ENV=production -UPLOAD_URL=https://api-cloud.browserstack.com/automate-frameworks/cypress/upload -RAILS_HOST=https://api.browserstack.com -DASHBOARD_URL=https://automate.browserstack.com/dashboard/v2/builds/ -USAGE_REPORTING_URL=https://eds.browserstack.com:443/send_event_cy_internal From 1fc6619ad0a2a4e662447f643fce386e29f463c9 Mon Sep 17 00:00:00 2001 From: nagpalkaran95 Date: Mon, 10 Aug 2020 13:41:47 +0530 Subject: [PATCH 4/5] update gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index ab1bc00a..6c5454b4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ tests.zip package-lock.json .nyc_output/ .env.* -!.env.production From cbdde01c6c24a4a61d743d0d6cc0447bf9ebc3e2 Mon Sep 17 00:00:00 2001 From: nagpalkaran95 Date: Mon, 10 Aug 2020 14:05:50 +0530 Subject: [PATCH 5/5] shift prod config to .json --- bin/helpers/config.js | 13 ++++--------- bin/helpers/config.json | 6 ++++++ 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 bin/helpers/config.json diff --git a/bin/helpers/config.js b/bin/helpers/config.js index 1d9cf3a9..6eb3dddb 100644 --- a/bin/helpers/config.js +++ b/bin/helpers/config.js @@ -1,20 +1,15 @@ -var config = {}; -config.env = process.env.NODE_ENV || "production"; +var config = require('./config.json'); -if(config.env === "production") { - config.uploadUrl = 'https://api-cloud.browserstack.com/automate-frameworks/cypress/upload'; - config.rails_host = 'https://api.browserstack.com'; - config.dashboardUrl = 'https://automate.browserstack.com/dashboard/v2/builds/'; - config.usageReportingUrl = 'https://eds.browserstack.com:443/send_event_cy_internal'; -} else { +config.env = process.env.NODE_ENV || "production"; +if(config.env !== "production") { // load config based on env require('custom-env').env(config.env); config.uploadUrl = process.env.UPLOAD_URL; config.rails_host = process.env.RAILS_HOST; config.dashboardUrl = process.env.DASHBOARD_URL; - config.usageReportingUrl = process.env.USAGE_REPORTING_URL; + config.usageReportingUrl = process.env.USAGE_REPORTING_URL; } config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`; diff --git a/bin/helpers/config.json b/bin/helpers/config.json new file mode 100644 index 00000000..dbd6b7a3 --- /dev/null +++ b/bin/helpers/config.json @@ -0,0 +1,6 @@ +{ + "uploadUrl": "https://api-cloud.browserstack.com/automate-frameworks/cypress/upload", + "rails_host": "https://api.browserstack.com", + "dashboardUrl": "https://automate.browserstack.com/dashboard/v2/builds/", + "usageReportingUrl": "https://eds.browserstack.com:443/send_event_cy_internal" +}