(filePath, conts, options)
| 68 | * @returns A promise that resolves when the file is written. |
| 69 | */ |
| 70 | const writeFile = async (filePath, conts, options) => { |
| 71 | let contents = conts || '' |
| 72 | |
| 73 | await fsp.mkdir(path.dirname(filePath), { recursive: true }) |
| 74 | |
| 75 | if (filePath.endsWith('.json') && typeof contents !== 'string') { |
| 76 | contents = JSON.stringify(contents, null, 2) |
| 77 | } |
| 78 | |
| 79 | const isYamlFile = filePath.endsWith('.yaml') || filePath.endsWith('.yml') |
| 80 | if (isYamlFile && typeof contents !== 'string') { |
| 81 | contents = yaml.dump(contents) |
| 82 | } |
| 83 | |
| 84 | await fsp.writeFile(filePath, contents, options || {}) |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Checks if the source is not a symbolic link. |
searching dependent graphs…