(filePath, content)
| 23 | const writeFilePromise = promisify(fs.writeFile); |
| 24 | |
| 25 | async function writeFile(filePath, content) { |
| 26 | if (!type.isString(filePath)) { |
| 27 | throw new Error('Could not write file, file path should be a string.'); |
| 28 | } |
| 29 | |
| 30 | try { |
| 31 | await writeFilePromise(path.resolve(filePath), content); |
| 32 | } catch (error) { |
| 33 | if (error.code === 'ENOENT') { |
| 34 | await mkdirPromise(path.dirname(filePath), { recursive: true }); |
| 35 | await writeFilePromise(filePath, content); |
| 36 | return; |
| 37 | } |
| 38 | throw error; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | export default writeFile; |
no outgoing calls
no test coverage detected