feat(tools): create challenge helper script for quiz files (#59523)

This commit is contained in:
Anna
2025-04-10 10:56:42 -04:00
committed by GitHub
parent 48091110d5
commit b8d4099796
7 changed files with 280 additions and 401 deletions

View File

@@ -10,6 +10,7 @@ import {
isTaskChallenge,
getTaskNumberFromTitle
} from './helpers/task-helpers';
import { getTemplate } from './helpers/get-challenge-template';
interface Options {
stepNum: number;
@@ -19,6 +20,14 @@ interface Options {
isFirstChallenge?: boolean;
}
interface QuizOptions {
challengeType: string;
projectPath?: string;
title: string;
dashedName: string;
questionCount: number;
}
const createStepFile = ({
stepNum,
challengeType,
@@ -50,6 +59,28 @@ const createChallengeFile = (
fs.writeFileSync(`${path}${filename}.md`, template);
};
const createQuizFile = ({
challengeType,
projectPath = getProjectPath(),
title,
dashedName,
questionCount
}: QuizOptions): ObjectID => {
const challengeId = new ObjectID();
const template = getTemplate(challengeType);
const quizText = template({
challengeId,
challengeType,
title,
dashedName,
questionCount
});
// eslint-disable-next-line @typescript-eslint/no-base-to-string
fs.writeFileSync(`${projectPath}${challengeId.toString()}.md`, quizText);
return challengeId;
};
interface InsertOptions {
stepNum: number;
stepId: ObjectID;
@@ -225,5 +256,6 @@ export {
insertStepIntoMeta,
deleteChallengeFromMeta,
deleteStepFromMeta,
validateBlockName
validateBlockName,
createQuizFile
};