MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / insertChallenge

Function insertChallenge

tools/challenge-helper-scripts/insert-task.ts:16–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14import { getInputType } from './helpers/get-input-type.js';
15
16const insertChallenge = async () => {
17 const challenges = getMetaData().challengeOrder;
18 const challengeAfterId = await select<string>({
19 message: 'Which challenge should come AFTER this new one?',
20 choices: challenges.map(({ id, title }) => ({
21 name: title,
22 value: id
23 }))
24 });
25 const challengeLang = getChallenge(challengeAfterId)?.lang;
26
27 const indexToInsert = challenges.findIndex(
28 ({ id }) => id === challengeAfterId
29 );
30
31 const newTaskTitle = 'Task 0';
32
33 const { challengeType } = await newTaskPrompts();
34
35 const inputType = await getInputType(challengeType, challengeLang);
36 const options = {
37 title: newTaskTitle,
38 dashedName: 'task-0',
39 challengeType,
40 ...{ ...(challengeLang && { challengeLang }) },
41 ...{ ...(inputType && { inputType }) }
42 };
43
44 const path = getProjectPath();
45 const template = getTemplate(challengeType);
46 const challengeId = new ObjectId();
47 const challengeText = template({ ...options, challengeId });
48
49 const challengeIdString = challengeId.toString();
50
51 createChallengeFile(challengeIdString, challengeText, path);
52 console.log('Finished creating new task markdown file.');
53
54 await insertChallengeIntoMeta({
55 index: indexToInsert,
56 id: challengeId,
57 title: newTaskTitle
58 });
59 console.log(`Finished inserting task into 'meta.json' file.`);
60
61 await updateTaskMeta();
62 console.log("Finished updating tasks in 'meta.json'.");
63
64 updateTaskMarkdownFiles();
65 console.log('Finished updating task markdown files.');
66};
67
68void insertChallenge();

Callers 1

insert-task.tsFile · 0.70

Calls 10

getMetaDataFunction · 0.85
getChallengeFunction · 0.85
newTaskPromptsFunction · 0.85
getInputTypeFunction · 0.85
getProjectPathFunction · 0.85
getTemplateFunction · 0.85
createChallengeFileFunction · 0.85
insertChallengeIntoMetaFunction · 0.85
updateTaskMetaFunction · 0.85
updateTaskMarkdownFilesFunction · 0.85

Tested by

no test coverage detected