Skip to content

Commit 7a92733

Browse files
committed
add veryVerbose
- fix missing topLevel linkAction
1 parent 604b299 commit 7a92733

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ like:
2222
$ node-scrub node_modules
2323
------summary------
2424
(dry-run results)
25-
total bytes: 65818 directories: 6 files: 10
25+
total bytes: 65818 directories: 6 files: 26
2626
deleted bytes: 35412 directories: 0 files: 20
27-
percents: bytes 53.8 directories 0.0 files 200.0
28-
elapsed time 8ms
27+
percents: bytes 53.8 directories 0.0 files 76.9
28+
elapsed time 11ms
2929
```
3030

3131
Note that the option `--dry-run` is by default true and that's a good thing because
@@ -36,10 +36,10 @@ want to delete.
3636
$ node-scrub .
3737
------summary------
3838
(dry-run results)
39-
total bytes: 281809 directories: 43 files: 59
40-
deleted bytes: 41897 directories: 0 files: 22
41-
percents: bytes 14.9 directories 0.0 files 37.3
42-
elapsed time 18ms
39+
total bytes: 329447 directories: 54 files: 89
40+
deleted bytes: 37157 directories: 0 files: 22
41+
percents: bytes 11.3 directories 0.0 files 24.7
42+
elapsed time 22ms
4343
```
4444

4545
## Command-line options
@@ -50,6 +50,7 @@ files and directories to delete.
5050
`--dry-run` - [true], use `--dry-run false` to delete files and directories.
5151
`--details, -d` - [false], show count and size for each match deleted.
5252
`--verbose` - [false], print every directory and file deleted.
53+
`--veryVerbose` - [false], print every directory, file, and link traversed + verbose.
5354

5455
### todos
5556

index.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const details = [dirs, pkgDirs, files, extensions];
2525
/* eslint-disable no-console */
2626

2727
const own = makeOwn();
28-
const options = {dirAction, fileAction, own, stat: 'lstat', dryRun: true};
28+
const options = {dirAction, fileAction, linkAction, own, stat: 'lstat', dryRun: true};
2929

3030
async function main () {
3131
const {values: args, ...config} = await configuration.get();
@@ -39,11 +39,12 @@ async function main () {
3939

4040
const dir = args.directory;
4141
options.dryRun = args.dryRun;
42-
options.verbose = args.verbose;
42+
options.verbose = args.verbose || args.veryVerbose;
43+
options.veryVerbose = args.veryVerbose;
4344
options.details = args.details;
4445

4546
if (options.verbose) {
46-
console.log('deleting:');
47+
console.log('deleting: (subtree, file, and ext)');
4748
}
4849
return walk(dir, options)
4950
.then(() => {
@@ -80,6 +81,10 @@ async function dirAction (filepath, ctx) {
8081
const {dirent, stat, own, stack} = ctx;
8182
own.dirs += 1;
8283

84+
if (options.veryVerbose) {
85+
console.log(`d: ${stack.join('/')} ${dirent.name}`);
86+
}
87+
8388
if (dirs.has(dirent.name) || (pkgDirs.has(dirent.name) && stack[stack.length - 2] === 'node_modules')) {
8489
// delete this directory after walking it to get the total size
8590
// that was removed. start with the size of this directory.
@@ -99,6 +104,7 @@ async function dirAction (filepath, ctx) {
99104
own.bytesDeleted += subOwn.bytes;
100105
own.dirs += subOwn.dirs;
101106
own.dirsDeleted += subOwn.dirs;
107+
own.files += subOwn.files;
102108
own.filesDeleted += subOwn.files;
103109

104110
let details;
@@ -134,6 +140,10 @@ async function fileAction (filepath, ctx) {
134140
own.bytes += stat.size;
135141
own.files += 1;
136142

143+
if (options.veryVerbose) {
144+
console.log(`f: ${ctx.stack.join('/')} ${dirent.name}`);
145+
}
146+
137147
if (files.has(dirent.name)) {
138148
own.filesDeleted += 1;
139149
own.bytesDeleted += stat.size;
@@ -151,6 +161,7 @@ async function fileAction (filepath, ctx) {
151161
}
152162
return;
153163
}
164+
154165
const ext = path.extname(dirent.name);
155166

156167
if (!xExtensions.has(ext) && extensions.has(ext)) {
@@ -175,6 +186,10 @@ async function linkAction (filepath, ctx) {
175186
const {stat, own} = ctx;
176187
own.bytes += stat.size;
177188
own.files += 1;
189+
190+
if (options.veryVerbose) {
191+
console.log(`l: ${ctx.stack.join('/')} ${ctx.dirent.name}`);
192+
}
178193
}
179194

180195
function makeOwn (proto) {

lib/configuration.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ async function get (options = {}) {
2727
directory: {location: 'b', type: 's', required: true, allow0: true},
2828
dryRun: {location: 'b', type: 'b', default: true},
2929
verbose: {location: 'c', type: 'b', default: false},
30+
veryVerbose: {location: 'c', type: 'b', default: false},
3031
details: {location: 'b', alias: 'd', type: 'b', default: false},
3132
commandLineOnly: {location: 'b', alias: 'clo', type: 'b', default: false},
3233
};

0 commit comments

Comments
 (0)