-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatedoc.ts
executable file
·42 lines (32 loc) · 1.62 KB
/
updatedoc.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
#!/usr/bin/env -S deno run --allow-sys --allow-read --allow-env --allow-net --allow-run --allow-write
function replaceCode(tag: string, content: string, replace: string): string {
const regex = new RegExp(`<!-- ${tag} -->.*/${tag} -->`, "sm");
return content.replace(
regex,
`<!-- ${tag} -->\n\n\`\`\`text\n${replace}\`\`\`\n\n<!-- /${tag} -->`,
);
}
///////////////////////////////////////////////////////////////////////////////
// Read README.md
///////////////////////////////////////////////////////////////////////////////
const doc = await Deno.readTextFile("README.md");
///////////////////////////////////////////////////////////////////////////////
// Execute commands
///////////////////////////////////////////////////////////////////////////////
// List commands
const cmdcommands = new Deno.Command("just", {});
let { stdout } = await cmdcommands.output();
const outputcommands = new TextDecoder().decode(stdout);
// List packages
const cmdpackages = new Deno.Command("just", { args: ["packages"] });
({ stdout } = await cmdpackages.output());
const outputpackages = new TextDecoder().decode(stdout);
///////////////////////////////////////////////////////////////////////////////
// Replace tags
///////////////////////////////////////////////////////////////////////////////
let result = replaceCode("COMMANDS", doc, outputcommands);
result = replaceCode("PACKAGES", result, outputpackages);
///////////////////////////////////////////////////////////////////////////////
// Update READLE.md
///////////////////////////////////////////////////////////////////////////////
await Deno.writeTextFile("README.md", result);