qleaner 1.0.24 โ†’ 1.0.26

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 (2) hide show
  1. package/README.md +95 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -5,6 +5,7 @@ A powerful CLI tool to analyze and clean up your React codebase by finding unuse
5
5
  ## Features
6
6
 
7
7
  - ๐Ÿ” **Scan for unused files**: Identify files that are not imported anywhere in your project
8
+ - ๐Ÿ–ผ๏ธ **Scan for unused images**: Find image files that are not referenced in your codebase
8
9
  - ๐Ÿ“‹ **List all imports**: Get a complete list of all import statements in your codebase with file locations
9
10
  - ๐ŸŽฏ **File listing**: List all files in your project
10
11
  - ๐Ÿ“Š **Table output**: Display results in formatted tables for better readability
@@ -13,6 +14,7 @@ A powerful CLI tool to analyze and clean up your React codebase by finding unuse
13
14
  - ๐Ÿ’ช **TypeScript support**: Works with TypeScript, JavaScript, JSX, and TSX files
14
15
  - ๐Ÿงช **Dry run mode**: Preview what would be deleted without actually deleting files
15
16
  - ๐Ÿ’พ **Smart caching**: Caches scan results for faster subsequent runs (automatically invalidates on file changes)
17
+ - ๐ŸŽจ **CSS and styled-components support**: Detects images used in CSS files and styled-components
16
18
 
17
19
  ## Installation
18
20
 
@@ -117,6 +119,63 @@ qleaner qlean-scan src --clear-cache
117
119
  qleaner qlean-scan src --clear-cache --dry-run
118
120
  ```
119
121
 
122
+ ### Scan for Unused Images
123
+
124
+ Find image files that are not referenced anywhere in your codebase:
125
+
126
+ ```bash
127
+ qleaner qlean-image <directory> <rootPath> [options]
128
+ ```
129
+
130
+ **Arguments:**
131
+ - `<directory>` - The path to the directory containing image files to scan
132
+ - `<rootPath>` - The root path to the project code that utilizes the images
133
+
134
+ **Options:**
135
+ - `-e, --exclude-dir-assets <dir...>` - Exclude directories from the asset scan
136
+ - `-f, --exclude-file-asset <file...>` - Exclude files from the asset scan
137
+ - `-F, --exclude-file-print-asset <files...>` - Scan but don't print the excluded asset files
138
+ - `-E, --exclude-dir-code <dir...>` - Exclude directories from the code scan
139
+ - `-S, --exclude-file-code <file...>` - Exclude files from the code scan
140
+ - `-P, --exclude-file-print-code <files...>` - Scan but don't print the excluded code files
141
+ - `-t, --table` - Display results in a formatted table
142
+ - `-d, --dry-run` - Show what would be deleted without actually deleting (skips prompt)
143
+ - `-C, --clear-cache` - Clear the cache before scanning
144
+
145
+ **Examples:**
146
+
147
+ ```bash
148
+ # Scan for unused images in public/images directory
149
+ qleaner qlean-image public/images src
150
+
151
+ # Display unused images in a table format
152
+ qleaner qlean-image public/images src --table
153
+
154
+ # Scan with exclusions for assets
155
+ qleaner qlean-image public/images src -e public/images/icons
156
+
157
+ # Scan with exclusions for code files
158
+ qleaner qlean-image public/images src -E __tests__ node_modules
159
+
160
+ # Dry run - preview what would be deleted
161
+ qleaner qlean-image public/images src --dry-run
162
+
163
+ # Dry run with table output
164
+ qleaner qlean-image public/images src --dry-run --table
165
+
166
+ # Scan with multiple exclusions
167
+ qleaner qlean-image public/images src -e public/images/icons -E __tests__ -S "**/*.test.*"
168
+ ```
169
+
170
+ **What it detects:**
171
+ - Images imported via `import` statements
172
+ - Images required via `require()` calls
173
+ - Images used in JSX `src` attributes
174
+ - Images in CSS `url()` functions (CSS and SCSS files)
175
+ - Images in styled-components and CSS-in-JS template literals
176
+ - Images in inline styles (backgroundImage, etc.)
177
+ - Images referenced in string literals and template literals
178
+
120
179
  ## Output Formats
121
180
 
122
181
  Qleaner provides two output formats:
@@ -131,9 +190,12 @@ Qleaner provides two output formats:
131
190
  - Import tables show: File, Line, Column, and Import path
132
191
  - File tables show: File path
133
192
  - Unused files table shows: Unused file paths (or "Would Delete" in dry run mode)
193
+ - Unused images table shows: Unused image paths (or "Would Delete" in dry run mode)
134
194
 
135
195
  ## How It Works
136
196
 
197
+ ### File Scanning (qlean-scan)
198
+
137
199
  1. **File Discovery**: Recursively finds all `.tsx`, `.ts`, `.js`, and `.jsx` files in the specified directory
138
200
  2. **Caching**: Checks cache for previously scanned files. Files that haven't changed are skipped for faster performance
139
201
  3. **Import Extraction**: Parses files using Babel AST and extracts all import statements (only for changed files or cache misses)
@@ -143,19 +205,49 @@ Qleaner provides two output formats:
143
205
  7. **Reporting**: Outputs the results in standard or table format based on your preferences
144
206
  8. **Safe Deletion**: In dry run mode, shows what would be deleted without making changes. In normal mode, prompts for confirmation before deletion
145
207
 
208
+ ### Image Scanning (qlean-image)
209
+
210
+ 1. **Image Discovery**: Recursively finds all image files (`.png`, `.jpg`, `.jpeg`, `.svg`, `.gif`, `.webp`) in the specified directory
211
+ 2. **Code Scanning**: Scans all code files (`.js`, `.jsx`, `.ts`, `.tsx`) for image references
212
+ 3. **Image Detection**: Detects images through multiple methods:
213
+ - Import statements (`import img from './image.png'`)
214
+ - Require calls (`require('./image.png')`)
215
+ - JSX src attributes (`<img src="./image.png" />`)
216
+ - CSS url() functions in CSS/SCSS files
217
+ - Styled-components and CSS-in-JS template literals
218
+ - Inline styles (backgroundImage, etc.)
219
+ - String and template literals containing image paths
220
+ 4. **Path Normalization**: Normalizes all detected image paths for consistent matching
221
+ 5. **Analysis**: Compares discovered image files with detected references to identify unused images
222
+ 6. **Reporting**: Outputs the results in standard or table format
223
+ 7. **Safe Deletion**: In dry run mode, shows what would be deleted without making changes. In normal mode, prompts for confirmation before deletion
224
+
146
225
  ## Supported File Types
147
226
 
227
+ **Code files:**
148
228
  - `.js` - JavaScript files
149
229
  - `.jsx` - JavaScript React files
150
230
  - `.ts` - TypeScript files
151
231
  - `.tsx` - TypeScript React files
152
232
 
233
+ **Image files (for qlean-image):**
234
+ - `.png` - PNG images
235
+ - `.jpg`, `.jpeg` - JPEG images
236
+ - `.svg` - SVG images
237
+ - `.gif` - GIF images
238
+ - `.webp` - WebP images
239
+
240
+ **CSS files (for image detection):**
241
+ - `.css` - CSS files
242
+ - `.scss` - SCSS files
243
+
153
244
  ## Use Cases
154
245
 
155
246
  - ๐Ÿงน **Code cleanup**: Remove dead code and unused files from your React projects
247
+ - ๐Ÿ–ผ๏ธ **Image cleanup**: Find and remove unused image assets to reduce project size
156
248
  - ๐Ÿ“Š **Code analysis**: Understand import patterns and dependencies in your codebase
157
- - ๐Ÿ” **Project audit**: Identify orphaned files that may have been forgotten
158
- - ๐Ÿ“ฆ **Bundle optimization**: Find files that can be removed to reduce bundle size
249
+ - ๐Ÿ” **Project audit**: Identify orphaned files and assets that may have been forgotten
250
+ - ๐Ÿ“ฆ **Bundle optimization**: Find files and images that can be removed to reduce bundle size
159
251
  - ๐ŸŽฏ **Maintenance**: Keep your codebase clean and maintainable
160
252
 
161
253
  ## Configuration
@@ -216,4 +308,4 @@ MIT
216
308
 
217
309
  ## Version
218
310
 
219
- Current version: 1.0.13
311
+ Current version: 1.0.26
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qleaner",
3
3
  "packageManager": "yarn@4.6.0",
4
- "version": "1.0.24",
4
+ "version": "1.0.26",
5
5
  "main": "command.js",
6
6
  "bin": "./bin/cli.js",
7
7
  "scripts": {