@catladder/pipeline
Version:
Panter workflow for cloud CI/CD and DevOps
53 lines (48 loc) • 1.39 kB
text/typescript
import { writeFile } from "fs/promises";
import { stringify } from "yaml";
export const getAutoGeneratedHeader = (commentChar: string) => {
return [
"-------------------------------------------------",
`🐱 🔨 This file is generated by catladder`,
`🚨 Do not edit this file manually 🚨`,
"-------------------------------------------------",
]
.map((line) => `${commentChar} ${line}`)
.join("\n")
.concat("\n");
};
export const writeGeneratedFile = async (
path: string,
content: string,
{
commentChar,
}: {
commentChar: string;
},
) => {
await writeFile(
path,
// need to spread out the jobs, forgot why
[getAutoGeneratedHeader(commentChar), content].join("\n"),
{
encoding: "utf-8",
},
);
};
type StringifyOptions = Exclude<
Parameters<typeof stringify>[2],
null | undefined | string | number
>;
export const yamlStringifyOptions: StringifyOptions = {
// prevents colapsing long command statements into multiple lines
lineWidth: 0,
// represent multi line commands as single line json strings
doubleQuotedAsJSON: true,
// Better readability when bash commands most often use double quotes
singleQuote: true,
};
export const writeYamlfile = async (path: string, data: any) => {
await writeGeneratedFile(path, stringify(data, yamlStringifyOptions), {
commentChar: "#",
});
};