aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-30 07:13:55 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-30 07:13:55 +0800
commitd99bdcf036eebc6613274fecfdd19187eaf4aa1a (patch)
tree444d55d6e6ec1c07280fa7ed7d3ebb75ce2d072b /packages/instant
parent4616c51e199b3e5c37f8b5f23788645632f2faf6 (diff)
downloaddexon-sol-tools-d99bdcf036eebc6613274fecfdd19187eaf4aa1a.tar
dexon-sol-tools-d99bdcf036eebc6613274fecfdd19187eaf4aa1a.tar.gz
dexon-sol-tools-d99bdcf036eebc6613274fecfdd19187eaf4aa1a.tar.bz2
dexon-sol-tools-d99bdcf036eebc6613274fecfdd19187eaf4aa1a.tar.lz
dexon-sol-tools-d99bdcf036eebc6613274fecfdd19187eaf4aa1a.tar.xz
dexon-sol-tools-d99bdcf036eebc6613274fecfdd19187eaf4aa1a.tar.zst
dexon-sol-tools-d99bdcf036eebc6613274fecfdd19187eaf4aa1a.zip
cdn approach to identifyign environments
Diffstat (limited to 'packages/instant')
-rw-r--r--packages/instant/.dogfood.discharge.json2
-rw-r--r--packages/instant/.production.discharge.json2
-rw-r--r--packages/instant/.staging.discharge.json2
-rw-r--r--packages/instant/package.json3
-rw-r--r--packages/instant/src/constants.ts7
-rw-r--r--packages/instant/webpack.config.js53
6 files changed, 20 insertions, 49 deletions
diff --git a/packages/instant/.dogfood.discharge.json b/packages/instant/.dogfood.discharge.json
index 5a11f8a1d..f9b96ac95 100644
--- a/packages/instant/.dogfood.discharge.json
+++ b/packages/instant/.dogfood.discharge.json
@@ -1,6 +1,6 @@
{
"domain": "0x-instant-dogfood",
- "build_command": "WEBPACK_OUTPUT_PATH=public yarn build:prod --env.dogfood",
+ "build_command": "WEBPACK_OUTPUT_PATH=public yarn build:prod --env.cdn=staging",
"upload_directory": "public",
"index_key": "index.html",
"error_key": "index.html",
diff --git a/packages/instant/.production.discharge.json b/packages/instant/.production.discharge.json
index ecd3a12d4..70dd4e04c 100644
--- a/packages/instant/.production.discharge.json
+++ b/packages/instant/.production.discharge.json
@@ -1,6 +1,6 @@
{
"domain": "instant.0xproject.com",
- "build_command": "yarn build:prod --env.production_cdn",
+ "build_command": "yarn build --env.cdn=production",
"upload_directory": "umd",
"index_key": "instant.js",
"error_key": "404.html",
diff --git a/packages/instant/.staging.discharge.json b/packages/instant/.staging.discharge.json
index ba2ca5f99..44fc3abc8 100644
--- a/packages/instant/.staging.discharge.json
+++ b/packages/instant/.staging.discharge.json
@@ -1,6 +1,6 @@
{
"domain": "0x-instant-staging",
- "build_command": "WEBPACK_OUTPUT_PATH=public yarn build:prod:prod --env.staging",
+ "build_command": "WEBPACK_OUTPUT_PATH=public yarn build --env.cdn=staging",
"upload_directory": "public",
"index_key": "index.html",
"error_key": "index.html",
diff --git a/packages/instant/package.json b/packages/instant/package.json
index 068900b48..381d78c88 100644
--- a/packages/instant/package.json
+++ b/packages/instant/package.json
@@ -8,8 +8,7 @@
"main": "umd/instant.js",
"private": true,
"scripts": {
- "build": "yarn build:prod --env.production_standalone",
- "build:prod": "webpack --mode production",
+ "build": "webpack --mode production",
"build:ci": "yarn build",
"watch_without_deps": "tsc -w",
"dev": "webpack-dev-server --mode development --env.development",
diff --git a/packages/instant/src/constants.ts b/packages/instant/src/constants.ts
index e70b3f1d8..3370af094 100644
--- a/packages/instant/src/constants.ts
+++ b/packages/instant/src/constants.ts
@@ -20,12 +20,7 @@ export const HEAP_ANALYTICS_ID = process.env.HEAP_ANALYTICS_ID;
export const COINBASE_API_BASE_URL = 'https://api.coinbase.com/v2';
export const PROGRESS_STALL_AT_WIDTH = '95%';
export const PROGRESS_FINISH_ANIMATION_TIME_MS = 200;
-export const INSTANT_ENVIRONMENT = process.env.INSTANT_ENVIRONMENT as
- | 'dogfood'
- | 'staging'
- | 'development'
- | 'production_cdn'
- | 'production_standalone';
+export const INSTANT_CDN = process.env.INSTANT_CDN as 'production' | 'dogfood' | 'staging' | undefined;
export const COINBASE_WALLET_IOS_APP_STORE_URL = 'https://itunes.apple.com/us/app/coinbase-wallet/id1278383455?mt=8';
export const COINBASE_WALLET_ANDROID_APP_STORE_URL = 'https://play.google.com/store/apps/details?id=org.toshi&hl=en';
export const COINBASE_WALLET_SITE_URL = 'https://wallet.coinbase.com/';
diff --git a/packages/instant/webpack.config.js b/packages/instant/webpack.config.js
index 284276c1a..020fab506 100644
--- a/packages/instant/webpack.config.js
+++ b/packages/instant/webpack.config.js
@@ -6,60 +6,37 @@ const webpack = require('webpack');
// The common js bundle (not this one) is built using tsc.
// The umd bundle (this one) has a different entrypoint.
-const ACCEPTABLE_ENV_NAMES = ['production_standalone', 'production_cdn', 'staging', 'dogfood', 'development'];
-const getEnvironmentName = env => {
- if (!env) {
- throw new Error('Please specify env via --env to webpack');
- }
- const foundName = ACCEPTABLE_ENV_NAMES.find(e => (env[e] ? e : false));
- if (!foundName) {
- throw new Error(
- `Couldn't find env name, please specify via one of the following CLI arguments: ${acceptableEnvNames.map(
- i => `--env.${i}`,
- )}`,
- );
- }
- return foundName;
-};
-
-const getConfigForEnv = environmentName => {
- switch (environmentName) {
- case 'production_standalone':
- case 'production_cdn':
- return {
- heapAnalyticsIdEnvName: 'INSTANT_HEAP_ANALYTICS_ID_PRODUCTION',
- heapAnalyticsIdRequired: environmentName !== 'production_standalone',
- };
- case 'staging':
- case 'dogfood':
- case 'development':
- return {
- heapAnalyticsIdEnvName: 'INSTANT_HEAP_ANALYTICS_ID_DEVELOPMENT',
- heapAnalyticsIdRequired: environmentName !== 'development',
- };
- }
+const CDNS_THAT_REQUIRE_HEAP = ['production', 'staging', 'dogfood'];
+const getConfigForCdn = cdnName => {
+ return {
+ heapAnalyticsIdEnvName:
+ cdnName === 'production' ? 'INSTANT_HEAP_ANALYTICS_ID_PRODUCTION' : 'INSTANT_HEAP_ANALYTICS_ID_DEVELOPMENT',
+ heapAnalyticsIdRequired: CDNS_THAT_REQUIRE_HEAP.includes(cdnName),
+ };
};
const GIT_SHA = childProcess
.execSync('git rev-parse HEAD')
.toString()
.trim();
-const generateConfig = (environmentName, configOptions) => {
+const generateConfig = (cdnName, configOptions) => {
const outputPath = process.env.WEBPACK_OUTPUT_PATH || 'umd';
const { heapAnalyticsIdEnvName, heapAnalyticsIdRequired } = configOptions;
const heapAnalyticsId = process.env[heapAnalyticsIdEnvName];
if (heapAnalyticsIdRequired && !heapAnalyticsId) {
throw new Error(
- `Must define heap analytics id in ENV var ${heapAnalyticsIdEnvName} when building for ${environmentName}`,
+ `Must define heap analytics id in ENV var ${heapAnalyticsIdEnvName} when building for ${cdnName}`,
);
}
const envVars = {
GIT_SHA: JSON.stringify(GIT_SHA),
- INSTANT_ENVIRONMENT: JSON.stringify(environmentName),
NPM_PACKAGE_VERSION: JSON.stringify(process.env.npm_package_version),
};
+ if (cdnName) {
+ envVars.INSTANT_CDN = JSON.stringify(cdnName);
+ }
if (heapAnalyticsId) {
envVars.HEAP_ANALYTICS_ID = JSON.stringify(heapAnalyticsId);
}
@@ -114,7 +91,7 @@ const generateConfig = (environmentName, configOptions) => {
};
module.exports = (env, _argv) => {
- const environmentName = getEnvironmentName(env);
- const configOptions = getConfigForEnv(environmentName);
- return generateConfig(environmentName, configOptions);
+ const cdnName = env ? env.cdn : undefined;
+ const configOptions = getConfigForCdn(cdnName);
+ return generateConfig(cdnName, configOptions);
};