(filePath, conts, cycles)
| 5 | import yaml from 'js-yaml' |
| 6 | |
| 7 | async function writeFile(filePath, conts, cycles) { |
| 8 | let contents = conts || '' |
| 9 | |
| 10 | return fse.mkdirs(path.dirname(filePath)).then(() => { |
| 11 | if (filePath.indexOf('.json') !== -1 && typeof contents !== 'string') { |
| 12 | if (cycles) { |
| 13 | contents = jc.stringify(contents, null, 2) |
| 14 | } else { |
| 15 | contents = JSON.stringify(contents, null, 2) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | const yamlFileExists = filePath.indexOf('.yaml') !== -1 |
| 20 | const ymlFileExists = filePath.indexOf('.yml') !== -1 |
| 21 | |
| 22 | if ((yamlFileExists || ymlFileExists) && typeof contents !== 'string') { |
| 23 | contents = yaml.dump(contents) |
| 24 | } |
| 25 | |
| 26 | return fsp.writeFile(filePath, contents) |
| 27 | }) |
| 28 | } |
| 29 | |
| 30 | export default writeFile |
no test coverage detected
searching dependent graphs…