-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_readme.ts
35 lines (34 loc) · 930 Bytes
/
update_readme.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
let [readme, example, first_make, second_make] = await Promise.all([
Deno.readTextFile("README.md"),
Deno.readTextFile("Makefile"),
Deno.readTextFile("tmp/first_make.txt"),
Deno.readTextFile("tmp/second_make.txt"),
]);
// Replace example code
readme = readme.replace(
/<!--begin-example-->[\s\S]*?<!--end-example-->/,
`<!--begin-example-->
\`\`\`Makefile
${example.split("# end-example")[0].trim()}
\`\`\`
<!--end-example-->`,
);
// Replace OS-specific example output
let isWin = Deno.build.os === "windows";
let id = isWin ? "windows" : "macos-linux";
let shell = isWin ? "batch" : "";
let command = isWin ? "> make" : "$ make";
readme = readme.replace(
new RegExp(`<!--begin-${id}-->[\\s\\S]*?<!--end-${id}-->`),
`<!--begin-${id}-->
\`\`\`${shell}
${command}
${first_make.trim()}
\`\`\`
\`\`\`${shell}
${command}
${second_make.trim()}
\`\`\`
<!--end-${id}-->`,
);
await Deno.writeTextFile("README.md", readme);