dir-analysis-tool 2.0.6 → 2.0.7

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.
Files changed (3) hide show
  1. package/README.md +194 -90
  2. package/dist/index.js +2 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,47 +1,116 @@
1
- # dir-analysis-tool
1
+ <div align="center">
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/dir-analysis-tool.svg)](https://www.npmjs.com/package/dir-analysis-tool)
4
- [![CI](https://github.com/KhaledSaeed18/dir-analysis-tool/actions/workflows/ci.yml/badge.svg)](https://github.com/KhaledSaeed18/dir-analysis-tool/actions/workflows/ci.yml)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
- [![Node.js Version](https://img.shields.io/node/v/dir-analysis-tool.svg)](https://nodejs.org/)
3
+ <a href="https://www.npmjs.com/package/dir-analysis-tool">
4
+ <img src=".github/assets/dir-analysis-tool-banner.png" alt="dir-analysis-tool, fast and memory-safe directory analysis for your terminal" width="100%" />
5
+ </a>
7
6
 
8
- A fast, memory-safe CLI for directory analysis — file classification, duplicate detection, large-file identification, HTML reports, and multiple export formats.
7
+ <h1>dir-analysis-tool</h1>
9
8
 
10
- ## Quick Start
9
+ <p><strong>A fast, memory-safe CLI for directory analysis:</strong> file classification, duplicate detection, large-file identification, HTML reports, and multiple export formats.</p>
10
+
11
+ <p>
12
+ <a href="https://www.npmjs.com/package/dir-analysis-tool"><img src="https://shieldcn.dev/npm/dir-analysis-tool.svg?logo=npm" alt="npm version" /></a>
13
+ <a href="https://www.npmjs.com/package/dir-analysis-tool"><img src="https://shieldcn.dev/npm/dw/dir-analysis-tool.svg" alt="npm downloads" /></a>
14
+ <a href="https://github.com/KhaledSaeed18/dir-analysis-tool/actions/workflows/ci.yml"><img src="https://shieldcn.dev/github/ci/KhaledSaeed18/dir-analysis-tool.svg" alt="CI status" /></a>
15
+ <a href="https://www.npmjs.com/package/dir-analysis-tool"><img src="https://shieldcn.dev/npm/types/dir-analysis-tool.svg" alt="TypeScript types" /></a>
16
+ <a href="LICENSE"><img src="https://shieldcn.dev/npm/license/dir-analysis-tool.svg?variant=secondary" alt="License: MIT" /></a>
17
+ </p>
18
+
19
+ <p>
20
+ <a href="https://github.com/KhaledSaeed18/dir-analysis-tool/stargazers"><img src="https://shieldcn.dev/github/stars/KhaledSaeed18/dir-analysis-tool.svg?variant=outline" alt="GitHub stars" /></a>
21
+ <a href="https://github.com/KhaledSaeed18/dir-analysis-tool/network/members"><img src="https://shieldcn.dev/github/forks/KhaledSaeed18/dir-analysis-tool.svg?variant=outline" alt="GitHub forks" /></a>
22
+ <a href="https://github.com/KhaledSaeed18/dir-analysis-tool/issues"><img src="https://shieldcn.dev/github/issues/KhaledSaeed18/dir-analysis-tool.svg?variant=outline" alt="GitHub issues" /></a>
23
+ <a href="https://github.com/KhaledSaeed18/dir-analysis-tool/pulls"><img src="https://shieldcn.dev/github/prs/KhaledSaeed18/dir-analysis-tool.svg?variant=outline" alt="GitHub pull requests" /></a>
24
+ <a href="https://github.com/KhaledSaeed18/dir-analysis-tool/releases"><img src="https://shieldcn.dev/github/release/KhaledSaeed18/dir-analysis-tool.svg?variant=ghost" alt="Latest release" /></a>
25
+ </p>
26
+
27
+ </div>
28
+
29
+ ---
30
+
31
+ ## Why dir-analysis-tool?
32
+
33
+ `dat` walks any directory once, streams file hashes without loading them into memory, and gives you a clear picture of what is taking up space: the largest files, duplicated content, empty files, and a full breakdown by file type. It is safe to run on huge trees, safe to pipe into other tools, and ships a polished HTML report when you want to share results.
34
+
35
+ - **Single-pass and streaming.** One filesystem walk, streaming MD5 hashing, constant memory even on multi-gigabyte trees.
36
+ - **Actionable insights.** Duplicates with wasted-space totals, large and empty file detection, top-N largest, and a type breakdown.
37
+ - **Pipe-friendly.** `--json` emits clean, ANSI-free output, and the progress bar auto-disables outside a TTY.
38
+ - **Reports and exports.** Self-contained HTML report with charts, plus CSV export for full analysis, large files, or duplicates.
39
+ - **Configurable.** Project-level `.dir-analyzer.json`, an interactive generator, and CLI flags that always win.
40
+
41
+ ## Table of Contents
42
+
43
+ - [Installation](#installation)
44
+ - [Quick Start](#quick-start)
45
+ - [Features](#features)
46
+ - [CLI Reference](#cli-reference)
47
+ - [`dat analyze`](#dat-directory--dat-analyze-directory)
48
+ - [`dat watch`](#dat-watch-directory)
49
+ - [`dat compare`](#dat-compare-dir1-dir2)
50
+ - [`dat init`](#dat-init)
51
+ - [Example Output](#example-output)
52
+ - [JSON Output](#json-output)
53
+ - [Configuration](#configuration)
54
+ - [Migrating from v1](#migrating-from-v1)
55
+ - [License](#license)
56
+
57
+ ## Installation
58
+
59
+ Install globally to use the `dat` command anywhere:
60
+
61
+ ```bash
62
+ npm install -g dir-analysis-tool
63
+ # or
64
+ pnpm add -g dir-analysis-tool
65
+ # or
66
+ yarn global add dir-analysis-tool
67
+ ```
68
+
69
+ Prefer not to install? Run it on demand with `npx`:
11
70
 
12
71
  ```bash
13
- npm install -g dir-analysis-tool # install globally
72
+ npx dir-analysis-tool # analyze the current directory
73
+ npx dir-analysis-tool /path/to/scan # analyze any path
74
+ ```
75
+
76
+ Two binaries are installed and are fully interchangeable: **`dat`** (short) and **`dir-analysis-tool`** (full). This README uses `dat` throughout.
14
77
 
15
- dat # analyze current directory
78
+ ## Quick Start
79
+
80
+ ```bash
81
+ dat # analyze the current directory
16
82
  dat /path/to/project # analyze any path
17
- dat analyze . --json | jq .files # pipe-safe JSON output
83
+ dat analyze . --duplicates # find duplicate files and wasted space
84
+ dat analyze . --large-files 50 # list files larger than 50 MB
85
+ dat analyze . --html # generate a shareable HTML report
86
+ dat analyze . --json | jq .types # pipe-safe JSON, no ANSI codes
18
87
  ```
19
88
 
20
89
  ## Features
21
90
 
22
91
  | Feature | Description |
23
92
  |---|---|
24
- | Single-pass streaming walk | No double I/O — files are stat'd once |
25
- | Streaming MD5 hashing | Duplicate detection without loading files into RAM |
26
- | TTY-aware progress | Progress bar only in interactive terminals; silent in pipes |
27
- | File type classification | Images, videos, audio, documents, code, archives, other |
28
- | Duplicate detection | Groups identical files by content hash; shows wasted space |
29
- | Large-file detection | Configurable threshold in MB |
30
- | Empty-file detection | Find all zero-byte files |
31
- | Top-N largest files | Quick disk usage overview |
32
- | HTML reports | Charts and tables, matrix/terminal aesthetic |
33
- | CSV export | Full analysis, large files, or duplicates |
34
- | Tree view | Visual directory structure (up to 1 000 files) |
35
- | Watch mode | Debounced re-analysis on every filesystem change |
36
- | Directory comparison | Side-by-side stats for two directories |
37
- | Config file | `.dir-analyzer.json` for default settings |
38
- | Interactive init | `dat init` creates the config file with prompts |
93
+ | **Single-pass streaming walk** | No double I/O. Every file is `stat`'d exactly once. |
94
+ | **Streaming MD5 hashing** | Duplicate detection without ever loading a file into RAM. |
95
+ | **TTY-aware progress** | Live progress in interactive terminals, silent and clean when piped. |
96
+ | **File-type classification** | Images, videos, audio, documents, code, archives, other. |
97
+ | **Duplicate detection** | Groups identical files by content hash and reports total wasted space. |
98
+ | **Large-file detection** | Configurable threshold in MB. |
99
+ | **Empty-file detection** | Surface every zero-byte file. |
100
+ | **Top-N largest files** | Instant disk-usage overview. |
101
+ | **HTML reports** | Self-contained page with charts and tables. |
102
+ | **CSV export** | Full analysis, large-file list, or duplicate groups. |
103
+ | **Tree view** | Visual directory structure (up to 1,000 files). |
104
+ | **Watch mode** | Debounced re-analysis on every filesystem change. |
105
+ | **Directory comparison** | Side-by-side stats for two directories. |
106
+ | **Config file** | `.dir-analyzer.json` for reusable defaults. |
107
+ | **Interactive init** | `dat init` generates the config file with prompts. |
39
108
 
40
109
  ## CLI Reference
41
110
 
42
111
  ### `dat [directory]` / `dat analyze [directory]`
43
112
 
44
- Analyze a directory. Defaults to the current working directory.
113
+ Analyze a directory. This is the default command, so `dat` and `dat analyze` are equivalent. Defaults to the current working directory.
45
114
 
46
115
  ```bash
47
116
  dat # analyze cwd
@@ -49,11 +118,11 @@ dat /path/to/project # explicit path
49
118
  dat analyze . --json # JSON output (no ANSI, pipe-safe)
50
119
  dat analyze . --tree # directory tree view
51
120
  dat analyze . --duplicates # detect duplicate files
52
- dat analyze . --large-files # files > 100 MB
121
+ dat analyze . --large-files # files > 100 MB (default threshold)
53
122
  dat analyze . --large-files 50 # files > 50 MB
54
123
  dat analyze . --empty-files # detect zero-byte files
55
124
  dat analyze . --top-n 20 # top 20 largest files
56
- dat analyze . --html # generate HTML report
125
+ dat analyze . --html # generate an HTML report
57
126
  dat analyze . --csv # export to CSV
58
127
  dat analyze . --exclude node_modules dist coverage
59
128
  dat analyze . --max-depth 3 # limit scan depth
@@ -65,31 +134,31 @@ dat analyze . --date-from 2024-01-01 --date-to 2024-12-31
65
134
 
66
135
  | Flag | Description |
67
136
  |---|---|
68
- | `--no-recursive` | Disable recursive scan |
69
- | `-j, --json` | JSON output (suppresses progress, safe to pipe) |
70
- | `--tree` | Show directory tree |
71
- | `--no-types` | Hide file-type breakdown |
72
- | `-e, --exclude <patterns...>` | Exclude dirs/files by name or glob |
73
- | `-l, --large-files [mb]` | Detect large files (default threshold: 100 MB) |
74
- | `-d, --duplicates` | Enable duplicate detection |
75
- | `--empty-files` | Detect zero-byte files |
76
- | `--top-n <n>` | Show top N largest files |
77
- | `--max-depth <depth>` | Limit directory depth |
78
- | `--min-size <bytes>` | Minimum file size filter |
79
- | `--max-size <bytes>` | Maximum file size filter |
80
- | `--date-from <YYYY-MM-DD>` | Files modified after this date |
81
- | `--date-to <YYYY-MM-DD>` | Files modified before this date |
82
- | `--csv [filename]` | Export full analysis to CSV |
83
- | `--csv-large [filename]` | Export large-file list to CSV |
84
- | `--csv-duplicates [filename]` | Export duplicate groups to CSV |
85
- | `--html [filename]` | Generate HTML report with charts |
86
- | `-c, --config [path]` | Path to config file |
137
+ | `--no-recursive` | Disable recursive scan. |
138
+ | `-j, --json` | JSON output (suppresses progress, safe to pipe). |
139
+ | `--tree` | Show directory tree. |
140
+ | `--no-types` | Hide the file-type breakdown. |
141
+ | `-e, --exclude <patterns...>` | Exclude dirs/files by name or glob. |
142
+ | `-l, --large-files [mb]` | Detect large files (default threshold: 100 MB). |
143
+ | `-d, --duplicates` | Enable duplicate detection. |
144
+ | `--empty-files` | Detect zero-byte files. |
145
+ | `--top-n <n>` | Show the top N largest files. |
146
+ | `--max-depth <depth>` | Limit directory depth. |
147
+ | `--min-size <bytes>` | Minimum file-size filter. |
148
+ | `--max-size <bytes>` | Maximum file-size filter. |
149
+ | `--date-from <YYYY-MM-DD>` | Files modified on or after this date. |
150
+ | `--date-to <YYYY-MM-DD>` | Files modified on or before this date. |
151
+ | `--csv [filename]` | Export full analysis to CSV. |
152
+ | `--csv-large [filename]` | Export the large-file list to CSV. |
153
+ | `--csv-duplicates [filename]` | Export duplicate groups to CSV. |
154
+ | `--html [filename]` | Generate an HTML report with charts. |
155
+ | `-c, --config [path]` | Path to a config file (auto-detected by default). |
87
156
 
88
157
  ---
89
158
 
90
159
  ### `dat watch [directory]`
91
160
 
92
- Watch a directory and re-analyze automatically (debounced 2 s) after changes.
161
+ Watch a directory and re-analyze automatically (debounced 2 s) after each change. Accepts the same analysis flags as `dat analyze`.
93
162
 
94
163
  ```bash
95
164
  dat watch .
@@ -100,7 +169,7 @@ dat watch /path/to/project --duplicates --top-n 10
100
169
 
101
170
  ### `dat compare <dir1> <dir2>`
102
171
 
103
- Compare two directories side by side.
172
+ Compare two directories side by side. Useful for diffing a build against its source, or comparing two versions of a project.
104
173
 
105
174
  ```bash
106
175
  dat compare src/ dist/
@@ -117,33 +186,40 @@ Interactively create a `.dir-analyzer.json` config file in the current directory
117
186
  dat init
118
187
  ```
119
188
 
120
- ---
121
-
122
- ## Configuration
123
-
124
- Create `.dir-analyzer.json` in your project root (or run `dat init`):
125
-
126
- ```json
127
- {
128
- "excludePatterns": ["coverage", "tmp", "__pycache__"],
129
- "clearDefaultExclusions": false,
130
- "largeSizeThresholdMB": 100,
131
- "enableDuplicateDetection": false,
132
- "maxDepth": -1,
133
- "topN": 10,
134
- "showEmptyFiles": false
135
- }
189
+ ## Example Output
190
+
191
+ Running `dat analyze . --duplicates --top-n 3` on a project prints a color-coded summary:
192
+
193
+ ```text
194
+ Directory: /Users/you/project
195
+ Total Size: 48.2 MB
196
+ Folders: 214
197
+ Files: 1,932
198
+
199
+ File Types:
200
+ Images: 42
201
+ Documents: 18
202
+ Code: 1,806
203
+ Archives: 3
204
+ Other: 63
205
+
206
+ Duplicates: 4 groups, 6.1 MB wasted
207
+ ab12cd... (3 files, 2.0 MB each)
208
+ src/assets/logo.png
209
+ public/logo.png
210
+ dist/logo.png
211
+
212
+ Top 3 Largest Files:
213
+ 1. dist/bundle.js, 5.4 MB
214
+ 2. assets/demo.mp4, 3.1 MB
215
+ 3. docs/manual.pdf, 1.2 MB
136
216
  ```
137
217
 
138
- `dat` searches for this file starting in the current directory and walking up the tree. CLI flags always override config values.
139
-
140
- **Default excluded directories** (unless `clearDefaultExclusions: true`): `node_modules`, `.git`, `.svn`, `.hg`, `dist`, `build`, `.cache`
141
-
142
- ---
218
+ > Piping the same command with `--json` produces machine-readable output with no ANSI escape codes and no progress bar, ideal for CI and scripting.
143
219
 
144
220
  ## JSON Output
145
221
 
146
- All fields from a `dat analyze . --json` call:
222
+ `dat analyze . --json` emits the full result object. Optional sections (`largeFiles`, `duplicateGroups`, `duplicateStats`, `emptyFiles`, `topLargestFiles`, `treeView`) appear only when the corresponding flag is enabled.
147
223
 
148
224
  ```jsonc
149
225
  {
@@ -157,16 +233,55 @@ All fields from a `dat analyze . --json` call:
157
233
  "images": 10, "videos": 0, "documents": 5,
158
234
  "audio": 0, "code": 480, "archives": 2, "other": 15
159
235
  },
160
- "largeFiles": [{ "path": "...", "size": 104857600, "sizeFormatted": "105 MB" }],
161
- "duplicateGroups": [{ "hash": "...", "size": 4096, "files": ["...", "..."], "wastedSpace": 4096 }],
162
- "duplicateStats": { "totalGroups": 3, "wastedSpace": 12288, "wastedSpaceFormatted": "12.3 kB" },
163
- "emptyFiles": [{ "path": "...", "mtime": "2024-01-01T00:00:00.000Z" }],
164
- "topLargestFiles": [{ "path": "...", "size": 1048576, "sizeFormatted": "1.05 MB" }],
165
- "treeView": "📁 project\n└── ..."
236
+ "largeFiles": [
237
+ { "path": "...", "size": 104857600, "sizeFormatted": "105 MB" }
238
+ ],
239
+ "duplicateGroups": [
240
+ { "hash": "...", "size": 4096, "sizeFormatted": "4.1 kB",
241
+ "files": ["...", "..."], "wastedSpace": 4096, "wastedSpaceFormatted": "4.1 kB" }
242
+ ],
243
+ "duplicateStats": {
244
+ "totalGroups": 3, "wastedSpace": 12288, "wastedSpaceFormatted": "12.3 kB"
245
+ },
246
+ "emptyFiles": [
247
+ { "path": "...", "mtime": "2024-01-01T00:00:00.000Z" }
248
+ ],
249
+ "topLargestFiles": [
250
+ { "path": "...", "size": 1048576, "sizeFormatted": "1.05 MB" }
251
+ ],
252
+ "treeView": "project\n ..."
166
253
  }
167
254
  ```
168
255
 
169
- ---
256
+ ## Configuration
257
+
258
+ Create `.dir-analyzer.json` in your project root (or run `dat init`):
259
+
260
+ ```json
261
+ {
262
+ "excludePatterns": ["coverage", "tmp", "__pycache__"],
263
+ "clearDefaultExclusions": false,
264
+ "largeSizeThresholdMB": 100,
265
+ "enableDuplicateDetection": false,
266
+ "maxDepth": -1,
267
+ "topN": 10,
268
+ "showEmptyFiles": false
269
+ }
270
+ ```
271
+
272
+ | Key | Type | Default | Description |
273
+ |---|---|---|---|
274
+ | `excludePatterns` | `string[]` | `[]` | Names or globs (for example `*.log`) to exclude, on top of the defaults. |
275
+ | `clearDefaultExclusions` | `boolean` | `false` | When `true`, ignore the built-in default exclusions. |
276
+ | `largeSizeThresholdMB` | `number` | `100` | Large-file threshold in MB. |
277
+ | `enableDuplicateDetection` | `boolean` | `false` | Enable content-hash duplicate detection. |
278
+ | `maxDepth` | `number` | `-1` | Maximum directory depth (`-1` means unlimited). |
279
+ | `topN` | `number` | none | Number of largest files to report. |
280
+ | `showEmptyFiles` | `boolean` | `false` | Include zero-byte files in the report. |
281
+
282
+ `dat` searches for the config starting in the current directory and walking up the tree (both `.dir-analyzer.json` and `dir-analyzer.config.json` are recognized). **CLI flags always override config values.**
283
+
284
+ **Default excluded directories** (unless `clearDefaultExclusions: true`): `node_modules`, `.git`, `.svn`, `.hg`, `dist`, `build`, `.cache`.
170
285
 
171
286
  ## Migrating from v1
172
287
 
@@ -179,17 +294,6 @@ All fields from a `dat analyze . --json` call:
179
294
  | `--large-files <bytes>` | `--large-files <mb>` (value now in MB) |
180
295
  | `bin/` build output | `dist/` build output |
181
296
 
182
- ---
183
-
184
- ## Requirements
185
-
186
- - Node.js >= 18.0.0
187
- - pnpm (for development)
188
-
189
- ## Contributing
190
-
191
- See [CONTRIBUTING.md](CONTRIBUTING.md).
192
-
193
297
  ## License
194
298
 
195
- [MIT](LICENSE)
299
+ [MIT](LICENSE), by [Khaled Saeed](https://github.com/KhaledSaeed18).
package/dist/index.js CHANGED
@@ -715,7 +715,7 @@ function largestFilesChartData(files) {
715
715
  function generateHTML(result) {
716
716
  const typeData = typeChartData(result.types);
717
717
  const largestData = largestFilesChartData(result.topLargestFiles);
718
- const version = true ? "2.0.6" : "2.0.0";
718
+ const version = true ? "2.0.7" : "2.0.0";
719
719
  return `<!DOCTYPE html>
720
720
  <html lang="en">
721
721
  <head>
@@ -1298,7 +1298,7 @@ var compareCommand = new Command4("compare").description("Compare two directorie
1298
1298
 
1299
1299
  // src/index.ts
1300
1300
  var program = new Command5();
1301
- program.name("dat").description("Directory Analysis Tool \u2014 fast, memory-safe directory analysis for your terminal").version(true ? "2.0.6" : "2.0.0", "-v, --version");
1301
+ program.name("dat").description("Directory Analysis Tool \u2014 fast, memory-safe directory analysis for your terminal").version(true ? "2.0.7" : "2.0.0", "-v, --version");
1302
1302
  program.addCommand(analyzeCommand, { isDefault: true });
1303
1303
  program.addCommand(watchCommand);
1304
1304
  program.addCommand(initCommand);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dir-analysis-tool",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "A fast, memory-safe CLI for directory analysis — file classification, duplicate detection, large-file identification, HTML reports, and multiple export formats.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",