source: trip-planner-front/node_modules/fs-extra/lib/output/index.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 947 bytes
Line 
1'use strict'
2
3const u = require('universalify').fromCallback
4const fs = require('graceful-fs')
5const path = require('path')
6const mkdir = require('../mkdirs')
7const pathExists = require('../path-exists').pathExists
8
9function outputFile (file, data, encoding, callback) {
10 if (typeof encoding === 'function') {
11 callback = encoding
12 encoding = 'utf8'
13 }
14
15 const dir = path.dirname(file)
16 pathExists(dir, (err, itDoes) => {
17 if (err) return callback(err)
18 if (itDoes) return fs.writeFile(file, data, encoding, callback)
19
20 mkdir.mkdirs(dir, err => {
21 if (err) return callback(err)
22
23 fs.writeFile(file, data, encoding, callback)
24 })
25 })
26}
27
28function outputFileSync (file, ...args) {
29 const dir = path.dirname(file)
30 if (fs.existsSync(dir)) {
31 return fs.writeFileSync(file, ...args)
32 }
33 mkdir.mkdirsSync(dir)
34 fs.writeFileSync(file, ...args)
35}
36
37module.exports = {
38 outputFile: u(outputFile),
39 outputFileSync
40}
Note: See TracBrowser for help on using the repository browser.