Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | const path = require('path'); |
Tim van der Lippe | 4cb0974 | 2022-01-07 14:25:03 +0100 | [diff] [blame^] | 4 | const { mkdir } = require('fs').promises; |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 5 | const stripAnsi = require('strip-ansi'); |
| 6 | const writeFileAtomic = require('write-file-atomic'); |
| 7 | |
| 8 | /** |
| 9 | * @param {string} content |
| 10 | * @param {string} filePath |
Tim van der Lippe | efb716a | 2020-12-01 12:54:04 +0000 | [diff] [blame] | 11 | * @returns {Promise<void>} |
Mathias Bynens | 79e2cf0 | 2020-05-29 16:46:17 +0200 | [diff] [blame] | 12 | */ |
| 13 | module.exports = (content, filePath) => |
Tim van der Lippe | 4cb0974 | 2022-01-07 14:25:03 +0100 | [diff] [blame^] | 14 | mkdir(path.dirname(filePath), { recursive: true }).then(() => |
| 15 | writeFileAtomic(path.normalize(filePath), stripAnsi(content)), |
| 16 | ); |