fix(challenge-helper-scripts): create quiz project challenges in correct folder (#64144)

Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
This commit is contained in:
Oliver Eyton-Williams
2025-11-26 14:04:49 -08:00
committed by GitHub
co-authored by Huyen Nguyen
parent 35c73a1503
commit 8f480d8cdf
4 changed files with 19 additions and 39 deletions
+11 -1
View File
@@ -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')
@@ -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<ObjectID> {
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,
@@ -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<ObjectID> {
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<ObjectID> {
];
// 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<ObjectID> {
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
@@ -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<ObjectID> {
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