| 743 | } |
| 744 | |
| 745 | async 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 | |
| 786 | interface JsrMeta { |
| 787 | scope: string; |