Sha256: 98b32626a3617fe4d952ca66d882e36b9cea195bac44696aff267fc9450c3f13

Contents?: true

Size: 966 Bytes

Versions: 46

Compression:

Stored size: 966 Bytes

Contents

'use strict'

const u = require('universalify').fromCallback
const fs = require('graceful-fs')
const path = require('path')
const mkdir = require('../mkdirs')
const pathExists = require('../path-exists').pathExists

function outputFile (file, data, encoding, callback) {
  if (typeof encoding === 'function') {
    callback = encoding
    encoding = 'utf8'
  }

  const dir = path.dirname(file)
  pathExists(dir, (err, itDoes) => {
    if (err) return callback(err)
    if (itDoes) return fs.writeFile(file, data, encoding, callback)

    mkdir.mkdirs(dir, err => {
      if (err) return callback(err)

      fs.writeFile(file, data, encoding, callback)
    })
  })
}

function outputFileSync (file, data, encoding) {
  const dir = path.dirname(file)
  if (fs.existsSync(dir)) {
    return fs.writeFileSync.apply(fs, arguments)
  }
  mkdir.mkdirsSync(dir)
  fs.writeFileSync.apply(fs, arguments)
}

module.exports = {
  outputFile: u(outputFile),
  outputFileSync
}

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
ilog-0.4.1 node_modules/fs-extra/lib/output/index.js
ilog-0.4.0 node_modules/fs-extra/lib/output/index.js
ilog-0.3.3 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-18.0.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.21.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.20.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.19.1 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.19.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.18.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.17.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.16.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.15.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.14.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.13.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.12.2 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.12.1 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.12.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.11.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.10.0 node_modules/fs-extra/lib/output/index.js
govuk_publishing_components-17.9.0 node_modules/fs-extra/lib/output/index.js