fix(env): update variable validations (#40813)
parent
58c6c54c67
commit
0b944ddfde
|
@ -1,7 +1,7 @@
|
||||||
import i18n from 'i18next';
|
import i18n from 'i18next';
|
||||||
import { initReactI18next } from 'react-i18next';
|
import { initReactI18next } from 'react-i18next';
|
||||||
|
|
||||||
const { environment, clientLocale } = require('../config/env');
|
const { clientLocale } = require('../config/env');
|
||||||
const { i18nextCodes } = require('./allLangs');
|
const { i18nextCodes } = require('./allLangs');
|
||||||
|
|
||||||
const i18nextCode = i18nextCodes[clientLocale];
|
const i18nextCode = i18nextCodes[clientLocale];
|
||||||
|
@ -20,7 +20,8 @@ i18n.use(initReactI18next).init({
|
||||||
ns: ['translations', 'trending', 'intro'],
|
ns: ['translations', 'trending', 'intro'],
|
||||||
defaultNS: 'translations',
|
defaultNS: 'translations',
|
||||||
returnObjects: true,
|
returnObjects: true,
|
||||||
debug: environment === 'development',
|
// Uncomment the next line for debug logging
|
||||||
|
// debug: true,
|
||||||
interpolation: {
|
interpolation: {
|
||||||
escapeValue: false
|
escapeValue: false
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,11 +30,13 @@ const {
|
||||||
|
|
||||||
const locations = {
|
const locations = {
|
||||||
homeLocation,
|
homeLocation,
|
||||||
|
chineseHome: !chineseHome ? 'https://chinese.freecodecamp.org' : chineseHome,
|
||||||
apiLocation,
|
apiLocation,
|
||||||
forumLocation,
|
forumLocation,
|
||||||
newsLocation,
|
newsLocation,
|
||||||
radioLocation,
|
radioLocation: !radioLocation
|
||||||
chineseHome
|
? 'https://coderadio.freecodecamp.org'
|
||||||
|
: radioLocation
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Object.assign(locations, {
|
module.exports = Object.assign(locations, {
|
||||||
|
|
|
@ -11,26 +11,32 @@ const { FREECODECAMP_NODE_ENV } = process.env;
|
||||||
|
|
||||||
function checkClientLocale() {
|
function checkClientLocale() {
|
||||||
if (!availableLangs.client.includes(process.env.CLIENT_LOCALE)) {
|
if (!availableLangs.client.includes(process.env.CLIENT_LOCALE)) {
|
||||||
throw Error(
|
throw Error(`
|
||||||
`CLIENT_LOCALE, ${process.env.CLIENT_LOCALE}, is not an available language in client/i18n/allLangs.js`
|
|
||||||
);
|
CLIENT_LOCALE, ${process.env.CLIENT_LOCALE}, is not an available language in client/i18n/allLangs.js
|
||||||
|
|
||||||
|
`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCurriculumLocale() {
|
function checkCurriculumLocale() {
|
||||||
if (!availableLangs.curriculum.includes(process.env.CURRICULUM_LOCALE)) {
|
if (!availableLangs.curriculum.includes(process.env.CURRICULUM_LOCALE)) {
|
||||||
throw Error(
|
throw Error(`
|
||||||
`CURRICULUM_LOCALE, ${process.env.CURRICULUM_LOCALE}, is not an available language in client/i18n/allLangs.js`
|
|
||||||
);
|
CURRICULUM_LOCALE, ${process.env.CURRICULUM_LOCALE}, is not an available language in client/i18n/allLangs.js
|
||||||
|
|
||||||
|
`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FREECODECAMP_NODE_ENV !== 'development') {
|
if (FREECODECAMP_NODE_ENV !== 'development') {
|
||||||
const locationKeys = [
|
const locationKeys = [
|
||||||
'homeLocation',
|
'homeLocation',
|
||||||
|
'chineseHome',
|
||||||
'apiLocation',
|
'apiLocation',
|
||||||
'forumLocation',
|
'forumLocation',
|
||||||
'newsLocation'
|
'newsLocation',
|
||||||
|
'radioLocation'
|
||||||
];
|
];
|
||||||
const deploymentKeys = [
|
const deploymentKeys = [
|
||||||
'clientLocale',
|
'clientLocale',
|
||||||
|
@ -48,28 +54,49 @@ if (FREECODECAMP_NODE_ENV !== 'development') {
|
||||||
searchKeys,
|
searchKeys,
|
||||||
donationKeys
|
donationKeys
|
||||||
);
|
);
|
||||||
const variables = Object.keys(env);
|
const receivedvariables = Object.keys(env);
|
||||||
expectedVariables.sort();
|
expectedVariables.sort();
|
||||||
variables.sort();
|
receivedvariables.sort();
|
||||||
if (expectedVariables.length !== variables.length) {
|
if (expectedVariables.length !== receivedvariables.length) {
|
||||||
throw Error(`Env. variable validation failed. Expected
|
throw Error(`
|
||||||
${expectedVariables}
|
|
||||||
but recieved
|
Env. variable validation failed. Make sure these keys are used and configured.
|
||||||
${variables}
|
|
||||||
|
Mismatch:
|
||||||
|
${expectedVariables
|
||||||
|
.filter(expected => !receivedvariables.includes(expected))
|
||||||
|
.concat(
|
||||||
|
receivedvariables.filter(
|
||||||
|
received => !expectedVariables.includes(received)
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const key of expectedVariables) {
|
for (const key of expectedVariables) {
|
||||||
if (typeof env[key] === 'undefined' || env[key] === null) {
|
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')
|
if (env['environment'] !== 'production')
|
||||||
throw Error("Production environment should be 'production' ");
|
throw Error(`
|
||||||
|
|
||||||
|
Production environment should be 'production'
|
||||||
|
|
||||||
|
`);
|
||||||
|
|
||||||
if (env['showUpcomingChanges'])
|
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();
|
checkClientLocale();
|
||||||
checkCurriculumLocale();
|
checkCurriculumLocale();
|
||||||
|
|
Loading…
Reference in New Issue