Skip to content

Commit 8f480d8

Browse files
fix(challenge-helper-scripts): create quiz project challenges in correct folder (freeCodeCamp#64144)
Co-authored-by: Huyen Nguyen <[email protected]>
1 parent 35c73a1 commit 8f480d8

File tree

4 files changed

+19
-39
lines changed

4 files changed

+19
-39
lines changed

curriculum/src/file-handler.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dirname, resolve } from 'node:path';
22
import assert from 'node:assert';
33
import { existsSync, readFileSync } from 'node:fs';
4-
import { writeFile } from 'node:fs/promises';
4+
import { mkdir, writeFile } from 'node:fs/promises';
55
import { fileURLToPath } from 'node:url';
66
import debug from 'debug';
77

@@ -173,6 +173,16 @@ export interface BlockStructure {
173173
module?: string;
174174
}
175175

176+
export async function createBlockFolder(block: string) {
177+
const { blockContentDir } = getContentConfig('english') as {
178+
blockContentDir: string;
179+
};
180+
181+
const newBlockDir = resolve(blockContentDir, block);
182+
await mkdir(newBlockDir, { recursive: true });
183+
return newBlockDir + '/';
184+
}
185+
176186
export function getBlockStructure(block: string) {
177187
return JSON.parse(
178188
readFileSync(getBlockStructurePath(block), 'utf8')

tools/challenge-helper-scripts/create-language-block.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fs from 'fs/promises';
2-
import { existsSync } from 'fs';
32
import path from 'path';
43
import { prompt } from 'inquirer';
54
import { format } from 'prettier';
@@ -15,7 +14,8 @@ import { BlockLayouts, BlockLabel } from '../../shared/config/blocks';
1514
import {
1615
getContentConfig,
1716
writeBlockStructure,
18-
getSuperblockStructure
17+
getSuperblockStructure,
18+
createBlockFolder
1919
} from '../../curriculum/src/file-handler';
2020
import { superBlockToFilename } from '../../curriculum/src/build-curriculum';
2121
import { getBaseMeta } from './helpers/get-base-meta';
@@ -211,16 +211,8 @@ async function createQuizChallenge(
211211
questionCount: number,
212212
challengeLang: string
213213
): Promise<ObjectID> {
214-
const { blockContentDir } = getContentConfig('english') as {
215-
blockContentDir: string;
216-
};
217-
218-
const newChallengeDir = path.resolve(blockContentDir, block);
219-
if (!existsSync(newChallengeDir)) {
220-
await withTrace(fs.mkdir, newChallengeDir);
221-
}
222214
return createQuizFile({
223-
projectPath: newChallengeDir + '/',
215+
projectPath: await createBlockFolder(block),
224216
title: title,
225217
dashedName: block,
226218
questionCount: questionCount,

tools/challenge-helper-scripts/create-project.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { existsSync } from 'fs';
21
import fs from 'fs/promises';
32
import path from 'path';
43
import { prompt } from 'inquirer';
@@ -11,7 +10,7 @@ import {
1110
} from '../../shared/config/curriculum';
1211
import { BlockLayouts, BlockLabel } from '../../shared/config/blocks';
1312
import {
14-
getContentConfig,
13+
createBlockFolder,
1514
writeBlockStructure
1615
} from '../../curriculum/src/file-handler';
1716
import { superBlockToFilename } from '../../curriculum/src/build-curriculum';
@@ -209,13 +208,6 @@ async function createMetaJson(
209208
}
210209

211210
async function createFirstChallenge(block: string): Promise<ObjectID> {
212-
const { blockContentDir } = getContentConfig('english') as {
213-
blockContentDir: string;
214-
};
215-
216-
const newChallengeDir = path.resolve(blockContentDir, block);
217-
await fs.mkdir(newChallengeDir, { recursive: true });
218-
219211
// TODO: would be nice if the extension made sense for the challenge, but, at
220212
// least until react I think they're all going to be html anyway.
221213
const challengeSeeds = [
@@ -227,7 +219,7 @@ async function createFirstChallenge(block: string): Promise<ObjectID> {
227219
];
228220
// including trailing slash for compatibility with createStepFile
229221
return createStepFile({
230-
projectPath: newChallengeDir + '/',
222+
projectPath: await createBlockFolder(block),
231223
stepNum: 1,
232224
challengeType: 0,
233225
challengeSeeds,
@@ -240,15 +232,8 @@ async function createQuizChallenge(
240232
title: string,
241233
questionCount: number
242234
): Promise<ObjectID> {
243-
const newChallengeDir = path.resolve(
244-
__dirname,
245-
`../../curriculum/challenges/english/${block}`
246-
);
247-
if (!existsSync(newChallengeDir)) {
248-
await withTrace(fs.mkdir, newChallengeDir);
249-
}
250235
return createQuizFile({
251-
projectPath: newChallengeDir + '/',
236+
projectPath: await createBlockFolder(block),
252237
title: title,
253238
dashedName: block,
254239
questionCount: questionCount

tools/challenge-helper-scripts/create-quiz.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ObjectID from 'bson-objectid';
66

77
import { SuperBlocks } from '../../shared/config/curriculum';
88
import {
9-
getContentConfig,
9+
createBlockFolder,
1010
writeBlockStructure
1111
} from '../../curriculum/src/file-handler';
1212
import { superBlockToFilename } from '../../curriculum/src/build-curriculum';
@@ -111,15 +111,8 @@ async function createQuizChallenge(
111111
title: string,
112112
questionCount: number
113113
): Promise<ObjectID> {
114-
const { blockContentDir } = getContentConfig('english') as {
115-
blockContentDir: string;
116-
};
117-
118-
const newChallengeDir = path.resolve(blockContentDir, block);
119-
await fs.mkdir(newChallengeDir, { recursive: true });
120-
121114
return createQuizFile({
122-
projectPath: newChallengeDir + '/',
115+
projectPath: await createBlockFolder(block),
123116
title: title,
124117
dashedName: block,
125118
questionCount: questionCount

0 commit comments

Comments
 (0)