prunify 0.1.0

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/README.md ADDED
@@ -0,0 +1,198 @@
1
+ # ๐Ÿงน prunify
2
+
3
+ > npm run clean. ship with confidence.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/prunify.svg)](https://www.npmjs.com/package/prunify)
6
+ [![npm downloads](https://img.shields.io/npm/dw/prunify.svg)](https://www.npmjs.com/package/prunify)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
8
+
9
+ **prunify** is a zero-config CLI that audits your TypeScript or JavaScript codebase for:
10
+
11
+ - ๐Ÿ—‘๏ธ **Dead files and exports** โ€” files and named exports that are never imported anywhere
12
+ - ๐Ÿ” **Duplicate code** โ€” functions with identical bodies or suspiciously similar names, duplicate constants
13
+ - โ™ป๏ธ **Circular imports** โ€” dependency cycles that can cause runtime bugs and build issues
14
+ - ๐Ÿ“ฆ **Unused dependencies** โ€” packages declared in `package.json` that are never imported
15
+ - ๐Ÿ“Š **Health score** โ€” a 0โ€“100 score summarising all findings, with optional HTML gauge output
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ # Global install
23
+ npm install -g prunify
24
+
25
+ # Or run directly without installing
26
+ npx prunify
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Quick Start
32
+
33
+ ```bash
34
+ # Analyse the current directory
35
+ npx prunify
36
+
37
+ # Analyse a specific project
38
+ npx prunify --dir ./my-app
39
+
40
+ # Only check dead code and circular imports
41
+ npx prunify --only dead-code,circular
42
+
43
+ # CI mode โ€” exits 1 if any issues found
44
+ npx prunify --ci
45
+ ```
46
+
47
+ ---
48
+
49
+ ## CLI Flags
50
+
51
+ | Flag | Type | Default | Description |
52
+ |------|------|---------|-------------|
53
+ | `--dir <path>` | `string` | `cwd` | Root directory to analyse. Must contain a `package.json`. |
54
+ | `--entry <path>` | `string` | auto-detected | Override the entry point file (e.g. `src/main.ts`). prunify auto-detects `pages/`, `app/`, `src/index.ts`, or reads `package.json` `"main"`. |
55
+ | `--only <modules>` | `string` | all | Comma-separated list of modules to run: `dead-code`, `dupes`, `circular`, `deps`, `health`. |
56
+ | `--ignore <pattern>` | `string` | โ€” | Glob pattern to exclude from analysis. Repeatable. |
57
+ | `--out <path>` | `string` | `<dir>/prunify-reports/` | Directory to write report files to. |
58
+ | `--html` | `boolean` | `false` | Also generate `code_health.html` โ€” a self-contained file with a colour-coded score gauge. |
59
+ | `--delete` | `boolean` | `false` | After analysis, prompt to permanently delete dead files. |
60
+ | `--ci` | `boolean` | `false` | Non-interactive CI mode. Exits with code `1` if any issues are found. |
61
+ | `-v, --version` | โ€” | โ€” | Print the installed version. |
62
+
63
+ ### Examples
64
+
65
+ ```bash
66
+ # Ignore test fixtures and generated files
67
+ npx prunify --ignore "tests/fixtures/**" --ignore "src/generated/**"
68
+
69
+ # Write reports to a custom folder
70
+ npx prunify --out reports/
71
+
72
+ # Full health report with HTML gauge
73
+ npx prunify --only health --html
74
+
75
+ # Specify entry point explicitly
76
+ npx prunify --dir ./packages/core --entry src/index.ts
77
+
78
+ # Delete dead files after confirming in prompt
79
+ npx prunify --delete
80
+
81
+ # Strict CI gate โ€” fails the build if issues exist
82
+ npx prunify --ci
83
+ ```
84
+
85
+ ---
86
+
87
+ ## Sample Output
88
+
89
+ ```
90
+ ๐Ÿงน prunify โ€” npm run clean. ship with confidence.
91
+
92
+ โœ” Parsed codebase โ€” 142 file(s) found
93
+ โœ” Import graph built โ€” 389 edge(s)
94
+
95
+ โœ” Dead code analysis complete โ€” 7 item(s) found
96
+ โœ” Duplicate scan complete โ€” 3 duplicate block(s) found
97
+ โœ” Circular import analysis complete โ€” 2 cycle(s) found
98
+ โœ” Dependency audit complete โ€” 4 issue(s) found
99
+
100
+ Summary
101
+
102
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
103
+ โ”‚ Check โ”‚ Found โ”‚ Output File โ”‚
104
+ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
105
+ โ”‚ Dead Files / Exports โ”‚ 7 โ”‚ dead-code.txt โ”‚
106
+ โ”‚ Duplicate Clusters โ”‚ 3 โ”‚ dupes.md โ”‚
107
+ โ”‚ Unused Packages โ”‚ 4 โ”‚ deps.md โ”‚
108
+ โ”‚ Circular Deps โ”‚ 2 โ”‚ circular.txt โ”‚
109
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
110
+ ```
111
+
112
+ ### Report files in `prunify-reports/`
113
+
114
+ | File | Contents |
115
+ |------|----------|
116
+ | `dead-code.txt` | Dead files with chain analysis and recoverable byte count |
117
+ | `dupes.md` | Duplicate function clusters with AI refactor prompts |
118
+ | `circular.txt` | Circular dependency chains |
119
+ | `deps.md` | Unused / missing packages |
120
+ | `code_health.txt` | Combined health score + all findings (with `--only health`) |
121
+ | `code_health.html` | Self-contained HTML with SVG gauge (with `--html`) |
122
+
123
+ ---
124
+
125
+ ## Add to `.gitignore`
126
+
127
+ prunify automatically appends `prunify-reports/` to your `.gitignore`. If you prefer to commit reports, remove the entry.
128
+
129
+ ```gitignore
130
+ # added by prunify
131
+ prunify-reports/
132
+ ```
133
+
134
+ ---
135
+
136
+ ## How the Health Score Works
137
+
138
+ Starting from **100**, points are deducted per finding:
139
+
140
+ | Finding | Deduction | Cap |
141
+ |---------|-----------|-----|
142
+ | Dead file | โˆ’2 | โˆ’20 |
143
+ | Duplicate function cluster | โˆ’3 | โˆ’15 |
144
+ | Circular dependency | โˆ’5 | โˆ’20 |
145
+ | Unused package | โˆ’2 | โˆ’10 |
146
+ | Barrel file (โ‰ฅ 15 exports) | โˆ’1 | โˆ’10 |
147
+ | Long file (> 300 lines) | โˆ’1 | โˆ’10 |
148
+
149
+ A score of **โ‰ฅ 80** is green, **50โ€“79** is amber, **< 50** is red.
150
+
151
+ ---
152
+
153
+ ## Requirements
154
+
155
+ - Node.js **โ‰ฅ 18**
156
+ - Works with TypeScript **and** JavaScript projects
157
+ - Reads `tsconfig.json` automatically for path-alias resolution
158
+
159
+ ---
160
+
161
+ ## Contributing
162
+
163
+ ```bash
164
+ git clone https://github.com/YOUR_USERNAME/prunify.git
165
+ cd prunify
166
+ npm install
167
+ npm test # run the test suite
168
+ npm run build # compile to dist/
169
+ ```
170
+
171
+ Issues and PRs are welcome at [github.com/YOUR_USERNAME/prunify](https://github.com/YOUR_USERNAME/prunify/issues).
172
+
173
+ ---
174
+
175
+ ## License
176
+
177
+ MIT
178
+ โ”œโ”€โ”€ cli.ts # Entry point
179
+ โ”œโ”€โ”€ core/
180
+ โ”‚ โ”œโ”€โ”€ parser.ts # File discovery + ts-morph AST parsing
181
+ โ”‚ โ”œโ”€โ”€ graph.ts # Import graph builder + DFS/SCC traversal
182
+ โ”‚ โ””โ”€โ”€ reporter.ts # Markdown/JSON output writer
183
+ โ”œโ”€โ”€ modules/
184
+ โ”‚ โ”œโ”€โ”€ dead-code.ts
185
+ โ”‚ โ”œโ”€โ”€ dupe-finder.ts
186
+ โ”‚ โ”œโ”€โ”€ circular.ts
187
+ โ”‚ โ”œโ”€โ”€ dep-check.ts
188
+ โ”‚ โ””โ”€โ”€ health-report.ts
189
+ โ”œโ”€โ”€ prompt-gen/
190
+ โ”‚ โ””โ”€โ”€ templates.ts # LLM prompt generators
191
+ โ””โ”€โ”€ utils/
192
+ โ”œโ”€โ”€ file.ts # Glob + file helpers
193
+ โ””โ”€โ”€ ast.ts # ts-morph AST helpers
194
+ ```
195
+
196
+ ## License
197
+
198
+ MIT