@stryke/prisma-trpc-generator
Version:
A fork of the prisma-trpc-generator code to work in ESM with Prisma v6.
1 lines • 2.87 kB
Source Map (JSON)
{"version":3,"file":"write-file-safely.mjs","names":[],"sources":["../../src/utils/write-file-safely.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { createDirectory } from \"@stryke/fs/helpers\";\nimport { writeFile } from \"@stryke/fs/write-file\";\nimport { correctPath } from \"@stryke/path/correct-path\";\nimport { findFilePath } from \"@stryke/path/file-path-fns\";\nimport path from \"node:path\";\nimport { formatFile } from \"./format-file\";\n\nconst indexExports = new Set<string>();\n\nexport const addIndexExport = (filePath: string) => {\n indexExports.add(filePath);\n};\n\nexport const writeFileSafely = async (\n writeLocation: string,\n content: any,\n addToIndex = true\n) => {\n const [fileContent] = await Promise.all([\n formatFile(content),\n createDirectory(findFilePath(writeLocation))\n ]);\n\n await writeFile(writeLocation, fileContent);\n if (addToIndex) {\n addIndexExport(writeLocation);\n }\n};\n\nexport const writeIndexFile = async (indexPath: string) => {\n const rows = Array.from(indexExports).map(filePath => {\n let relativePath = path.relative(path.dirname(indexPath), filePath);\n if (relativePath.endsWith(\".ts\")) {\n relativePath = relativePath.slice(0, relativePath.lastIndexOf(\".ts\"));\n }\n const normalized = correctPath(relativePath);\n\n return `export * from './${normalized}';`;\n });\n\n rows.push(\"export * from './models';\");\n\n await writeFileSafely(indexPath, rows.join(\"\\n\"), false);\n};\n"],"mappings":";;;;;;;;AAyBA,MAAM,+BAAe,IAAI,KAAa;AAEtC,MAAa,kBAAkB,aAAqB;AAClD,cAAa,IAAI,SAAS;;AAG5B,MAAa,kBAAkB,OAC7B,eACA,SACA,aAAa,SACV;CACH,MAAM,CAAC,eAAe,MAAM,QAAQ,IAAI,CACtC,WAAW,QAAQ,EACnB,gBAAgB,aAAa,cAAc,CAAC,CAC7C,CAAC;AAEF,OAAM,UAAU,eAAe,YAAY;AAC3C,KAAI,WACF,gBAAe,cAAc;;AAIjC,MAAa,iBAAiB,OAAO,cAAsB;CACzD,MAAM,OAAO,MAAM,KAAK,aAAa,CAAC,KAAI,aAAY;EACpD,IAAI,eAAe,KAAK,SAAS,KAAK,QAAQ,UAAU,EAAE,SAAS;AACnE,MAAI,aAAa,SAAS,MAAM,CAC9B,gBAAe,aAAa,MAAM,GAAG,aAAa,YAAY,MAAM,CAAC;AAIvE,SAAO,oBAFY,YAAY,aAEM,CAAC;GACtC;AAEF,MAAK,KAAK,4BAA4B;AAEtC,OAAM,gBAAgB,WAAW,KAAK,KAAK,KAAK,EAAE,MAAM"}