mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-19 18:18:27 -05:00
feat(tools): create challenge helper script for quiz files (#59523)
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user