From 8f480d8cdfdd0ff8ad5be602e0d0d0ddc9ca4c4b Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Wed, 26 Nov 2025 23:04:49 +0100 Subject: [PATCH] fix(challenge-helper-scripts): create quiz project challenges in correct folder (#64144) Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com> --- curriculum/src/file-handler.ts | 12 ++++++++++- .../create-language-block.ts | 14 +++---------- .../create-project.ts | 21 +++---------------- tools/challenge-helper-scripts/create-quiz.ts | 11 ++-------- 4 files changed, 19 insertions(+), 39 deletions(-) diff --git a/curriculum/src/file-handler.ts b/curriculum/src/file-handler.ts index dff790112ab..0049432957e 100644 --- a/curriculum/src/file-handler.ts +++ b/curriculum/src/file-handler.ts @@ -1,7 +1,7 @@ import { dirname, resolve } from 'node:path'; import assert from 'node:assert'; import { existsSync, readFileSync } from 'node:fs'; -import { writeFile } from 'node:fs/promises'; +import { mkdir, writeFile } from 'node:fs/promises'; import { fileURLToPath } from 'node:url'; import debug from 'debug'; @@ -173,6 +173,16 @@ export interface BlockStructure { module?: string; } +export async function createBlockFolder(block: string) { + const { blockContentDir } = getContentConfig('english') as { + blockContentDir: string; + }; + + const newBlockDir = resolve(blockContentDir, block); + await mkdir(newBlockDir, { recursive: true }); + return newBlockDir + '/'; +} + export function getBlockStructure(block: string) { return JSON.parse( readFileSync(getBlockStructurePath(block), 'utf8') diff --git a/tools/challenge-helper-scripts/create-language-block.ts b/tools/challenge-helper-scripts/create-language-block.ts index 00b0c4d3c40..a6e0272b8cf 100644 --- a/tools/challenge-helper-scripts/create-language-block.ts +++ b/tools/challenge-helper-scripts/create-language-block.ts @@ -1,5 +1,4 @@ import fs from 'fs/promises'; -import { existsSync } from 'fs'; import path from 'path'; import { prompt } from 'inquirer'; import { format } from 'prettier'; @@ -15,7 +14,8 @@ import { BlockLayouts, BlockLabel } from '../../shared/config/blocks'; import { getContentConfig, writeBlockStructure, - getSuperblockStructure + getSuperblockStructure, + createBlockFolder } from '../../curriculum/src/file-handler'; import { superBlockToFilename } from '../../curriculum/src/build-curriculum'; import { getBaseMeta } from './helpers/get-base-meta'; @@ -211,16 +211,8 @@ async function createQuizChallenge( questionCount: number, challengeLang: string ): Promise { - const { blockContentDir } = getContentConfig('english') as { - blockContentDir: string; - }; - - const newChallengeDir = path.resolve(blockContentDir, block); - if (!existsSync(newChallengeDir)) { - await withTrace(fs.mkdir, newChallengeDir); - } return createQuizFile({ - projectPath: newChallengeDir + '/', + projectPath: await createBlockFolder(block), title: title, dashedName: block, questionCount: questionCount, diff --git a/tools/challenge-helper-scripts/create-project.ts b/tools/challenge-helper-scripts/create-project.ts index d7b0b15d66d..b7243b11efb 100644 --- a/tools/challenge-helper-scripts/create-project.ts +++ b/tools/challenge-helper-scripts/create-project.ts @@ -1,4 +1,3 @@ -import { existsSync } from 'fs'; import fs from 'fs/promises'; import path from 'path'; import { prompt } from 'inquirer'; @@ -11,7 +10,7 @@ import { } from '../../shared/config/curriculum'; import { BlockLayouts, BlockLabel } from '../../shared/config/blocks'; import { - getContentConfig, + createBlockFolder, writeBlockStructure } from '../../curriculum/src/file-handler'; import { superBlockToFilename } from '../../curriculum/src/build-curriculum'; @@ -209,13 +208,6 @@ async function createMetaJson( } async function createFirstChallenge(block: string): Promise { - const { blockContentDir } = getContentConfig('english') as { - blockContentDir: string; - }; - - const newChallengeDir = path.resolve(blockContentDir, block); - await fs.mkdir(newChallengeDir, { recursive: true }); - // TODO: would be nice if the extension made sense for the challenge, but, at // least until react I think they're all going to be html anyway. const challengeSeeds = [ @@ -227,7 +219,7 @@ async function createFirstChallenge(block: string): Promise { ]; // including trailing slash for compatibility with createStepFile return createStepFile({ - projectPath: newChallengeDir + '/', + projectPath: await createBlockFolder(block), stepNum: 1, challengeType: 0, challengeSeeds, @@ -240,15 +232,8 @@ async function createQuizChallenge( title: string, questionCount: number ): Promise { - const newChallengeDir = path.resolve( - __dirname, - `../../curriculum/challenges/english/${block}` - ); - if (!existsSync(newChallengeDir)) { - await withTrace(fs.mkdir, newChallengeDir); - } return createQuizFile({ - projectPath: newChallengeDir + '/', + projectPath: await createBlockFolder(block), title: title, dashedName: block, questionCount: questionCount diff --git a/tools/challenge-helper-scripts/create-quiz.ts b/tools/challenge-helper-scripts/create-quiz.ts index 1eeff584e0d..20014540311 100644 --- a/tools/challenge-helper-scripts/create-quiz.ts +++ b/tools/challenge-helper-scripts/create-quiz.ts @@ -6,7 +6,7 @@ import ObjectID from 'bson-objectid'; import { SuperBlocks } from '../../shared/config/curriculum'; import { - getContentConfig, + createBlockFolder, writeBlockStructure } from '../../curriculum/src/file-handler'; import { superBlockToFilename } from '../../curriculum/src/build-curriculum'; @@ -111,15 +111,8 @@ async function createQuizChallenge( title: string, questionCount: number ): Promise { - const { blockContentDir } = getContentConfig('english') as { - blockContentDir: string; - }; - - const newChallengeDir = path.resolve(blockContentDir, block); - await fs.mkdir(newChallengeDir, { recursive: true }); - return createQuizFile({ - projectPath: newChallengeDir + '/', + projectPath: await createBlockFolder(block), title: title, dashedName: block, questionCount: questionCount