UNPKG

@stryke/prisma-trpc-generator

Version:

A fork of the prisma-trpc-generator code to work in ESM with Prisma v6.

30 lines (28 loc) 1.3 kB
import { formatFile } from "./format-file.mjs"; import { createDirectory } from "@stryke/fs/helpers"; import path from "node:path"; import { findFilePath } from "@stryke/path/file-path-fns"; import { writeFile } from "@stryke/fs/write-file"; import { correctPath } from "@stryke/path/correct-path"; //#region src/utils/write-file-safely.ts const indexExports = /* @__PURE__ */ new Set(); const addIndexExport = (filePath) => { indexExports.add(filePath); }; const writeFileSafely = async (writeLocation, content, addToIndex = true) => { const [fileContent] = await Promise.all([formatFile(content), createDirectory(findFilePath(writeLocation))]); await writeFile(writeLocation, fileContent); if (addToIndex) addIndexExport(writeLocation); }; const writeIndexFile = async (indexPath) => { const rows = Array.from(indexExports).map((filePath) => { let relativePath = path.relative(path.dirname(indexPath), filePath); if (relativePath.endsWith(".ts")) relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts")); return `export * from './${correctPath(relativePath)}';`; }); rows.push("export * from './models';"); await writeFileSafely(indexPath, rows.join("\n"), false); }; //#endregion export { writeFileSafely, writeIndexFile }; //# sourceMappingURL=write-file-safely.mjs.map