-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathupdateReadme.ts
30 lines (22 loc) · 949 Bytes
/
updateReadme.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
import fs from "node:fs/promises";
import { EOL } from "node:os";
import { readFileSafe } from "../shared/readFileSafe.js";
import { Options } from "../shared/types.js";
export const endOfReadmeTemplateLine = `> 💙 This package was templated with [\`create-typescript-app\`](https://github.com/JoshuaKGoldberg/create-typescript-app).`;
export const endOfReadmeNotice = [
``,
`<!-- You can remove this notice if you don't want it 🙂 no worries! -->`,
``,
endOfReadmeTemplateLine,
``,
].join(EOL);
export const endOfReadmeMatcher =
/💙.+(?:based|built|templated).+(?:from|using|on|with).+create-typescript-app/;
export async function updateReadme(options: Pick<Options, "owner">) {
let contents = await readFileSafe("./README.md", "");
contents = contents.replaceAll("JoshuaKGoldberg", options.owner);
if (!endOfReadmeMatcher.test(contents)) {
contents += endOfReadmeNotice;
}
await fs.writeFile("./README.md", contents);
}