refactor: share common intro creation code (#61814)

This commit is contained in:
Oliver Eyton-Williams
2025-08-15 08:05:54 +02:00
committed by GitHub
parent 91f87ea237
commit 0ae01847cb
4 changed files with 45 additions and 72 deletions

View File

@@ -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