( filePath: string, data: string, options?: fs.WriteFileOptions, )
| 9 | * @param options - Optional write options (encoding, flag, etc.). |
| 10 | */ |
| 11 | export function writeFileEnsuringDir( |
| 12 | filePath: string, |
| 13 | data: string, |
| 14 | options?: fs.WriteFileOptions, |
| 15 | ): void { |
| 16 | const dir = path.dirname(filePath); |
| 17 | if (!fs.existsSync(dir)) { |
| 18 | fs.mkdirSync(dir, { recursive: true }); |
| 19 | } |
| 20 | fs.writeFileSync(filePath, data, options); |
| 21 | } |