Files
freeCodeCamp/tools/challenge-helper-scripts/helpers/get-challenge-order.ts
Naomi Carrigan ab640abee1 chore: detuplication (#50955)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2023-07-13 12:46:00 +02:00

33 lines
795 B
TypeScript

import { readdir } from 'fs/promises';
import { join } from 'path';
import matter from 'gray-matter';
import { getProjectPath } from './get-project-info';
import { getMetaData } from './project-metadata';
export const getChallengeOrderFromFileTree = async (): Promise<
{ id: string; title: string }[]
> => {
const path = getProjectPath();
const fileList = await readdir(path);
const challengeOrder = fileList
.map(file => matter.read(join(path, file)))
.map(({ data }) => ({
id: data.id as string,
title: data.title as string
}));
return challengeOrder;
};
export const getChallengeOrderFromMeta = (): {
id: string;
title: string;
}[] => {
const meta = getMetaData();
return meta.challengeOrder.map(({ id, title }) => ({
id,
title
}));
};