-
Notifications
You must be signed in to change notification settings - Fork 7
/
examples.ts
43 lines (32 loc) · 961 Bytes
/
examples.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
38
39
40
41
42
43
import { readFileSync, readdirSync, writeFileSync } from "node:fs";
import { relative, resolve } from "node:path";
import { parse } from "json5";
import { renderTweet } from "./src/";
const readmePath = resolve(__dirname, "README.md");
const examplesPath = resolve(__dirname, "examples");
const splitter = "<!-- CUT -->";
const examplesData = readdirSync(examplesPath)
.map((filename) => {
console.log(`Rendering ${filename}...`);
const examplePath = resolve(examplesPath, filename);
const relativePath = relative(__dirname, examplePath);
const tweetData = parse(
readFileSync(examplePath, {
encoding: "utf-8",
}),
);
return `### [${filename}](${relativePath})
${renderTweet(tweetData)}
`;
})
.join("\n---\n\n");
const [heading] = readFileSync(readmePath, {
encoding: "utf-8",
}).split(splitter);
writeFileSync(
readmePath,
`${heading}${splitter}
${examplesData}
`,
{ encoding: "utf-8" },
);