feat(instant): Cleaner config-specific setup
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"domain": "0x-instant-dogfood",
|
"domain": "0x-instant-dogfood",
|
||||||
"build_command": "WEBPACK_OUTPUT_PATH=public yarn build --env.dogfood",
|
"build_command": "WEBPACK_OUTPUT_PATH=public yarn build:prod --env.dogfood",
|
||||||
"upload_directory": "public",
|
"upload_directory": "public",
|
||||||
"index_key": "index.html",
|
"index_key": "index.html",
|
||||||
"error_key": "index.html",
|
"error_key": "index.html",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"domain": "instant.0xproject.com",
|
"domain": "instant.0xproject.com",
|
||||||
"build_command": "yarn build --env.production_cdn",
|
"build_command": "yarn build:prod --env.production_cdn",
|
||||||
"upload_directory": "umd",
|
"upload_directory": "umd",
|
||||||
"index_key": "instant.js",
|
"index_key": "instant.js",
|
||||||
"error_key": "404.html",
|
"error_key": "404.html",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"domain": "0x-instant-staging",
|
"domain": "0x-instant-staging",
|
||||||
"build_command": "WEBPACK_OUTPUT_PATH=public yarn build:prod --env.staging",
|
"build_command": "WEBPACK_OUTPUT_PATH=public yarn build:prod:prod --env.staging",
|
||||||
"upload_directory": "public",
|
"upload_directory": "public",
|
||||||
"index_key": "index.html",
|
"index_key": "index.html",
|
||||||
"error_key": "index.html",
|
"error_key": "index.html",
|
||||||
|
|||||||
@@ -8,10 +8,11 @@
|
|||||||
"main": "umd/instant.js",
|
"main": "umd/instant.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack --mode production --env.production_standalone",
|
"build": "yarn build:prod --env.production_standalone",
|
||||||
"build:ci": "yarn build",
|
"build:prod": "webpack --mode production",
|
||||||
|
"build:ci": "build",
|
||||||
"watch_without_deps": "tsc -w",
|
"watch_without_deps": "tsc -w",
|
||||||
"dev": "webpack-dev-server --mode development",
|
"dev": "webpack-dev-server --mode development --env.development",
|
||||||
"lint": "tslint --format stylish --project .",
|
"lint": "tslint --format stylish --project .",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:coverage": "jest --coverage",
|
"test:coverage": "jest --coverage",
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ export const HEAP_ANALYTICS_ID = process.env.HEAP_ANALYTICS_ID;
|
|||||||
export const COINBASE_API_BASE_URL = 'https://api.coinbase.com/v2';
|
export const COINBASE_API_BASE_URL = 'https://api.coinbase.com/v2';
|
||||||
export const PROGRESS_STALL_AT_WIDTH = '95%';
|
export const PROGRESS_STALL_AT_WIDTH = '95%';
|
||||||
export const PROGRESS_FINISH_ANIMATION_TIME_MS = 200;
|
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 COINBASE_WALLET_IOS_APP_STORE_URL = 'https://itunes.apple.com/us/app/coinbase-wallet/id1278383455?mt=8';
|
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_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/';
|
export const COINBASE_WALLET_SITE_URL = 'https://wallet.coinbase.com/';
|
||||||
|
|||||||
@@ -6,27 +6,64 @@ const webpack = require('webpack');
|
|||||||
// The common js bundle (not this one) is built using tsc.
|
// The common js bundle (not this one) is built using tsc.
|
||||||
// The umd bundle (this one) has a different entrypoint.
|
// 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 GIT_SHA = childProcess
|
const GIT_SHA = childProcess
|
||||||
.execSync('git rev-parse HEAD')
|
.execSync('git rev-parse HEAD')
|
||||||
.toString()
|
.toString()
|
||||||
.trim();
|
.trim();
|
||||||
|
const generateConfig = (environmentName, configOptions) => {
|
||||||
const HEAP_PRODUCTION_ENV_VAR_NAME = 'INSTANT_HEAP_ANALYTICS_ID_PRODUCTION';
|
|
||||||
const HEAP_DEVELOPMENT_ENV_VAR_NAME = 'INSTANT_HEAP_ANALYTICS_ID_DEVELOPMENT';
|
|
||||||
const getHeapAnalyticsId = modeName => {
|
|
||||||
if (modeName === 'production') {
|
|
||||||
return process.env[HEAP_PRODUCTION_ENV_VAR_NAME];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (modeName === 'development') {
|
|
||||||
return process.env[HEAP_DEVELOPMENT_ENV_VAR_NAME];
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = (env, argv) => {
|
|
||||||
const outputPath = process.env.WEBPACK_OUTPUT_PATH || 'umd';
|
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}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const envVars = {
|
||||||
|
GIT_SHA: JSON.stringify(GIT_SHA),
|
||||||
|
INSTANT_ENVIRONMENT: JSON.stringify(environmentName),
|
||||||
|
NPM_PACKAGE_VERSION: JSON.stringify(process.env.npm_package_version),
|
||||||
|
};
|
||||||
|
if (heapAnalyticsId) {
|
||||||
|
envVars.HEAP_ANALYTICS_ID = JSON.stringify(heapAnalyticsId);
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
entry: {
|
entry: {
|
||||||
instant: './src/index.umd.ts',
|
instant: './src/index.umd.ts',
|
||||||
@@ -39,11 +76,7 @@ module.exports = (env, argv) => {
|
|||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': {
|
'process.env': envVars,
|
||||||
GIT_SHA: JSON.stringify(GIT_SHA),
|
|
||||||
HEAP_ANALYTICS_ID: getHeapAnalyticsId(argv.mode),
|
|
||||||
NPM_PACKAGE_VERSION: JSON.stringify(process.env.npm_package_version),
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
devtool: 'source-map',
|
devtool: 'source-map',
|
||||||
@@ -79,3 +112,9 @@ module.exports = (env, argv) => {
|
|||||||
};
|
};
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = (env, _argv) => {
|
||||||
|
const environmentName = getEnvironmentName(env);
|
||||||
|
const configOptions = getConfigForEnv(environmentName);
|
||||||
|
return generateConfig(environmentName, configOptions);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user