chore: use constants for superblocks (#43886)
* chore: use constants for superblocks * add prettier ts dec to challenge-helper-scripts * config/ to ts. broken * typescripterise tools/ and config/ * create global tsconfig, remove alternate configs * delete temp ts->js, add to gitignore * fix gitignore * re-import SuperBlocks in super-block-intro.tsx * remove renamed files added again * fix config * remove accidental files * remove snap * delete built files * adjust eslintrc for enums * add node types to root * ignore build files in lint and prettier * fix tools/ in tsconfig * ignore annoying ts warnings * prettierise Map/index.tsx * fix enum to match lint rule * rejig Map to render RWD superblock * 'pretty minor' - implicitly tsc within root Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix client/package.json for Gitpod * broken: migrate @types to root * fix: use typeRoots to prevent duplication * fix show.tsx, try typeroots in root * silly fix for duplicate node_modules types * remove typeRoots from root * fix: tsconfig or not tsconfig, that is the... * fix: ...question: Whether 'tis nobler in the mind to suffer the slings and arrows of outrageous configs... * fix: Or to take Arms against a Sea of lint errors And by opposing end them Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
134
tools/scripts/build/ensure-env.ts
Normal file
134
tools/scripts/build/ensure-env.ts
Normal file
@ -0,0 +1,134 @@
|
||||
import { spawn } from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import { availableLangs } from '../../../config/i18n/all-langs';
|
||||
|
||||
// eslint-disable-next-line
|
||||
const env = require('../../../config/read-env.js');
|
||||
|
||||
const globalConfigPath = path.resolve(__dirname, '../../../config');
|
||||
|
||||
const { FREECODECAMP_NODE_ENV } = process.env;
|
||||
|
||||
function checkClientLocale() {
|
||||
if (!availableLangs.client.includes(process.env.CLIENT_LOCALE)) {
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
throw Error(`
|
||||
|
||||
CLIENT_LOCALE, ${process.env.CLIENT_LOCALE}, is not an available language in config/i18n/all-langs.js
|
||||
|
||||
`);
|
||||
/* eslint-enable @typescript-eslint/restrict-template-expressions */
|
||||
}
|
||||
}
|
||||
|
||||
function checkCurriculumLocale() {
|
||||
if (!availableLangs.curriculum.includes(process.env.CURRICULUM_LOCALE)) {
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
throw Error(`
|
||||
|
||||
CURRICULUM_LOCALE, ${process.env.CURRICULUM_LOCALE}, is not an available language in config/i18n/all-langs.js
|
||||
|
||||
`);
|
||||
/* eslint-enable @typescript-eslint/restrict-template-expressions */
|
||||
}
|
||||
}
|
||||
|
||||
if (FREECODECAMP_NODE_ENV !== 'development') {
|
||||
const locationKeys = [
|
||||
'homeLocation',
|
||||
'apiLocation',
|
||||
'forumLocation',
|
||||
'newsLocation',
|
||||
'radioLocation'
|
||||
];
|
||||
const deploymentKeys = [
|
||||
'clientLocale',
|
||||
'curriculumLocale',
|
||||
'showLocaleDropdownMenu',
|
||||
'deploymentEnv',
|
||||
'environment',
|
||||
'showUpcomingChanges'
|
||||
];
|
||||
const searchKeys = ['algoliaAppId', 'algoliaAPIKey'];
|
||||
const donationKeys = ['stripePublicKey', 'paypalClientId', 'patreonClientId'];
|
||||
|
||||
const expectedVariables = locationKeys.concat(
|
||||
deploymentKeys,
|
||||
searchKeys,
|
||||
donationKeys
|
||||
);
|
||||
const receivedvariables = Object.keys(env);
|
||||
expectedVariables.sort();
|
||||
receivedvariables.sort();
|
||||
if (expectedVariables.length !== receivedvariables.length) {
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
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)
|
||||
)
|
||||
)}
|
||||
|
||||
`);
|
||||
/* eslint-enable @typescript-eslint/restrict-template-expressions */
|
||||
}
|
||||
|
||||
for (const key of expectedVariables) {
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
if (typeof env[key] === 'undefined' || env[key] === null) {
|
||||
throw Error(`
|
||||
|
||||
Env. variable ${key} is missing, build cannot continue
|
||||
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
||||
if (env['environment'] !== 'production')
|
||||
throw Error(`
|
||||
|
||||
Production environment should be 'production'
|
||||
|
||||
`);
|
||||
|
||||
if (env['showUpcomingChanges'])
|
||||
throw Error(`
|
||||
|
||||
SHOW_UPCOMING_CHANGES should never be 'true' in production
|
||||
|
||||
`);
|
||||
|
||||
checkClientLocale();
|
||||
checkCurriculumLocale();
|
||||
} else {
|
||||
checkClientLocale();
|
||||
checkCurriculumLocale();
|
||||
if (fs.existsSync(`${globalConfigPath}/env.json`)) {
|
||||
// eslint-disable-next-line
|
||||
const { showUpcomingChanges } = require(`${globalConfigPath}/env.json`);
|
||||
if (env['showUpcomingChanges'] !== showUpcomingChanges) {
|
||||
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
|
||||
console.log(
|
||||
'SHOW_UPCOMING_CHANGES value has changed, cleaning client cache.'
|
||||
);
|
||||
const child = spawn('npm', ['run', 'clean:client']);
|
||||
child.stdout.setEncoding('utf8');
|
||||
child.stdout.on('data', function (data) {
|
||||
console.log(data);
|
||||
});
|
||||
child.on('error', err => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(`${globalConfigPath}/env.json`, JSON.stringify(env));
|
Reference in New Issue
Block a user