37 lines
977 B
TypeScript
37 lines
977 B
TypeScript
export const updateFile = (
|
|
filePath: string,
|
|
fileContent: string,
|
|
comment = true,
|
|
) => {
|
|
const preamble = comment
|
|
? "# THIS FILE IS AUTOGENERATED. DO NOT EDIT IT BY HAND.\n"
|
|
: "";
|
|
return Deno.writeTextFile(filePath, preamble + fileContent);
|
|
};
|
|
|
|
export const 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;
|
|
};
|