From c4a4abe487f3984eaedf87f9465c039f2a4fb710 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 26 Sep 2025 02:04:45 -0400 Subject: [PATCH] fix(tools): allow more chapter based superblocks (#62203) --- .../create-project.ts | 69 +++++++++++++------ .../helpers/create-project.ts | 2 +- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/tools/challenge-helper-scripts/create-project.ts b/tools/challenge-helper-scripts/create-project.ts index 3380fb83380..56c14f94126 100644 --- a/tools/challenge-helper-scripts/create-project.ts +++ b/tools/challenge-helper-scripts/create-project.ts @@ -5,8 +5,10 @@ import { prompt } from 'inquirer'; import { format } from 'prettier'; import ObjectID from 'bson-objectid'; -import fullStackData from '../../curriculum/structure/superblocks/full-stack-developer.json'; -import { SuperBlocks } from '../../shared/config/curriculum'; +import { + SuperBlocks, + chapterBasedSuperBlocks +} from '../../shared/config/curriculum'; import { BlockLayouts, BlockTypes } from '../../shared/config/blocks'; import { getContentConfig, @@ -17,6 +19,7 @@ import { createQuizFile, createStepFile, validateBlockName } from './utils'; import { getBaseMeta } from './helpers/get-base-meta'; import { createIntroMD } from './helpers/create-intro'; import { + ChapterModuleSuperblockStructure, updateChapterModuleSuperblockStructure, updateSimpleSuperblockStructure } from './helpers/create-project'; @@ -71,7 +74,7 @@ async function createProject(projectArgs: CreateProjectArgs) { superBlockToFilename as Record )[projectArgs.superBlock]; - if (projectArgs.superBlock === SuperBlocks.FullStackDeveloper) { + if (chapterBasedSuperBlocks.includes(projectArgs.superBlock)) { if (!chapter || !module || typeof position == 'undefined') { throw Error( 'Missing one of the following arguments: chapter, module, position' @@ -133,7 +136,7 @@ async function createProject(projectArgs: CreateProjectArgs) { } if ( - (projectArgs.superBlock === SuperBlocks.FullStackDeveloper && + (chapterBasedSuperBlocks.includes(projectArgs.superBlock) && projectArgs.blockType) == null ) { throw new Error('Missing argument: blockType when updating intro markdown'); @@ -178,7 +181,7 @@ async function createMetaJson( blockLayout?: string ) { let newMeta; - if (superBlock === SuperBlocks.FullStackDeveloper) { + if (chapterBasedSuperBlocks.includes(superBlock)) { newMeta = getBaseMeta('FullStack'); newMeta.blockType = blockType; newMeta.blockLayout = blockLayout; @@ -262,6 +265,31 @@ function withTrace( }); } +async function getChapters(superBlock: string) { + const blockMetaFile = await fs.readFile( + '../../curriculum/structure/superblocks/' + superBlock + '.json', + { encoding: 'utf8' } + ); + const blockMetaData = JSON.parse( + blockMetaFile + ) as ChapterModuleSuperblockStructure; + return blockMetaData.chapters; +} + +async function getModules(superBlock: string, chapterName: string) { + const blockMetaFile = await fs.readFile( + '../../curriculum/structure/superblocks/' + superBlock + '.json', + { encoding: 'utf8' } + ); + const blockMetaData = JSON.parse( + blockMetaFile + ) as ChapterModuleSuperblockStructure; + const modifiedChapter = blockMetaData.chapters.find( + x => x.dashedName === chapterName + ); + return modifiedChapter?.modules; +} + void prompt([ { name: 'superBlock', @@ -296,7 +324,7 @@ void prompt([ type: 'list', choices: Object.values(BlockTypes), when: (answers: CreateProjectArgs) => - answers.superBlock === SuperBlocks.FullStackDeveloper + chapterBasedSuperBlocks.includes(answers.superBlock) }, { name: 'blockLayout', @@ -309,7 +337,7 @@ void prompt([ type: 'list', choices: Object.values(BlockLayouts), when: (answers: CreateProjectArgs) => - answers.superBlock === SuperBlocks.FullStackDeveloper + chapterBasedSuperBlocks.includes(answers.superBlock) }, { name: 'questionCount', @@ -321,26 +349,27 @@ void prompt([ }, { name: 'chapter', - message: - 'What chapter in full-stack.json should this full stack project go in?', + message: 'What chapter should this project go in?', default: 'html', type: 'list', - choices: fullStackData.chapters.map(x => x.dashedName), + choices: async (answers: CreateProjectArgs) => { + const chapters = await getChapters(answers.superBlock); + return chapters.map(x => x.dashedName); + }, when: (answers: CreateProjectArgs) => - answers.superBlock === SuperBlocks.FullStackDeveloper + chapterBasedSuperBlocks.includes(answers.superBlock) }, { name: 'module', - message: - 'What module in full-stack.json should this full stack project go in?', + message: 'What module should this project go in?', default: 'html', type: 'list', - choices: (answers: CreateProjectArgs) => - fullStackData.chapters - .find(x => x.dashedName === answers.chapter) - ?.modules.map(x => x.dashedName), + choices: async (answers: CreateProjectArgs) => { + const modules = await getModules(answers.superBlock, answers.chapter!); + return modules!.map(x => x.dashedName); + }, when: (answers: CreateProjectArgs) => - answers.superBlock === SuperBlocks.FullStackDeveloper + chapterBasedSuperBlocks.includes(answers.superBlock) }, { name: 'position', @@ -352,7 +381,7 @@ void prompt([ : 'Position must be an number greater than zero.'; }, when: (answers: CreateProjectArgs) => - answers.superBlock === SuperBlocks.FullStackDeveloper, + chapterBasedSuperBlocks.includes(answers.superBlock), filter: (position: string) => { return parseInt(position, 10); } @@ -367,7 +396,7 @@ void prompt([ : 'Order must be an number greater than zero.'; }, when: (answers: CreateProjectArgs) => - answers.superBlock !== SuperBlocks.FullStackDeveloper, + !chapterBasedSuperBlocks.includes(answers.superBlock), filter: (order: string) => { return parseInt(order, 10); } diff --git a/tools/challenge-helper-scripts/helpers/create-project.ts b/tools/challenge-helper-scripts/helpers/create-project.ts index 10be07828da..05f36624077 100644 --- a/tools/challenge-helper-scripts/helpers/create-project.ts +++ b/tools/challenge-helper-scripts/helpers/create-project.ts @@ -45,7 +45,7 @@ function createNewModule(module: string, block: string) { }; } -type ChapterModuleSuperblockStructure = { +export type ChapterModuleSuperblockStructure = { chapters: { dashedName: string; modules: {