@stryke/prisma-trpc-generator
Version:
A fork of the prisma-trpc-generator code to work in ESM with Prisma v6.
32 lines (30 loc) • 1.63 kB
JavaScript
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
const require_format_file = require('./format-file.cjs');
let _stryke_fs_helpers = require("@stryke/fs/helpers");
let node_path = require("node:path");
node_path = require_runtime.__toESM(node_path, 1);
let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
let _stryke_fs_write_file = require("@stryke/fs/write-file");
let _stryke_path_correct_path = require("@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([require_format_file.formatFile(content), (0, _stryke_fs_helpers.createDirectory)((0, _stryke_path_file_path_fns.findFilePath)(writeLocation))]);
await (0, _stryke_fs_write_file.writeFile)(writeLocation, fileContent);
if (addToIndex) addIndexExport(writeLocation);
};
const writeIndexFile = async (indexPath) => {
const rows = Array.from(indexExports).map((filePath) => {
let relativePath = node_path.default.relative(node_path.default.dirname(indexPath), filePath);
if (relativePath.endsWith(".ts")) relativePath = relativePath.slice(0, relativePath.lastIndexOf(".ts"));
return `export * from './${(0, _stryke_path_correct_path.correctPath)(relativePath)}';`;
});
rows.push("export * from './models';");
await writeFileSafely(indexPath, rows.join("\n"), false);
};
//#endregion
exports.writeFileSafely = writeFileSafely;
exports.writeIndexFile = writeIndexFile;