Sha256: 46e30a0f4b8833c6343e68959ec7cb407584e7cc4c7f251d91949a567031227d

Contents?: true

Size: 983 Bytes

Versions: 46

Compression:

Stored size: 983 Bytes

Contents

'use strict'

const u = require('universalify').fromCallback
const fs = require('fs')
const path = require('path')
const mkdir = require('../mkdirs')
const remove = require('../remove')

const emptyDir = u(function emptyDir (dir, callback) {
  callback = callback || function () {}
  fs.readdir(dir, (err, items) => {
    if (err) return mkdir.mkdirs(dir, callback)

    items = items.map(item => path.join(dir, item))

    deleteItem()

    function deleteItem () {
      const item = items.pop()
      if (!item) return callback()
      remove.remove(item, err => {
        if (err) return callback(err)
        deleteItem()
      })
    }
  })
})

function emptyDirSync (dir) {
  let items
  try {
    items = fs.readdirSync(dir)
  } catch (err) {
    return mkdir.mkdirsSync(dir)
  }

  items.forEach(item => {
    item = path.join(dir, item)
    remove.removeSync(item)
  })
}

module.exports = {
  emptyDirSync,
  emptydirSync: emptyDirSync,
  emptyDir,
  emptydir: emptyDir
}

Version data entries

46 entries across 46 versions & 2 rubygems

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