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:
Shaun Hamilton
2021-11-19 14:19:40 +00:00
committed by GitHub
parent d944fa0c8e
commit d75e43a1e7
29 changed files with 1391 additions and 262 deletions

View File

@@ -4,25 +4,10 @@ import path from 'path';
import { prompt } from 'inquirer';
import { format } from 'prettier';
import { SuperBlocks } from '../../config/certification-settings';
import { blockNameify } from '../../utils/block-nameify';
import { createStepFile } from './utils.js';
const superBlocks = [
'responsive-web-design',
'javascript-algorithms-and-data-structures',
'front-end-development-libraries',
'data-visualization',
'back-end-development-and-apis',
'quality-assurance',
'scientific-computing-with-python',
'data-analysis-with-python',
'information-security',
'machine-learning-with-python',
'coding-interview-prep'
] as const;
type SuperBlock = typeof superBlocks[number];
const helpCategories = ['HTML-CSS', 'JavaScript', 'Python'] as const;
type BlockInfo = {
@@ -34,7 +19,7 @@ type SuperBlockInfo = {
blocks: Record<string, BlockInfo>;
};
type IntroJson = Record<SuperBlock, SuperBlockInfo>;
type IntroJson = Record<SuperBlocks, SuperBlockInfo>;
type Meta = {
name: string;
@@ -51,7 +36,7 @@ type Meta = {
};
async function createProject(
superBlock: SuperBlock,
superBlock: SuperBlocks,
block: string,
helpCategory: string,
order: number,
@@ -86,7 +71,7 @@ async function createProject(
}
async function updateIntroJson(
superBlock: SuperBlock,
superBlock: SuperBlocks,
block: string,
title: string
) {
@@ -138,7 +123,7 @@ async function updateBlockNames(block: string, title: string) {
}
async function createMetaJson(
superBlock: SuperBlock,
superBlock: SuperBlocks,
block: string,
title: string,
order: number,
@@ -149,7 +134,7 @@ async function createMetaJson(
newMeta.name = title;
newMeta.dashedName = block;
newMeta.order = order;
newMeta.superOrder = superBlocks.indexOf(superBlock) + 1;
newMeta.superOrder = Object.values(SuperBlocks).indexOf(superBlock) + 1;
newMeta.superBlock = superBlock;
newMeta.challengeOrder = [[challengeId, 'Step 1']];
const newMetaDir = path.resolve(metaDir, block);
@@ -190,10 +175,10 @@ This is a test for the new project-based curriculum.
}
async function createFirstChallenge(
superBlock: SuperBlock,
superBlock: SuperBlocks,
block: string
): Promise<string> {
const superBlockId = (superBlocks.indexOf(superBlock) + 1)
const superBlockId = (Object.values(SuperBlocks).indexOf(superBlock) + 1)
.toString()
.padStart(2, '0');
const newChallengeDir = path.resolve(
@@ -234,9 +219,9 @@ prompt([
{
name: 'superBlock',
message: 'Which certification does this belong to?',
default: 'responsive-web-design',
default: SuperBlocks.RespWebDesign,
type: 'list',
choices: superBlocks
choices: SuperBlocks
},
{
name: 'block',

View File

@@ -23,8 +23,6 @@
"create-project": "ts-node create-project"
},
"devDependencies": {
"@types/inquirer": "7.3.3",
"@types/node": "16.11.7",
"bson-objectid": "2.0.1",
"cross-env": "7.0.3",
"gray-matter": "4.0.3",

View File

@@ -1,12 +0,0 @@
{
"compilerOptions": {
"target": "ES2020",
"noEmit": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}

View File

@@ -1,9 +1,11 @@
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
import { spawn } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
const { availableLangs } = require('../../../config/i18n/all-langs');
const env = require('../../../config/read-env');
import { availableLangs } from '../../../config/i18n/all-langs';
// eslint-disable-next-line
const env = require('../../../config/read-env.js');
const globalConfigPath = path.resolve(__dirname, '../../../config');
@@ -11,21 +13,25 @@ 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 */
}
}
@@ -57,6 +63,7 @@ if (FREECODECAMP_NODE_ENV !== 'development') {
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.
@@ -71,9 +78,11 @@ if (FREECODECAMP_NODE_ENV !== 'development') {
)}
`);
/* 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(`
@@ -86,16 +95,16 @@ if (FREECODECAMP_NODE_ENV !== 'development') {
if (env['environment'] !== 'production')
throw Error(`
Production environment should be 'production'
Production environment should be 'production'
`);
`);
if (env['showUpcomingChanges'])
throw Error(`
SHOW_UPCOMING_CHANGES should never be 'true' in production
SHOW_UPCOMING_CHANGES should never be 'true' in production
`);
`);
checkClientLocale();
checkCurriculumLocale();
@@ -103,8 +112,10 @@ if (FREECODECAMP_NODE_ENV !== 'development') {
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.'
);

View File

@@ -0,0 +1,6 @@
{
"compilerOptions": {
"typeRoots": ["../../node_modules/@types"],
"types": ["node"]
}
}

View File

@@ -20,7 +20,6 @@
"homepage": "https://github.com/freeCodeCamp/freeCodeCamp#readme",
"dependencies": {
"@babel/preset-typescript": "7.16.0",
"@types/jest": "27.0.2",
"@types/node": "16.11.7",
"@types/react": "17.0.33",
"@types/react-dom": "17.0.11",
@@ -39,18 +38,20 @@
"@storybook/addon-links": "6.3.12",
"@storybook/addon-postcss": "2.0.0",
"@storybook/react": "6.3.12",
"@testing-library/jest-dom": "^5.15.0",
"@testing-library/react": "12.1.2",
"@types/jest": "^27.0.2",
"autoprefixer": "10.4.0",
"babel-loader": "8.2.3",
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
"cross-env": "7.0.3",
"postcss": "8.3.11",
"postcss-import": "14.0.2",
"tailwindcss": "2.2.19",
"rimraf": "3.0.2",
"rollup": "2.60.0",
"rollup-plugin-postcss": "4.0.1",
"rollup-plugin-terser": "7.0.2"
"rollup-plugin-terser": "7.0.2",
"tailwindcss": "2.2.19"
},
"scripts": {
"storybook": "start-storybook -p 6006",

View File

@@ -8,6 +8,7 @@
"esModuleInterop": true,
"moduleResolution": "node",
"strict": true,
"noEmit": true
"noEmit": true,
"typeRoots": ["./node_modules/@types"]
}
}