forked from sveltejs/eslint-plugin-svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-readme.ts
87 lines (78 loc) · 2.6 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
82
83
84
85
86
87
import path from "path"
import fs from "fs"
import renderRulesTableContent from "./render-rules"
const insertText = `\n${renderRulesTableContent(
(name) => `https://ota-meshi.github.io/eslint-plugin-svelte/rules/${name}/`,
)}\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.replace(
/\$/g,
"$$$$",
)}<!--RULES_TABLE_END-->`,
)
fs.writeFileSync(readmeFilePath, newReadme)
const docsReadmeFilePath = path.resolve(__dirname, "../docs/README.md")
fs.writeFileSync(
docsReadmeFilePath,
`---
title: "eslint-plugin-svelte"
---
${newReadme
.replace("# eslint-plugin-svelte\n", "# Introduction\n")
.replace(
/<!--RULES_SECTION_START-->[\s\S]*<!--RULES_SECTION_END-->/u,
"See [Available Rules](./rules.md).",
)
.replace(
/<!--USAGE_SECTION_START-->[\s\S]*<!--USAGE_SECTION_END-->/u,
"See [User Guide](./user-guide.md).",
)
.replace(/<!--DOCS_IGNORE_START-->[\s\S]*?<!--DOCS_IGNORE_END-->/gu, "")
.replace(
/\(https:\/\/ota-meshi.github.io\/eslint-plugin-svelte(.*?)\)/gu,
(_ptn, path: string) => {
const [hash] = /(?:#.*)?$/u.exec(path)!
const pathWithoutHash = hash ? path.slice(0, -hash.length) : path
const normalizePathWithoutHash = pathWithoutHash.replace(/\/$/u, "")
const [file] = /[^/]+$/u.exec(normalizePathWithoutHash)!
const pathWithoutFile = file
? normalizePathWithoutHash.slice(0, -file.length)
: normalizePathWithoutHash
let result = `(.${pathWithoutFile}`
if (file.endsWith(".html")) {
result +=
file === "index.html" ? "README.md" : file.replace(/\.html$/, ".md")
} else {
result += `${file}.md`
}
result += `${hash})`
return result
},
)
.replace(
"[LICENSE](LICENSE)",
"[LICENSE](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/LICENSE)",
)
.replace(/\n{3,}/gu, "\n\n")}`,
)
const docsUserGuideFilePath = path.resolve(__dirname, "../docs/user-guide.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(
/\(https:\/\/ota-meshi.github.io\/eslint-plugin-svelte(.*?)\)/gu,
(_s, c: string) => `(.${c.endsWith("/") ? c.slice(0, -1) : c}.md)`,
),
"utf8",
)