forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
33 lines (30 loc) 路 911 Bytes
/
Copy pathutils.ts
File metadata and controls
33 lines (30 loc) 路 911 Bytes
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
export function writeWithPreamble(
filePath: string,
fileContent: string,
) {
return Deno.writeTextFile(
filePath,
"# THIS FILE IS AUTOGENERATED. DO NOT EDIT IT BY HAND.\n" + fileContent,
);
}
export function updateReadme({
readme,
section,
newContent,
}: {
readme: string;
section: string;
newContent: string;
}): string {
const preamble =
"<!-- the following section is auto-generated, do not edit -->";
const startMarker = `<!-- AUTOGEN:${section.toUpperCase()} START -->`;
const endMarker = `<!-- AUTOGEN:${section.toUpperCase()} END -->`;
const wrapped = `${startMarker}\n${preamble}\n${newContent}\n${endMarker}`;
if (!(readme.includes(startMarker) && readme.includes(endMarker))) {
throw new Error("Markers not found in README.md");
}
const pre = readme.split(startMarker)[0];
const end = readme.split(endMarker)[1];
return pre + wrapped + end;
}