@ -29,6 +29,7 @@ const bifyModuleGroups = require('bify-module-groups');
const metamaskrc = require ( 'rc' ) ( 'metamask' , {
const metamaskrc = require ( 'rc' ) ( 'metamask' , {
INFURA _PROJECT _ID : process . env . INFURA _PROJECT _ID ,
INFURA _PROJECT _ID : process . env . INFURA _PROJECT _ID ,
INFURA _PROD _PROJECT _ID : process . env . INFURA _PROD _PROJECT _ID ,
ONBOARDING _V2 : process . env . ONBOARDING _V2 ,
ONBOARDING _V2 : process . env . ONBOARDING _V2 ,
SEGMENT _HOST : process . env . SEGMENT _HOST ,
SEGMENT _HOST : process . env . SEGMENT _HOST ,
SEGMENT _WRITE _KEY : process . env . SEGMENT _WRITE _KEY ,
SEGMENT _WRITE _KEY : process . env . SEGMENT _WRITE _KEY ,
@ -50,6 +51,51 @@ const {
createRemoveFencedCodeTransform ,
createRemoveFencedCodeTransform ,
} = require ( './transforms/remove-fenced-code' ) ;
} = require ( './transforms/remove-fenced-code' ) ;
/ * *
* The build environment . This describes the environment this build was produced in .
* /
const ENVIRONMENT = {
DEVELOPMENT : 'development' ,
PRODUCTION : 'production' ,
OTHER : 'other' ,
PULL _REQUEST : 'pull-request' ,
RELEASE _CANDIDATE : 'release-candidate' ,
STAGING : 'staging' ,
TESTING : 'testing' ,
} ;
/ * *
* Get a value from the configuration , and confirm that it is set .
*
* @ param { string } key - The configuration key to retrieve .
* @ returns { string } The config entry requested .
* @ throws { Error } Throws if the requested key is missing .
* /
function getConfigValue ( key ) {
const value = metamaskrc [ key ] ;
if ( ! value ) {
throw new Error ( ` Missing config entry for ' ${ key } ' ` ) ;
}
return value ;
}
/ * *
* Get the appropriate Infura project ID .
*
* @ param { object } options - The Infura project ID options .
* @ param { ENVIRONMENT [ keyof ENVIRONMENT ] } options . environment - The build environment .
* @ param { boolean } options . testing - Whether the current build is a test build or not .
* @ returns { string } The Infura project ID .
* /
function getInfuraProjectId ( { environment , testing } ) {
if ( testing ) {
return '00000000000000000000000000000000' ;
} else if ( environment === ENVIRONMENT . PRODUCTION ) {
return getConfigValue ( 'INFURA_PROD_PROJECT_ID' ) ;
}
return getConfigValue ( 'INFURA_PROJECT_ID' ) ;
}
module . exports = createScriptTasks ;
module . exports = createScriptTasks ;
function createScriptTasks ( {
function createScriptTasks ( {
@ -624,7 +670,7 @@ async function bundleIt(buildConfiguration) {
function getEnvironmentVariables ( { buildType , devMode , testing } ) {
function getEnvironmentVariables ( { buildType , devMode , testing } ) {
const environment = getEnvironment ( { devMode , testing } ) ;
const environment = getEnvironment ( { devMode , testing } ) ;
if ( environment === 'production' && ! process . env . SENTRY _DSN ) {
if ( environment === ENVIRONMENT . PRODUCTION && ! process . env . SENTRY _DSN ) {
throw new Error ( 'Missing SENTRY_DSN environment variable' ) ;
throw new Error ( 'Missing SENTRY_DSN environment variable' ) ;
}
}
return {
return {
@ -632,16 +678,14 @@ function getEnvironmentVariables({ buildType, devMode, testing }) {
METAMASK _ENVIRONMENT : environment ,
METAMASK _ENVIRONMENT : environment ,
METAMASK _VERSION : version ,
METAMASK _VERSION : version ,
METAMASK _BUILD _TYPE : buildType ,
METAMASK _BUILD _TYPE : buildType ,
NODE _ENV : devMode ? 'development' : 'production' ,
NODE _ENV : devMode ? ENVIRONMENT . DEVELOPMENT : ENVIRONMENT . PRODUCTION ,
IN _TEST : testing ? 'true' : false ,
IN _TEST : testing ? 'true' : false ,
PUBNUB _SUB _KEY : process . env . PUBNUB _SUB _KEY || '' ,
PUBNUB _SUB _KEY : process . env . PUBNUB _SUB _KEY || '' ,
PUBNUB _PUB _KEY : process . env . PUBNUB _PUB _KEY || '' ,
PUBNUB _PUB _KEY : process . env . PUBNUB _PUB _KEY || '' ,
CONF : devMode ? metamaskrc : { } ,
CONF : devMode ? metamaskrc : { } ,
SENTRY _DSN : process . env . SENTRY _DSN ,
SENTRY _DSN : process . env . SENTRY _DSN ,
SENTRY _DSN _DEV : metamaskrc . SENTRY _DSN _DEV ,
SENTRY _DSN _DEV : metamaskrc . SENTRY _DSN _DEV ,
INFURA _PROJECT _ID : testing
INFURA _PROJECT _ID : getInfuraProjectId ( { environment , testing } ) ,
? '00000000000000000000000000000000'
: metamaskrc . INFURA _PROJECT _ID ,
SEGMENT _HOST : metamaskrc . SEGMENT _HOST ,
SEGMENT _HOST : metamaskrc . SEGMENT _HOST ,
// When we're in the 'production' environment we will use a specific key only set in CI
// When we're in the 'production' environment we will use a specific key only set in CI
// Otherwise we'll use the key from .metamaskrc or from the environment variable. If
// Otherwise we'll use the key from .metamaskrc or from the environment variable. If
@ -649,7 +693,7 @@ function getEnvironmentVariables({ buildType, devMode, testing }) {
// in the build. This is intentional so that developers can contribute to MetaMask without
// in the build. This is intentional so that developers can contribute to MetaMask without
// inflating event volume.
// inflating event volume.
SEGMENT _WRITE _KEY :
SEGMENT _WRITE _KEY :
environment === 'production'
environment === ENVIRONMENT . PRODUCTION
? process . env . SEGMENT _PROD _WRITE _KEY
? process . env . SEGMENT _PROD _WRITE _KEY
: metamaskrc . SEGMENT _WRITE _KEY ,
: metamaskrc . SEGMENT _WRITE _KEY ,
SWAPS _USE _DEV _APIS : process . env . SWAPS _USE _DEV _APIS === '1' ,
SWAPS _USE _DEV _APIS : process . env . SWAPS _USE _DEV _APIS === '1' ,
@ -660,21 +704,21 @@ function getEnvironmentVariables({ buildType, devMode, testing }) {
function getEnvironment ( { devMode , testing } ) {
function getEnvironment ( { devMode , testing } ) {
// get environment slug
// get environment slug
if ( devMode ) {
if ( devMode ) {
return 'development' ;
return ENVIRONMENT . DEVELOPMENT ;
} else if ( testing ) {
} else if ( testing ) {
return 'testing' ;
return ENVIRONMENT . TESTING ;
} else if ( process . env . CIRCLE _BRANCH === 'master' ) {
} else if ( process . env . CIRCLE _BRANCH === 'master' ) {
return 'production' ;
return ENVIRONMENT . PRODUCTION ;
} else if (
} else if (
/^Version-v(\d+)[.](\d+)[.](\d+)/u . test ( process . env . CIRCLE _BRANCH )
/^Version-v(\d+)[.](\d+)[.](\d+)/u . test ( process . env . CIRCLE _BRANCH )
) {
) {
return 'release-candidate' ;
return ENVIRONMENT . RELEASE _CANDIDATE ;
} else if ( process . env . CIRCLE _BRANCH === 'develop' ) {
} else if ( process . env . CIRCLE _BRANCH === 'develop' ) {
return 'staging' ;
return ENVIRONMENT . STAGING ;
} else if ( process . env . CIRCLE _PULL _REQUEST ) {
} else if ( process . env . CIRCLE _PULL _REQUEST ) {
return 'pull-request' ;
return ENVIRONMENT . PULL _REQUEST ;
}
}
return 'other' ;
return ENVIRONMENT . OTHER ;
}
}
function renderHtmlFile ( {
function renderHtmlFile ( {