MCPcopy
hub / github.com/freshframework/fresh / writeProjectFile

Function writeProjectFile

packages/init/src/init.ts:745–784  ·  view source on GitHub ↗
(
  projectDir: string,
  pathname: string,
  content:
    | string
    | Uint8Array
    | ReadableStream<Uint8Array>
    | Record<string, unknown>,
)

Source from the content-addressed store, hash-verified

743}
744
745async function writeProjectFile(
746 projectDir: string,
747 pathname: string,
748 content:
749 | string
750 | Uint8Array
751 | ReadableStream<Uint8Array>
752 | Record<string, unknown>,
753) {
754 const filePath = path.join(
755 projectDir,
756 ...pathname.split("/").filter(Boolean),
757 );
758 try {
759 await Deno.mkdir(
760 path.dirname(filePath),
761 { recursive: true },
762 );
763 if (typeof content === "string") {
764 let formatted = content;
765 if (!content.endsWith("\n\n")) {
766 formatted += "\n";
767 }
768 await Deno.writeTextFile(filePath, formatted);
769 } else if (
770 content instanceof Uint8Array || content instanceof ReadableStream
771 ) {
772 await Deno.writeFile(filePath, content);
773 } else {
774 await Deno.writeTextFile(
775 filePath,
776 JSON.stringify(content, null, 2) + "\n",
777 );
778 }
779 } catch (err) {
780 if (!(err instanceof Deno.errors.AlreadyExists)) {
781 throw err;
782 }
783 }
784}
785
786interface JsrMeta {
787 scope: string;

Callers 1

writeFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected