mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-06 06:01:31 -05:00
33 lines
795 B
TypeScript
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
|
|
}));
|
|
};
|