Last change
on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
657 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | const path = require('path')
|
---|
| 4 | const mkdir = require('../mkdirs')
|
---|
| 5 | const pathExists = require('../path-exists').pathExists
|
---|
| 6 | const jsonFile = require('./jsonfile')
|
---|
| 7 |
|
---|
| 8 | function outputJson (file, data, options, callback) {
|
---|
| 9 | if (typeof options === 'function') {
|
---|
| 10 | callback = options
|
---|
| 11 | options = {}
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | const dir = path.dirname(file)
|
---|
| 15 |
|
---|
| 16 | pathExists(dir, (err, itDoes) => {
|
---|
| 17 | if (err) return callback(err)
|
---|
| 18 | if (itDoes) return jsonFile.writeJson(file, data, options, callback)
|
---|
| 19 |
|
---|
| 20 | mkdir.mkdirs(dir, err => {
|
---|
| 21 | if (err) return callback(err)
|
---|
| 22 | jsonFile.writeJson(file, data, options, callback)
|
---|
| 23 | })
|
---|
| 24 | })
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | module.exports = outputJson
|
---|
Note:
See
TracBrowser
for help on using the repository browser.