-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathscript.ts
37 lines (26 loc) · 1.02 KB
/
script.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 fs from "node:fs";
const JOINER = "\n\n[`⬆ BACK TO TOP ⬆`](#table-of-contents)";
const CODE_ADDRESS = "[EXAMPLE-FILE-ADDRESS]";
const DOCS_DIRECTORY = "./Documentations";
function wrapInTypeScriptBlock(content: string) {
const PREFIX = "```typescript";
const SUFFIX = "```";
return `${PREFIX}\n${content}\n${SUFFIX}`;
}
const contents = fs.readdirSync(DOCS_DIRECTORY).map((fileName) => {
const fileContent = fs.readFileSync(`${DOCS_DIRECTORY}/${fileName}`, "utf-8");
const lines = fileContent.split("\n");
const newLines = lines.map((line) => {
if (line.startsWith(CODE_ADDRESS)) {
const codeFileAddress = line.replace(CODE_ADDRESS, "").slice(1, -1);
const code = fs.readFileSync(`.${codeFileAddress}`, "utf-8");
return wrapInTypeScriptBlock(code);
} else {
return line;
}
});
const joinedLines = newLines.join("\n").trim();
return `${joinedLines}${JOINER}`;
});
const fullDocumentation = contents.join(`\n\n`);
fs.writeFileSync("./README.md", fullDocumentation);