freeCodeCamp/tools/challenge-helper-scripts/helpers/create-intro.ts
Oliver Eyton-Williams 0ae01847cb
Some checks failed
CI - E2E - 3rd party donation tests / Build Client (22) (push) Has been cancelled
CI - E2E - 3rd party donation tests / Build API (Container) (push) Has been cancelled
CI - Node.js / Lint (22) (push) Has been cancelled
CI - E2E - 3rd party donation tests / Run Playwright 3rd Party Donation Tests (chromium, 22) (push) Has been cancelled
CI - Node.js / Build (22) (push) Has been cancelled
CI - Node.js / Test (22) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (22) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 22) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 22) (push) Has been cancelled
refactor: share common intro creation code (#61814)
2025-08-15 08:05:54 +02:00

37 lines
739 B
TypeScript

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'
});
}