diff --git a/tools/challenge-helper-scripts/create-language-block.ts b/tools/challenge-helper-scripts/create-language-block.ts index cf2c307d392..13cea2d6f27 100644 --- a/tools/challenge-helper-scripts/create-language-block.ts +++ b/tools/challenge-helper-scripts/create-language-block.ts @@ -12,6 +12,7 @@ import { } from '../../shared/config/curriculum'; import { createDialogueFile, validateBlockName } from './utils'; import { getBaseMeta } from './helpers/get-base-meta'; +import { createIntroMD } from './helpers/create-intro'; const helpCategories = ['English'] as const; @@ -42,12 +43,12 @@ async function createLanguageBlock( if (!title) { title = block; } - void updateIntroJson(superBlock, block, title); + await updateIntroJson(superBlock, block, title); const challengeId = await createDialogueChallenge(superBlock, block); - void createMetaJson(superBlock, block, title, helpCategory, challengeId); + await createMetaJson(superBlock, block, title, helpCategory, challengeId); // TODO: remove once we stop relying on markdown in the client. - void createIntroMD(superBlock, block, title); + await createIntroMD(superBlock, block, title); } async function updateIntroJson( @@ -100,28 +101,6 @@ async function createMetaJson( ); } -async function createIntroMD(superBlock: string, block: string, title: string) { - const introMD = `--- -title: Introduction to the ${title} -block: ${block} -superBlock: ${superBlock} ---- - -## Introduction to the ${title} - -This page is for the ${title} -`; - const dirPath = path.resolve( - __dirname, - `../../client/src/pages/learn/${superBlock}/${block}/` - ); - const filePath = path.resolve(dirPath, 'index.md'); - if (!existsSync(dirPath)) { - await withTrace(fs.mkdir, dirPath); - } - void withTrace(fs.writeFile, filePath, introMD, { encoding: 'utf8' }); -} - async function createDialogueChallenge( superBlock: SuperBlocks, block: string diff --git a/tools/challenge-helper-scripts/create-project.ts b/tools/challenge-helper-scripts/create-project.ts index 51372498ef1..79ce960de03 100644 --- a/tools/challenge-helper-scripts/create-project.ts +++ b/tools/challenge-helper-scripts/create-project.ts @@ -11,6 +11,7 @@ import { } from '../../shared/config/curriculum'; import { createStepFile, validateBlockName } from './utils'; import { getBaseMeta } from './helpers/get-base-meta'; +import { createIntroMD } from './helpers/create-intro'; const helpCategories = [ 'HTML-CSS', @@ -117,28 +118,6 @@ async function createMetaJson( ); } -async function createIntroMD(superBlock: string, block: string, title: string) { - const introMD = `--- -title: Introduction to the ${title} -block: ${block} -superBlock: ${superBlock} ---- - -## Introduction to the ${title} - -This is a test for the new project-based curriculum. -`; - const dirPath = path.resolve( - __dirname, - `../../client/src/pages/learn/${superBlock}/${block}/` - ); - const filePath = path.resolve(dirPath, 'index.md'); - if (!existsSync(dirPath)) { - await withTrace(fs.mkdir, dirPath); - } - void withTrace(fs.writeFile, filePath, introMD, { encoding: 'utf8' }); -} - async function createFirstChallenge( superBlock: SuperBlocks, block: string diff --git a/tools/challenge-helper-scripts/create-quiz.ts b/tools/challenge-helper-scripts/create-quiz.ts index 7a83dcc0e49..ea66fe1ebd4 100644 --- a/tools/challenge-helper-scripts/create-quiz.ts +++ b/tools/challenge-helper-scripts/create-quiz.ts @@ -11,6 +11,7 @@ import { } from '../../shared/config/curriculum'; import { createQuizFile, validateBlockName } from './utils'; import { getBaseMeta } from './helpers/get-base-meta'; +import { createIntroMD } from './helpers/create-intro'; const helpCategories = [ 'HTML-CSS', @@ -48,7 +49,7 @@ async function createQuiz( if (!title) { title = block; } - void updateIntroJson(superBlock, block, title); + await updateIntroJson(superBlock, block, title); const challengeId = await createQuizChallenge( superBlock, @@ -56,9 +57,9 @@ async function createQuiz( title, questionCount ); - void createMetaJson(superBlock, block, title, helpCategory, challengeId); + await createMetaJson(superBlock, block, title, helpCategory, challengeId); // TODO: remove once we stop relying on markdown in the client. - void createIntroMD(superBlock, block, title); + await createIntroMD(superBlock, block, title); } async function updateIntroJson( @@ -109,28 +110,6 @@ async function createMetaJson( ); } -async function createIntroMD(superBlock: string, block: string, title: string) { - const introMD = `--- -title: Introduction to the ${title} -block: ${block} -superBlock: ${superBlock} ---- - -## Introduction to the ${title} - -This page is for the ${title} -`; - const dirPath = path.resolve( - __dirname, - `../../client/src/pages/learn/${superBlock}/${block}/` - ); - const filePath = path.resolve(dirPath, 'index.md'); - if (!existsSync(dirPath)) { - await withTrace(fs.mkdir, dirPath); - } - void withTrace(fs.writeFile, filePath, introMD, { encoding: 'utf8' }); -} - async function createQuizChallenge( superBlock: SuperBlocks, block: string, diff --git a/tools/challenge-helper-scripts/helpers/create-intro.ts b/tools/challenge-helper-scripts/helpers/create-intro.ts new file mode 100644 index 00000000000..032fd2f6f10 --- /dev/null +++ b/tools/challenge-helper-scripts/helpers/create-intro.ts @@ -0,0 +1,36 @@ +import path from 'node:path'; +import fs from 'node:fs/promises'; + +function introTemplate( + superBlock: string, + block: string, + title: string +): string { + return `--- +title: Introduction to the ${title} +block: ${block} +superBlock: ${superBlock} +--- + +## Introduction to the ${title} + +This page is for the ${title} +`; +} + +export async function createIntroMD( + superBlock: string, + block: string, + title: string +) { + const dirPath = path.resolve( + __dirname, + `../../../client/src/pages/learn/${superBlock}/${block}/` + ); + await fs.mkdir(dirPath, { recursive: true }); + + const filePath = path.resolve(dirPath, 'index.md'); + await fs.writeFile(filePath, introTemplate(superBlock, block, title), { + encoding: 'utf8' + }); +}