You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
657 B
28 lines
657 B
2 years ago
|
'use strict'
|
||
|
|
||
|
const path = require('path')
|
||
|
const mkdir = require('../mkdirs')
|
||
|
const pathExists = require('../path-exists').pathExists
|
||
|
const jsonFile = require('./jsonfile')
|
||
|
|
||
|
function outputJson (file, data, options, callback) {
|
||
|
if (typeof options === 'function') {
|
||
|
callback = options
|
||
|
options = {}
|
||
|
}
|
||
|
|
||
|
const dir = path.dirname(file)
|
||
|
|
||
|
pathExists(dir, (err, itDoes) => {
|
||
|
if (err) return callback(err)
|
||
|
if (itDoes) return jsonFile.writeJson(file, data, options, callback)
|
||
|
|
||
|
mkdir.mkdirs(dir, err => {
|
||
|
if (err) return callback(err)
|
||
|
jsonFile.writeJson(file, data, options, callback)
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
|
||
|
module.exports = outputJson
|