cleanout 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -2
- package/src/commands/cleanout.js +10 -3
- package/src/constants/targets.js +1 -1
- package/src/utils/ui.js +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cleanout",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "clean out the clutter, ship the code; one command your project is clean.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -29,5 +29,10 @@
|
|
|
29
29
|
"bugs": {
|
|
30
30
|
"url": "https://github.com/jaswanreddych/cleanout/issues"
|
|
31
31
|
},
|
|
32
|
-
"homepage": "https://github.com/jaswanreddych/cleanout#readme"
|
|
32
|
+
"homepage": "https://github.com/jaswanreddych/cleanout#readme",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"cleanout": "^1.0.1",
|
|
35
|
+
"express": "^5.2.1",
|
|
36
|
+
"g": "^2.0.1"
|
|
37
|
+
}
|
|
33
38
|
}
|
package/src/commands/cleanout.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fsp from "fs/promises"
|
|
2
2
|
import { c } from "../constants/color.js"
|
|
3
3
|
import { getSize, scan } from "../utils/scanner.js"
|
|
4
|
-
import { confirm, printDone, printDryRun, printEmptyMatches, printMatches, printStats } from "../utils/ui.js"
|
|
4
|
+
import { confirm, printDone, printDryRun, printEmptyMatches, printMatches, printStats, startSpinner } from "../utils/ui.js"
|
|
5
5
|
|
|
6
6
|
export async function cleanout(targetDir, config) {
|
|
7
7
|
const { dryRun, yes, stats, depth, include, exclude } = config
|
|
8
8
|
|
|
9
|
+
const spinner = startSpinner("Collecting scan info from the directories (files or folders) to clean up")
|
|
10
|
+
|
|
9
11
|
const matches = await scan(targetDir, depth, include, exclude)
|
|
10
12
|
|
|
11
13
|
for (const item of matches) {
|
|
12
14
|
item['size'] = await getSize(item.path)
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
spinner.stop()
|
|
18
|
+
|
|
15
19
|
if (!(matches.length)) {
|
|
16
20
|
printEmptyMatches()
|
|
17
21
|
return
|
|
@@ -58,15 +62,18 @@ export async function cleanout(targetDir, config) {
|
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
|
|
65
|
+
const deleteSpinner = startSpinner("Deleting files and folders")
|
|
66
|
+
|
|
61
67
|
let space = 0
|
|
62
68
|
for (const item of matches) {
|
|
63
69
|
try {
|
|
64
|
-
|
|
70
|
+
await fsp.rm(item.path, { recursive: true, force: true })
|
|
65
71
|
space += item.size
|
|
66
72
|
} catch (error) {
|
|
67
73
|
console.log(`${c.red}✖ failed to delete ${item.path}: ${error.message}${c.reset}`)
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
76
|
|
|
77
|
+
deleteSpinner.stop()
|
|
71
78
|
printDone(space)
|
|
72
79
|
}
|
package/src/constants/targets.js
CHANGED
package/src/utils/ui.js
CHANGED
|
@@ -107,4 +107,26 @@ export function confirm(question) {
|
|
|
107
107
|
|
|
108
108
|
export function printDone(space) {
|
|
109
109
|
console.log(`\n${c.green}${c.bold}✔ Done!${c.reset} Total ${c.yellow}${formatSize(space)}${c.reset} freed`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function startSpinner(label) {
|
|
113
|
+
if (!process.stdout.isTTY) {
|
|
114
|
+
process.stdout.write(` ${label}...\n`)
|
|
115
|
+
return { stop: () => { } }
|
|
116
|
+
}
|
|
117
|
+
const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
|
|
118
|
+
let i = 0
|
|
119
|
+
const interval = setInterval(() => {
|
|
120
|
+
const frame = SPINNER_FRAMES[i % SPINNER_FRAMES.length]
|
|
121
|
+
process.stdout.write(`\r ${c.cyan}${frame}${c.reset} ${c.gray}${label}${c.reset} `)
|
|
122
|
+
i++
|
|
123
|
+
}, 10)
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
stop(finalMessage = '') {
|
|
127
|
+
clearInterval(interval)
|
|
128
|
+
process.stdout.write('\r' + ' '.repeat(label.length + 10) + '\r')
|
|
129
|
+
if (finalMessage) process.stdout.write(` ${finalMessage}\n`)
|
|
130
|
+
},
|
|
131
|
+
}
|
|
110
132
|
}
|