-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarkdown.ts
37 lines (31 loc) · 1.24 KB
/
markdown.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import {MarkdownForChainIdT, PROTOCOL_STEPS_ID, CHAINS} from 'types';
import {CHAINS_CONFIG} from 'lib/constants';
import path from 'path';
import fs from 'fs';
const MARKDOWN_PATH = path.resolve('markdown');
export function fetchMarkdownForChainId(chainId: CHAINS): MarkdownForChainIdT {
const steps = CHAINS_CONFIG[chainId].steps.map((step) => step.id);
return steps.reduce((markdownMap, stepId) => {
// We have a special case for preface because it's common to every pathway
const filePath =
stepId === PROTOCOL_STEPS_ID.PREFACE
? path.join(MARKDOWN_PATH, `PREFACE.md`)
: path.join(MARKDOWN_PATH, chainId, `${stepId}.md`);
const fileContent = fs.readFileSync(filePath, 'utf-8');
const markdown = fileContent.toString();
markdownMap[stepId as PROTOCOL_STEPS_ID] = markdown;
return markdownMap;
}, {} as MarkdownForChainIdT);
}
export function getMarkdownForStepId(
chainId: CHAINS,
stepId: PROTOCOL_STEPS_ID,
): string {
const filePath =
stepId === PROTOCOL_STEPS_ID.PREFACE
? path.join(MARKDOWN_PATH, `PREFACE.md`)
: path.join(MARKDOWN_PATH, chainId, `${stepId}.md`);
const fileContent = fs.readFileSync(filePath, 'utf-8');
const markdown = fileContent.toString();
return markdown;
}