From d4c3fa6885637f783de7e1d462cd3946ef3d71a3 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 30 Jul 2020 16:19:42 -0300 Subject: [PATCH] Factor out `getEnvironment` function in build script (#9114) There are no functional changes. This was extracted from #8170 --- development/build/scripts.js | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/development/build/scripts.js b/development/build/scripts.js index 04f21aa76..6f206ee57 100644 --- a/development/build/scripts.js +++ b/development/build/scripts.js @@ -316,23 +316,7 @@ function createScriptTasks ({ browserPlatforms, livereload }) { bundler = bundler.external(opts.externalDependencies) } - let environment - if (opts.devMode) { - environment = 'development' - } else if (opts.testing) { - environment = 'testing' - } else if (process.env.CIRCLE_BRANCH === 'master') { - environment = 'production' - } else if (/^Version-v(\d+)[.](\d+)[.](\d+)/.test(process.env.CIRCLE_BRANCH)) { - environment = 'release-candidate' - } else if (process.env.CIRCLE_BRANCH === 'develop') { - environment = 'staging' - } else if (process.env.CIRCLE_PULL_REQUEST) { - environment = 'pull-request' - } else { - environment = 'other' - } - + const environment = getEnvironment({ devMode: opts.devMode, test: opts.testing }) if (environment === 'production' && !process.env.SENTRY_DSN) { throw new Error('Missing SENTRY_DSN environment variable') } @@ -372,3 +356,22 @@ function createScriptTasks ({ browserPlatforms, livereload }) { function beep () { process.stdout.write('\x07') } + +function getEnvironment ({ devMode, test }) { + // get environment slug + if (devMode) { + return 'development' + } else if (test) { + return 'testing' + } else if (process.env.CIRCLE_BRANCH === 'master') { + return 'production' + } else if (/^Version-v(\d+)[.](\d+)[.](\d+)/.test(process.env.CIRCLE_BRANCH)) { + return 'release-candidate' + } else if (process.env.CIRCLE_BRANCH === 'develop') { + return 'staging' + } else if (process.env.CIRCLE_PULL_REQUEST) { + return 'pull-request' + } else { + return 'other' + } +}