forked from siemah/nodejs-password
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.mjs
25 lines (25 loc) · 825 Bytes
/
cleanup.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { existsSync, lstatSync, readdirSync, rmdirSync, unlinkSync } from 'fs'
import Path, { dirname } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const deleteDirRecursive = (/** @type string */ path) => {
if (existsSync(path)) {
readdirSync(path).forEach((file) => {
const curPath = Path.join(path, file)
if (lstatSync(curPath).isDirectory()) {
deleteDirRecursive(curPath)
} else {
unlinkSync(curPath)
}
})
rmdirSync(path)
}
}
const dir = process.argv.slice(2)[0]
if (dir) {
deleteDirRecursive(Path.join(__dirname, 'lib', dir))
} else {
deleteDirRecursive(Path.join(__dirname, 'lib/cjs'))
deleteDirRecursive(Path.join(__dirname, 'lib/esm'))
deleteDirRecursive(Path.join(__dirname, 'lib/types'))
}