-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate-readme.ts
81 lines (75 loc) · 2.41 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import path from "path";
import fs from "fs";
import os from "os";
import renderRulesTableContent from "./render-rules";
const isWin = os.platform().startsWith("win");
let insertText = `\n${renderRulesTableContent(
2,
(name) =>
`https://ota-meshi.github.io/eslint-plugin-json-schema-validator/rules/${name}.html`,
)}\n`;
if (isWin) {
insertText = insertText
.replace(/\r?\n/gu, "\n")
.replace(/\r/gu, "\n")
.replace(/\n/gu, "\r\n");
}
const readmeFilePath = path.resolve(__dirname, "../README.md");
const newReadme = fs
.readFileSync(readmeFilePath, "utf8")
.replace(
/<!--RULES_TABLE_START-->[\s\S]*<!--RULES_TABLE_END-->/u,
`<!--RULES_TABLE_START-->${insertText}<!--RULES_TABLE_END-->`,
);
fs.writeFileSync(readmeFilePath, newReadme, "utf8");
const docsReadmeFilePath = path.resolve(__dirname, "../docs/index.md");
fs.writeFileSync(
docsReadmeFilePath,
newReadme
.replace("# eslint-plugin-json-schema-validator\n", "# Introduction\n")
.replace(
/<!--RULES_SECTION_START-->[\s\S]*<!--RULES_SECTION_END-->/u,
"See [Available Rules](./rules/index.md).",
)
.replace(
/<!--USAGE_SECTION_START-->[\s\S]*<!--USAGE_SECTION_END-->/u,
"See [User Guide](./user-guide/index.md).",
)
.replace(/<!--DOCS_IGNORE_START-->[\s\S]*?<!--DOCS_IGNORE_END-->/gu, "")
.replace(
/\(https:\/\/ota-meshi.github.io\/eslint-plugin-json-schema-validator/gu,
"(.",
)
.replace(
"[LICENSE](LICENSE)",
"[LICENSE](https://github.com/ota-meshi/eslint-plugin-json-schema-validator/blob/main/LICENSE)",
)
.replace(/\n{3,}/gu, "\n\n"),
"utf8",
);
const docsUserGuideFilePath = path.resolve(
__dirname,
"../docs/user-guide/index.md",
);
const docsUserGuide = fs.readFileSync(docsUserGuideFilePath, "utf8");
fs.writeFileSync(
docsUserGuideFilePath,
docsUserGuide
.replace(
/<!--USAGE_GUIDE_START-->[\s\S]*<!--USAGE_GUIDE_END-->/u,
/<!--USAGE_GUIDE_START-->[\s\S]*<!--USAGE_GUIDE_END-->/u.exec(
newReadme,
)![0],
)
.replace(
/<!--ADVANCED_USAGE_GUIDE_START-->[\s\S]*<!--ADVANCED_USAGE_GUIDE_END-->/u,
/<!--ADVANCED_USAGE_GUIDE_START-->[\s\S]*<!--ADVANCED_USAGE_GUIDE_END-->/u.exec(
newReadme,
)![0],
)
.replace(
/\(https:\/\/ota-meshi.github.io\/eslint-plugin-json-schema-validator(.*?)\)/gu,
(_s, c: string) => `(..${c.endsWith("/") ? `${c}index.md` : c})`,
),
"utf8",
);