fix(env): update variable validations (#40813)
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
58c6c54c67
commit
0b944ddfde
@ -11,26 +11,32 @@ const { FREECODECAMP_NODE_ENV } = process.env;
|
||||
|
||||
function checkClientLocale() {
|
||||
if (!availableLangs.client.includes(process.env.CLIENT_LOCALE)) {
|
||||
throw Error(
|
||||
`CLIENT_LOCALE, ${process.env.CLIENT_LOCALE}, is not an available language in client/i18n/allLangs.js`
|
||||
);
|
||||
throw Error(`
|
||||
|
||||
CLIENT_LOCALE, ${process.env.CLIENT_LOCALE}, is not an available language in client/i18n/allLangs.js
|
||||
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
||||
function checkCurriculumLocale() {
|
||||
if (!availableLangs.curriculum.includes(process.env.CURRICULUM_LOCALE)) {
|
||||
throw Error(
|
||||
`CURRICULUM_LOCALE, ${process.env.CURRICULUM_LOCALE}, is not an available language in client/i18n/allLangs.js`
|
||||
);
|
||||
throw Error(`
|
||||
|
||||
CURRICULUM_LOCALE, ${process.env.CURRICULUM_LOCALE}, is not an available language in client/i18n/allLangs.js
|
||||
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
||||
if (FREECODECAMP_NODE_ENV !== 'development') {
|
||||
const locationKeys = [
|
||||
'homeLocation',
|
||||
'chineseHome',
|
||||
'apiLocation',
|
||||
'forumLocation',
|
||||
'newsLocation'
|
||||
'newsLocation',
|
||||
'radioLocation'
|
||||
];
|
||||
const deploymentKeys = [
|
||||
'clientLocale',
|
||||
@ -48,28 +54,49 @@ if (FREECODECAMP_NODE_ENV !== 'development') {
|
||||
searchKeys,
|
||||
donationKeys
|
||||
);
|
||||
const variables = Object.keys(env);
|
||||
const receivedvariables = Object.keys(env);
|
||||
expectedVariables.sort();
|
||||
variables.sort();
|
||||
if (expectedVariables.length !== variables.length) {
|
||||
throw Error(`Env. variable validation failed. Expected
|
||||
${expectedVariables}
|
||||
but recieved
|
||||
${variables}
|
||||
receivedvariables.sort();
|
||||
if (expectedVariables.length !== receivedvariables.length) {
|
||||
throw Error(`
|
||||
|
||||
Env. variable validation failed. Make sure these keys are used and configured.
|
||||
|
||||
Mismatch:
|
||||
${expectedVariables
|
||||
.filter(expected => !receivedvariables.includes(expected))
|
||||
.concat(
|
||||
receivedvariables.filter(
|
||||
received => !expectedVariables.includes(received)
|
||||
)
|
||||
)}
|
||||
|
||||
`);
|
||||
}
|
||||
|
||||
for (const key of expectedVariables) {
|
||||
if (typeof env[key] === 'undefined' || env[key] === null) {
|
||||
throw Error(`Env. variable ${key} is missing, build cannot continue`);
|
||||
throw Error(`
|
||||
|
||||
Env. variable ${key} is missing, build cannot continue
|
||||
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
||||
if (env['environment'] !== 'production')
|
||||
throw Error("Production environment should be 'production' ");
|
||||
throw Error(`
|
||||
|
||||
Production environment should be 'production'
|
||||
|
||||
`);
|
||||
|
||||
if (env['showUpcomingChanges'])
|
||||
throw Error("SHOW_UPCOMING_CHANGES should never be 'true' in production");
|
||||
throw Error(`
|
||||
|
||||
SHOW_UPCOMING_CHANGES should never be 'true' in production
|
||||
|
||||
`);
|
||||
|
||||
checkClientLocale();
|
||||
checkCurriculumLocale();
|
||||
|
Reference in New Issue
Block a user