( data: any, filePath: string, )
| 86 | }; |
| 87 | |
| 88 | export const writeJsonFile = async ( |
| 89 | data: any, |
| 90 | filePath: string, |
| 91 | ): Promise<void> => { |
| 92 | const finalPath = path.join(process.cwd(), filePath); |
| 93 | const tmpPath = `${finalPath}.${randomUUID()}.tmp`; |
| 94 | |
| 95 | try { |
| 96 | await fs.mkdir(path.dirname(finalPath), { recursive: true }); |
| 97 | await fs.writeFile(tmpPath, JSON.stringify(data, null, 2), "utf-8"); |
| 98 | await fs.rename(tmpPath, finalPath); |
| 99 | } catch (error) { |
| 100 | console.error("Error writing data:", error); |
| 101 | try { await fs.unlink(tmpPath); } catch {} |
| 102 | throw error; |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | export const readFile = async (filePath: string): Promise<string> => { |
| 107 | try { |
no outgoing calls
no test coverage detected