fix(tools): curriculum command line helpers (#61831)

This commit is contained in:
Oliver Eyton-Williams
2025-09-02 16:03:28 +02:00
committed by GitHub
parent c58ba56eeb
commit 10c565828e
40 changed files with 773 additions and 1010 deletions

View File

@@ -1,17 +1,19 @@
import { existsSync } from 'fs';
import fs from 'fs/promises';
import path from 'path';
import { prompt } from 'inquirer';
import { format } from 'prettier';
import ObjectID from 'bson-objectid';
import { SuperBlocks } from '../../shared/config/curriculum';
import {
SuperBlocks,
superBlockToFolderMap
} from '../../shared/config/curriculum';
getContentConfig,
writeBlockStructure
} from '../../curriculum/file-handler';
import { superBlockToFilename } from '../../curriculum/build-curriculum';
import { createQuizFile, validateBlockName } from './utils';
import { getBaseMeta } from './helpers/get-base-meta';
import { createIntroMD } from './helpers/create-intro';
import { updateSimpleSuperblockStructure } from './helpers/create-project';
const helpCategories = [
'HTML-CSS',
@@ -57,7 +59,11 @@ async function createQuiz(
title,
questionCount
);
await createMetaJson(superBlock, block, title, helpCategory, challengeId);
await createMetaJson(block, title, helpCategory, challengeId);
const superblockFilename = (
superBlockToFilename as Record<SuperBlocks, string>
)[superBlock];
void updateSimpleSuperblockStructure(block, { order: 0 }, superblockFilename);
// TODO: remove once we stop relying on markdown in the client.
await createIntroMD(superBlock, block, title);
}
@@ -84,30 +90,19 @@ async function updateIntroJson(
}
async function createMetaJson(
superBlock: SuperBlocks,
block: string,
title: string,
helpCategory: string,
challengeId: ObjectID
) {
const metaDir = path.resolve(__dirname, '../../curriculum/challenges/_meta');
const newMeta = getBaseMeta('Quiz');
newMeta.name = title;
newMeta.dashedName = block;
newMeta.helpCategory = helpCategory;
newMeta.superBlock = superBlock;
// eslint-disable-next-line @typescript-eslint/no-base-to-string
newMeta.challengeOrder = [{ id: challengeId.toString(), title: title }];
const newMetaDir = path.resolve(metaDir, block);
if (!existsSync(newMetaDir)) {
await withTrace(fs.mkdir, newMetaDir);
}
void withTrace(
fs.writeFile,
path.resolve(metaDir, `${block}/meta.json`),
await format(JSON.stringify(newMeta), { parser: 'json' })
);
await writeBlockStructure(block, newMeta);
}
async function createQuizChallenge(
@@ -116,14 +111,13 @@ async function createQuizChallenge(
title: string,
questionCount: number
): Promise<ObjectID> {
const superBlockSubPath = superBlockToFolderMap[superBlock];
const newChallengeDir = path.resolve(
__dirname,
`../../curriculum/challenges/english/${superBlockSubPath}/${block}`
);
if (!existsSync(newChallengeDir)) {
await withTrace(fs.mkdir, newChallengeDir);
}
const { blockContentDir } = getContentConfig('english') as {
blockContentDir: string;
};
const newChallengeDir = path.resolve(blockContentDir, block);
await fs.mkdir(newChallengeDir, { recursive: true });
return createQuizFile({
projectPath: newChallengeDir + '/',
title: title,