Sha256: e32d83a6fd73dd1399e5a755f34d070788a68b0f215a679945b226c1b3f00a8b

Contents?: true

Size: 986 Bytes

Versions: 21

Compression:

Stored size: 986 Bytes

Contents

'use strict'

const u = require('universalify').fromCallback
const fs = require('graceful-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 {
    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

21 entries across 21 versions & 1 rubygems

Version Path
appmap-0.72.2 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.72.1 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.72.0 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.71.0 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.70.2 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.70.1 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.70.0 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.69.0 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.68.2 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.68.1 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.68.0 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.67.1 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.67.0 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.66.2 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.66.1 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.66.0 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.65.1 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.65.0 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.64.0 ./node_modules/fs-extra/lib/empty/index.js
appmap-0.63.0 ./node_modules/fs-extra/lib/empty/index.js