mirror of
https://github.com/deployphp/action.git
synced 2024-12-02 16:29:03 +00:00
40 lines
747 B
JavaScript
40 lines
747 B
JavaScript
|
'use strict'
|
||
|
|
||
|
const u = require('universalify').fromPromise
|
||
|
const fs = require('../fs')
|
||
|
const path = require('path')
|
||
|
const mkdir = require('../mkdirs')
|
||
|
const remove = require('../remove')
|
||
|
|
||
|
const emptyDir = u(async function emptyDir (dir) {
|
||
|
let items
|
||
|
try {
|
||
|
items = await fs.readdir(dir)
|
||
|
} catch {
|
||
|
return mkdir.mkdirs(dir)
|
||
|
}
|
||
|
|
||
|
return Promise.all(items.map(item => remove.remove(path.join(dir, item))))
|
||
|
})
|
||
|
|
||
|
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
|
||
|
}
|