mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-30 03:03:06 -05:00
* refactor: explicit types for validate * refactor: explicit return types for ui-components * refactor: use exec instead of match * refactor: add lots more boundary types * refactor: more eslint warnings * refactor: more explicit exports * refactor: more explicit types * refactor: even more explicit types * fix: relax type contrainsts for superblock-order * refactor: final boundaries * refactor: avoid using 'object' type * fix: use named import for captureException This uses TypeScript (which works) instead of import/namespace (which doesn't) to check if captureException exists in sentry/gatsby (it does)
33 lines
735 B
TypeScript
33 lines
735 B
TypeScript
import { readdir, readFile } from 'fs/promises';
|
|
import { join } from 'path';
|
|
import { CHALLENGE_DIR, META_DIR } from '../configs/paths';
|
|
|
|
import { PartialMeta } from '../interfaces/partial-meta';
|
|
|
|
type Block = {
|
|
name: string;
|
|
path: string;
|
|
};
|
|
|
|
export const getBlocks = async (sup: string): Promise<Block[]> => {
|
|
const filePath = join(CHALLENGE_DIR, sup);
|
|
|
|
const files = await readdir(filePath);
|
|
const blocks = await Promise.all(
|
|
files.map(async file => {
|
|
const metaPath = join(META_DIR, file, 'meta.json');
|
|
|
|
const metaData = JSON.parse(
|
|
await readFile(metaPath, 'utf8')
|
|
) as PartialMeta;
|
|
|
|
return {
|
|
name: metaData.name,
|
|
path: file
|
|
};
|
|
})
|
|
);
|
|
|
|
return blocks;
|
|
};
|