qleaner 1.0.32 โ 1.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 +129 -72
- package/bin/cli.js +29 -34
- package/command.js +231 -77
- package/controllers/image.js +584 -190
- package/controllers/initialize.js +41 -0
- package/controllers/list.js +83 -26
- package/controllers/summary.js +397 -0
- package/eslint.config.mjs +9 -0
- package/package.json +10 -4
- package/qleaner.config.json +28 -0
- package/utils/cache.js +90 -28
- package/utils/constants.js +10 -0
- package/utils/cssImages.js +113 -21
- package/utils/resolver.js +67 -12
- package/utils/summary.js +81 -0
- package/utils/utils.js +52 -11
package/README.md
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
# Qleaner
|
|
2
2
|
|
|
3
|
-
A powerful CLI tool to analyze and clean up your React codebase by finding unused files and
|
|
3
|
+
A powerful CLI tool to analyze and clean up your React codebase by finding unused files and images, providing project insights, and analyzing dependencies.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- ๐ **Scan for unused files**: Identify files that are not imported anywhere in your project
|
|
8
8
|
- ๐ผ๏ธ **Scan for unused images**: Find image files that are not referenced in your codebase
|
|
9
|
-
-
|
|
10
|
-
-
|
|
9
|
+
- ๐ **Project summary**: Get comprehensive project insights including file counts, unused files/images, largest files, dependencies, and more
|
|
10
|
+
- ๐ **Dependency analysis**: Analyze import patterns and identify files with heavy or light dependencies
|
|
11
|
+
- ๐ **File size analysis**: Identify largest files and potential optimization opportunities
|
|
11
12
|
- ๐ **Table output**: Display results in formatted tables for better readability
|
|
12
|
-
- โ๏ธ **Flexible configuration**: Exclude directories and files from scanning
|
|
13
|
+
- โ๏ธ **Flexible configuration**: Exclude directories and files from scanning via command-line options or configuration file (`qleaner.config.json`)
|
|
13
14
|
- ๐ **Fast performance**: Efficient file scanning across large codebases with intelligent caching
|
|
14
15
|
- ๐ช **TypeScript support**: Works with TypeScript, JavaScript, JSX, and TSX files
|
|
15
16
|
- ๐งช **Dry run mode**: Preview what would be deleted without actually deleting files
|
|
16
17
|
- ๐พ **Smart caching**: Caches scan results for faster subsequent runs (automatically invalidates on file changes)
|
|
17
18
|
- ๐จ **CSS and styled-components support**: Detects images used in CSS files and styled-components
|
|
19
|
+
- ๐ง **Configuration file**: Use `qleaner init` to create a `qleaner.config.json` file with default settings for your project
|
|
18
20
|
|
|
19
21
|
## Installation
|
|
20
22
|
|
|
@@ -31,92 +33,95 @@ yarn add qleaner
|
|
|
31
33
|
|
|
32
34
|
## Usage
|
|
33
35
|
|
|
34
|
-
###
|
|
36
|
+
### Initialize Configuration
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
Create a `qleaner.config.json` file in your project root to configure default settings:
|
|
37
39
|
|
|
38
40
|
```bash
|
|
39
|
-
qleaner
|
|
41
|
+
qleaner init
|
|
40
42
|
```
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
- `-l, --list-files` - List all the files in the project
|
|
44
|
-
- `-i, --list-imports` - List all the imports in the project
|
|
45
|
-
- `-e, --exclude-dir <dir...>` - Exclude directories from the scan
|
|
46
|
-
- `-f, --exclude-file <file...>` - Exclude files from the scan
|
|
47
|
-
- `-F, --exclude-file-print <file...>` - Do not print the excluded files
|
|
48
|
-
- `-t, --table` - Display results in a formatted table
|
|
44
|
+
This creates a configuration file with default settings for exclusions and image scanning options. You can then modify `qleaner.config.json` to customize your settings.
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
### Project Summary
|
|
47
|
+
|
|
48
|
+
Get a comprehensive summary of your project including file counts, unused files/images, and dependencies:
|
|
51
49
|
|
|
52
50
|
```bash
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
qleaner summary [options]
|
|
52
|
+
```
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
**Options:**
|
|
55
|
+
- `-l, --largest-files` - List the largest files in the project
|
|
56
|
+
- `-d, --dependencies` - List the dependencies in the project
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
qleaner qlean-list src --list-files --list-imports --table
|
|
58
|
+
**Examples:**
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
```bash
|
|
61
|
+
# Get project summary (default)
|
|
62
|
+
qleaner summary
|
|
64
63
|
|
|
65
|
-
# List
|
|
66
|
-
qleaner
|
|
64
|
+
# List the largest files
|
|
65
|
+
qleaner summary --largest-files
|
|
67
66
|
|
|
68
|
-
# List
|
|
69
|
-
qleaner
|
|
67
|
+
# List dependencies
|
|
68
|
+
qleaner summary --dependencies
|
|
70
69
|
```
|
|
71
70
|
|
|
71
|
+
**Important:** Before viewing the summary, make sure to run a fresh scan with `--clear-cache` to ensure accurate results. The summary reads from the cache, so outdated cache data will show outdated results.
|
|
72
|
+
|
|
72
73
|
### Scan for Unused Files
|
|
73
74
|
|
|
74
75
|
Find files that are not imported anywhere in your project:
|
|
75
76
|
|
|
76
77
|
```bash
|
|
77
|
-
qleaner
|
|
78
|
+
qleaner scan <path> [options]
|
|
78
79
|
```
|
|
79
80
|
|
|
80
81
|
**Options:**
|
|
81
82
|
- `-e, --exclude-dir <dir...>` - Exclude directories from the scan
|
|
82
83
|
- `-f, --exclude-file <file...>` - Exclude files from the scan
|
|
83
|
-
- `-F, --exclude-file-print <files...>` -
|
|
84
|
+
- `-F, --exclude-file-print <files...>` - Scan but don't print the excluded files
|
|
85
|
+
- `-x, --exclude-extensions <extensions...>` - Exclude file extensions from the scan (e.g., test.tsx, test.ts, test.js, test.jsx)
|
|
84
86
|
- `-t, --table` - Display results in a formatted table
|
|
85
87
|
- `-d, --dry-run` - Show what would be deleted without actually deleting (skips prompt)
|
|
86
|
-
- `-C, --clear-cache` - Clear the cache before scanning (
|
|
88
|
+
- `-C, --clear-cache` - Clear the cache before scanning (recommended after making code changes)
|
|
87
89
|
|
|
88
90
|
**Examples:**
|
|
89
91
|
|
|
90
92
|
```bash
|
|
91
93
|
# Scan src directory for unused files
|
|
92
|
-
qleaner
|
|
94
|
+
qleaner scan src
|
|
93
95
|
|
|
94
96
|
# Display unused files in a table format
|
|
95
|
-
qleaner
|
|
97
|
+
qleaner scan src --table
|
|
96
98
|
|
|
97
99
|
# Scan excluding test directories
|
|
98
|
-
qleaner
|
|
100
|
+
qleaner scan src -e __tests__ __mocks__ test
|
|
99
101
|
|
|
100
102
|
# Scan excluding specific file patterns
|
|
101
|
-
qleaner
|
|
103
|
+
qleaner scan src -f "**/*.test.js" "**/*.stories.js"
|
|
104
|
+
|
|
105
|
+
# Scan excluding file extensions
|
|
106
|
+
qleaner scan src -x test.tsx test.ts test.js test.jsx
|
|
102
107
|
|
|
103
108
|
# Scan with multiple exclusions
|
|
104
|
-
qleaner
|
|
109
|
+
qleaner scan src -e node_modules dist -f "**/*.config.js"
|
|
105
110
|
|
|
106
111
|
# Scan with table output and exclusions
|
|
107
|
-
qleaner
|
|
112
|
+
qleaner scan src --table -e __tests__ dist -f "**/*.config.js"
|
|
108
113
|
|
|
109
114
|
# Dry run - preview what would be deleted without deleting
|
|
110
|
-
qleaner
|
|
115
|
+
qleaner scan src --dry-run
|
|
111
116
|
|
|
112
117
|
# Dry run with table output
|
|
113
|
-
qleaner
|
|
118
|
+
qleaner scan src --dry-run --table
|
|
114
119
|
|
|
115
120
|
# Clear cache and scan (recommended after making code changes)
|
|
116
|
-
qleaner
|
|
121
|
+
qleaner scan src --clear-cache
|
|
117
122
|
|
|
118
123
|
# Clear cache with dry run
|
|
119
|
-
qleaner
|
|
124
|
+
qleaner scan src --clear-cache --dry-run
|
|
120
125
|
```
|
|
121
126
|
|
|
122
127
|
### Scan for Unused Images
|
|
@@ -124,7 +129,7 @@ qleaner qlean-scan src --clear-cache --dry-run
|
|
|
124
129
|
Find image files that are not referenced anywhere in your codebase:
|
|
125
130
|
|
|
126
131
|
```bash
|
|
127
|
-
qleaner
|
|
132
|
+
qleaner image <directory> <rootPath> [options]
|
|
128
133
|
```
|
|
129
134
|
|
|
130
135
|
**Arguments:**
|
|
@@ -133,38 +138,51 @@ qleaner qlean-image <directory> <rootPath> [options]
|
|
|
133
138
|
|
|
134
139
|
**Options:**
|
|
135
140
|
- `-e, --exclude-dir-assets <dir...>` - Exclude directories from the asset scan
|
|
136
|
-
- `-f, --exclude-file-
|
|
137
|
-
- `-F, --exclude-file-print-asset <files...>` - Scan but don't print the excluded asset files
|
|
141
|
+
- `-f, --exclude-file-assets <file...>` - Exclude files from the asset scan
|
|
138
142
|
- `-E, --exclude-dir-code <dir...>` - Exclude directories from the code scan
|
|
139
143
|
- `-S, --exclude-file-code <file...>` - Exclude files from the code scan
|
|
140
|
-
- `-
|
|
144
|
+
- `-r, --is-root-folder-referenced` - Is the root folder referenced in the image path (e.g., `/img/a.png` where `img` is the root folder)
|
|
145
|
+
- `-a, --alias` - Is the alias referenced in the image path (e.g., `@/assets/images/a.png`)
|
|
141
146
|
- `-t, --table` - Display results in a formatted table
|
|
142
147
|
- `-d, --dry-run` - Show what would be deleted without actually deleting (skips prompt)
|
|
143
|
-
- `-C, --clear-cache` - Clear the cache before scanning
|
|
148
|
+
- `-C, --clear-cache` - Clear the cache before scanning (recommended after making code changes)
|
|
149
|
+
- `-H, --hide-not-found-images` - Hide images shown in code but not found in the image directory
|
|
144
150
|
|
|
145
151
|
**Examples:**
|
|
146
152
|
|
|
147
153
|
```bash
|
|
148
154
|
# Scan for unused images in public/images directory
|
|
149
|
-
qleaner
|
|
155
|
+
qleaner image public/images src
|
|
150
156
|
|
|
151
157
|
# Display unused images in a table format
|
|
152
|
-
qleaner
|
|
158
|
+
qleaner image public/images src --table
|
|
153
159
|
|
|
154
160
|
# Scan with exclusions for assets
|
|
155
|
-
qleaner
|
|
161
|
+
qleaner image public/images src -e public/images/icons
|
|
156
162
|
|
|
157
163
|
# Scan with exclusions for code files
|
|
158
|
-
qleaner
|
|
164
|
+
qleaner image public/images src -E __tests__ node_modules
|
|
165
|
+
|
|
166
|
+
# Scan with root folder reference pattern
|
|
167
|
+
qleaner image public/images src -r
|
|
168
|
+
|
|
169
|
+
# Scan with alias pattern
|
|
170
|
+
qleaner image public/images src -a
|
|
171
|
+
|
|
172
|
+
# Hide not-found images from results
|
|
173
|
+
qleaner image public/images src --hide-not-found-images
|
|
159
174
|
|
|
160
175
|
# Dry run - preview what would be deleted
|
|
161
|
-
qleaner
|
|
176
|
+
qleaner image public/images src --dry-run
|
|
162
177
|
|
|
163
178
|
# Dry run with table output
|
|
164
|
-
qleaner
|
|
179
|
+
qleaner image public/images src --dry-run --table
|
|
165
180
|
|
|
166
181
|
# Scan with multiple exclusions
|
|
167
|
-
qleaner
|
|
182
|
+
qleaner image public/images src -e public/images/icons -E __tests__ -S "**/*.test.*"
|
|
183
|
+
|
|
184
|
+
# Clear cache and scan
|
|
185
|
+
qleaner image public/images src --clear-cache
|
|
168
186
|
```
|
|
169
187
|
|
|
170
188
|
**What it detects:**
|
|
@@ -187,14 +205,13 @@ Qleaner provides two output formats:
|
|
|
187
205
|
- Cyan for dry run mode messages
|
|
188
206
|
|
|
189
207
|
2. **Table output**: Formatted tables with organized columns (use `--table` flag)
|
|
190
|
-
-
|
|
191
|
-
-
|
|
192
|
-
-
|
|
193
|
-
- Unused images table shows: Unused image paths (or "Would Delete" in dry run mode)
|
|
208
|
+
- Unused files table shows: Unused file paths with sizes (or "Would Delete" in dry run mode)
|
|
209
|
+
- Unused images table shows: Unused image paths with information about whether they exist and are referenced in code (or "Would Delete" in dry run mode)
|
|
210
|
+
- Summary tables show: Project statistics, largest files, dependencies, and more
|
|
194
211
|
|
|
195
212
|
## How It Works
|
|
196
213
|
|
|
197
|
-
### File Scanning (
|
|
214
|
+
### File Scanning (scan)
|
|
198
215
|
|
|
199
216
|
1. **File Discovery**: Recursively finds all `.tsx`, `.ts`, `.js`, and `.jsx` files in the specified directory
|
|
200
217
|
2. **Caching**: Checks cache for previously scanned files. Files that haven't changed are skipped for faster performance
|
|
@@ -205,7 +222,7 @@ Qleaner provides two output formats:
|
|
|
205
222
|
7. **Reporting**: Outputs the results in standard or table format based on your preferences
|
|
206
223
|
8. **Safe Deletion**: In dry run mode, shows what would be deleted without making changes. In normal mode, prompts for confirmation before deletion
|
|
207
224
|
|
|
208
|
-
### Image Scanning (
|
|
225
|
+
### Image Scanning (image)
|
|
209
226
|
|
|
210
227
|
1. **Image Discovery**: Recursively finds all image files (`.png`, `.jpg`, `.jpeg`, `.svg`, `.gif`, `.webp`) in the specified directory
|
|
211
228
|
2. **Code Scanning**: Scans all code files (`.js`, `.jsx`, `.ts`, `.tsx`) for image references
|
|
@@ -245,37 +262,65 @@ Qleaner provides two output formats:
|
|
|
245
262
|
|
|
246
263
|
- ๐งน **Code cleanup**: Remove dead code and unused files from your React projects
|
|
247
264
|
- ๐ผ๏ธ **Image cleanup**: Find and remove unused image assets to reduce project size
|
|
248
|
-
- ๐ **Code analysis**: Understand import patterns and dependencies in your codebase
|
|
265
|
+
- ๐ **Code analysis**: Understand import patterns and dependencies in your codebase through the summary command
|
|
249
266
|
- ๐ **Project audit**: Identify orphaned files and assets that may have been forgotten
|
|
250
267
|
- ๐ฆ **Bundle optimization**: Find files and images that can be removed to reduce bundle size
|
|
268
|
+
- ๐ **Project insights**: Analyze largest files, dependency patterns, and project statistics
|
|
251
269
|
- ๐ฏ **Maintenance**: Keep your codebase clean and maintainable
|
|
252
270
|
|
|
253
271
|
## Configuration
|
|
254
272
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
-
|
|
273
|
+
Qleaner supports configuration through both command-line options and a configuration file (`qleaner.config.json`). Use `qleaner init` to create a default configuration file.
|
|
274
|
+
|
|
275
|
+
### Configuration File
|
|
276
|
+
|
|
277
|
+
The `qleaner.config.json` file allows you to set default options that will be merged with command-line options. Command-line options take precedence over configuration file options.
|
|
278
|
+
|
|
279
|
+
**Configuration options:**
|
|
280
|
+
- `excludeDir` - Array of directories to exclude from scans
|
|
281
|
+
- `excludeFile` - Array of file patterns to exclude from scans
|
|
282
|
+
- `excludeExtensions` - Array of file extensions to exclude (e.g., `["test.tsx", "test.ts"]`)
|
|
283
|
+
- `excludeFilePrint` - Array of files to scan but not print in results
|
|
284
|
+
- `excludeDirAssets` - Array of directories to exclude from asset scans
|
|
285
|
+
- `excludeFileAssets` - Array of file patterns to exclude from asset scans
|
|
286
|
+
- `excludeDirCode` - Array of directories to exclude from code scans
|
|
287
|
+
- `excludeFileCode` - Array of file patterns to exclude from code scans
|
|
288
|
+
- `isRootFolderReferenced` - Boolean indicating if root folder is referenced in image paths
|
|
289
|
+
- `alias` - Boolean indicating if aliases are used in image paths
|
|
260
290
|
|
|
261
291
|
**Common exclusions:**
|
|
262
|
-
- Test files: `-f "**/*.test.*" "**/*.spec.*"`
|
|
292
|
+
- Test files: `-f "**/*.test.*" "**/*.spec.*"` or `excludeExtensions: ["test.tsx", "test.ts"]`
|
|
263
293
|
- Storybook files: `-f "**/*.stories.*"`
|
|
264
294
|
- Test directories: `-e __tests__ __mocks__ test`
|
|
265
295
|
- Build outputs: `-e dist build .next`
|
|
266
296
|
- Configuration files: `-f "**/*.config.*"`
|
|
267
297
|
- Third-party code: `-e node_modules vendor`
|
|
268
298
|
|
|
299
|
+
**Example configuration file:**
|
|
300
|
+
```json
|
|
301
|
+
{
|
|
302
|
+
"excludeDir": ["node_modules", "dist", "build"],
|
|
303
|
+
"excludeFile": [],
|
|
304
|
+
"excludeExtensions": ["test.tsx", "test.ts"],
|
|
305
|
+
"excludeFilePrint": ["page.tsx", "route.ts", "layout.tsx"],
|
|
306
|
+
"isRootFolderReferenced": false,
|
|
307
|
+
"alias": true
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
269
311
|
## Tips and Best Practices
|
|
270
312
|
|
|
271
313
|
1. **Start with a small scope**: Begin by scanning a specific directory before scanning the entire project
|
|
272
314
|
2. **Use dry run first**: Always run with `--dry-run` first to preview what would be deleted before actually deleting files
|
|
273
|
-
3. **Clear cache
|
|
274
|
-
4. **
|
|
275
|
-
5. **
|
|
276
|
-
6. **
|
|
277
|
-
7. **
|
|
278
|
-
8. **
|
|
315
|
+
3. **Clear cache before summary**: Before running `qleaner summary`, always run a fresh scan with `--clear-cache` to ensure accurate results. The summary reads from the cache, so outdated cache data will show outdated results
|
|
316
|
+
4. **Clear cache after code changes**: If you've made changes to your codebase (added/removed files, changed imports), use `--clear-cache` to ensure accurate results. The cache automatically invalidates when files change, but clearing it manually ensures a fresh scan
|
|
317
|
+
5. **Use exclusions**: Exclude test files and build outputs when scanning for unused files
|
|
318
|
+
6. **Review before deleting**: Always review the unused files list before removing them - some files might be used dynamically (e.g., through dynamic imports, configuration files, or asset references)
|
|
319
|
+
7. **Use table format**: The table format is easier to read for large results
|
|
320
|
+
8. **Combine options**: Use multiple flags together for comprehensive analysis
|
|
321
|
+
9. **Check dynamic imports**: Files imported using dynamic imports (`import()`) may appear as unused but are actually needed
|
|
322
|
+
10. **Image scanning setup**: For best results when scanning images, ensure images are located in one central location and use a uniform reference pattern (either aliases or root folder references consistently)
|
|
323
|
+
11. **Index file references**: Files or images referenced through index files (e.g., `/folderA/folderB` where `folderB` contains index files with exports) may be difficult to scan accurately. For proper scanning, ensure the full path to the actual file is used in references
|
|
279
324
|
|
|
280
325
|
## Important Notes
|
|
281
326
|
|
|
@@ -285,12 +330,24 @@ You can exclude directories and files from scanning using the command-line optio
|
|
|
285
330
|
- Required for build processes
|
|
286
331
|
- Used as entry points that aren't directly imported
|
|
287
332
|
|
|
333
|
+
โ ๏ธ **Generated/Compiled Code**: Scans do **not** work on generated or compiled code (e.g., `build`, `dist`, `.next` directories). Always scan your source code, not the compiled output. Exclude build directories from scans.
|
|
334
|
+
|
|
335
|
+
โ ๏ธ **Image Scanning Requirements**: For accurate image scanning results:
|
|
336
|
+
- Images should be located in **one central location** (single directory structure)
|
|
337
|
+
- Use a **uniform reference pattern** throughout your codebase - either consistently use aliases (e.g., `@/assets/images/`) or root folder references (e.g., `/img/`), but not both mixed
|
|
338
|
+
- The tool supports both patterns, but mixing them may lead to incomplete detection
|
|
339
|
+
|
|
340
|
+
โ ๏ธ **Index File Limitations**: Files or images referenced via index files (e.g., `/folderA/folderB` where `folderB` contains index files with exports) might be difficult to scan accurately. The tool may not always detect references when the path points to a folder containing an index file rather than the full path to the actual file. For proper scanning, ensure the full path to where the file is located is used in references (e.g., `/folderA/folderB/Component.tsx` instead of `/folderA/folderB`).
|
|
341
|
+
|
|
288
342
|
๐ก **Tip**: Always use `--dry-run` first to preview what would be deleted. This is especially important in CI/CD pipelines or when scanning large codebases.
|
|
289
343
|
|
|
344
|
+
๐ก **Summary Command**: Before running `qleaner summary`, always run a fresh scan with `--clear-cache` to ensure the summary shows accurate, up-to-date results. The summary reads from the cache, so outdated cache data will produce outdated summaries.
|
|
345
|
+
|
|
290
346
|
๐พ **Cache Management**: Qleaner uses intelligent caching to speed up scans. The cache automatically detects file changes via content hashing. However, if you've made significant changes to your codebase structure or want to ensure a completely fresh scan, use `--clear-cache` before scanning. This is particularly useful:
|
|
291
347
|
- After major refactoring
|
|
292
348
|
- When files have been moved or renamed
|
|
293
349
|
- When you want to ensure the most up-to-date results
|
|
350
|
+
- Before running the summary command
|
|
294
351
|
- In CI/CD pipelines where you want consistent, fresh scans
|
|
295
352
|
|
|
296
353
|
## Requirements
|
|
@@ -308,4 +365,4 @@ MIT
|
|
|
308
365
|
|
|
309
366
|
## Version
|
|
310
367
|
|
|
311
|
-
Current version: 1.0.
|
|
368
|
+
Current version: 1.0.34
|
package/bin/cli.js
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const { Command } = require("commander");
|
|
3
|
-
const {
|
|
4
|
-
const { clearCache } = require("../utils/cache");
|
|
3
|
+
const { summary, scan } = require("../controllers/list");
|
|
5
4
|
const { getUnusedImages } = require("../controllers/image");
|
|
5
|
+
const { init } = require("../controllers/initialize");
|
|
6
6
|
|
|
7
7
|
async function loadChalk() {
|
|
8
8
|
return (await import("chalk")).default;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
async function loadOra(){
|
|
12
|
+
return (await import("ora")).default
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
(async () => {
|
|
12
16
|
const chalk = await loadChalk();
|
|
17
|
+
const ora = await loadOra()
|
|
13
18
|
|
|
14
19
|
const program = new Command();
|
|
15
20
|
|
|
16
21
|
program
|
|
17
22
|
.name("qleaner")
|
|
18
23
|
.description("A tool to clean up your React code")
|
|
19
|
-
.version("1.0.
|
|
24
|
+
.version("1.0.34");
|
|
25
|
+
|
|
26
|
+
program.command("init")
|
|
27
|
+
.description("Initialize the project for Qleaner")
|
|
28
|
+
.action(async () => {
|
|
29
|
+
await init(chalk);
|
|
30
|
+
});
|
|
20
31
|
|
|
21
32
|
program
|
|
22
|
-
.command("
|
|
33
|
+
.command("summary")
|
|
23
34
|
.description("List all the imports in the project")
|
|
24
|
-
.
|
|
25
|
-
.option("-
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
.option("-f, --exclude-file <file...>", "Exclude files from the scan")
|
|
29
|
-
.option(
|
|
30
|
-
"-F, --exclude-file-print <file...>",
|
|
31
|
-
"Do not Print the excluded files"
|
|
32
|
-
)
|
|
33
|
-
.option("-t, --table", "Print the results in a table")
|
|
34
|
-
.action(async (path, options) => {
|
|
35
|
-
await list(chalk, path, options);
|
|
35
|
+
.option("-l, --largest-files", "List the largest files in the project")
|
|
36
|
+
.option("-d, --dependencies", "List the dependencies in the project")
|
|
37
|
+
.action(async (options) => {
|
|
38
|
+
await summary(chalk, options);
|
|
36
39
|
});
|
|
37
40
|
|
|
38
41
|
program
|
|
39
|
-
.command("
|
|
42
|
+
.command("scan")
|
|
40
43
|
.description("Scan the project for unused files")
|
|
41
44
|
.argument("<path>", "The path to the directory to scan for unused files")
|
|
42
45
|
.option("-e, --exclude-dir <dir...>", "Exclude directories from the scan")
|
|
@@ -45,39 +48,31 @@ async function loadChalk() {
|
|
|
45
48
|
"-F, --exclude-file-print <files...>",
|
|
46
49
|
"Scan but don't print the excluded files"
|
|
47
50
|
)
|
|
51
|
+
.option("-x, --exclude-extensions <extensions...>", "Exclude file extensions from the scan like .test.tsx, .test.ts, .test.js, .test.jsx")
|
|
48
52
|
.option("-t, --table", "Print the results in a table")
|
|
49
53
|
.option("-d, --dry-run", "Show what would be deleted without actually deleting (skips prompt)")
|
|
50
54
|
.option("-C, --clear-cache", "Clear the cache recommended after making code changes")
|
|
51
55
|
.action(async (path, options) => {
|
|
52
|
-
|
|
53
|
-
clearCache(process.cwd());
|
|
54
|
-
console.log(chalk.green('โ Cache cleared successfully'));
|
|
55
|
-
}
|
|
56
|
-
await scan(chalk, path, options);
|
|
56
|
+
await scan(ora,chalk, path, options);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
program
|
|
60
|
-
.command('
|
|
60
|
+
.command('image')
|
|
61
61
|
.description("Scan the project for unused images")
|
|
62
62
|
.argument("<directory>", "The path to the directory to scan for unused images")
|
|
63
63
|
.argument("<rootPath>", "The root path to the project code utilizing the images")
|
|
64
64
|
.option("-e, --exclude-dir-assets <dir...>", "Exclude directories from the scan")
|
|
65
|
-
.option("-f, --exclude-file-
|
|
66
|
-
.option(
|
|
67
|
-
"-F, --exclude-file-print-asset <files...>",
|
|
68
|
-
"Scan but don't print the excluded files"
|
|
69
|
-
)
|
|
65
|
+
.option("-f, --exclude-file-assets <file...>", "Exclude files from the scan")
|
|
70
66
|
.option("-E, --exclude-dir-code <dir...>", "Exclude directories from the scan")
|
|
71
67
|
.option("-S, --exclude-file-code <file...>", "Exclude files from the scan")
|
|
72
|
-
.option(
|
|
73
|
-
|
|
74
|
-
"Scan but don't print the excluded files"
|
|
75
|
-
)
|
|
68
|
+
.option("-r, --is-root-folder-referenced", "Is the root folder referenced in the image path eg /img/a.png where img is the root folder")
|
|
69
|
+
.option("-a, --alias", "Is the alias referenced in the image path eg @/assets/images/a.png")
|
|
76
70
|
.option("-t, --table", "Print the results in a table")
|
|
77
|
-
.option("-d, --dry-run", "Show what would be deleted without actually deleting (skips prompt)")
|
|
78
71
|
.option("-C, --clear-cache", "Clear the cache recommended after making code changes")
|
|
72
|
+
.option("-H, --hide-not-found-images", "Hide the images shown in code but not found in the image directory")
|
|
73
|
+
.option("-d, --dry-run", "Show what would be deleted without actually deleting (skips prompt)")
|
|
79
74
|
.action(async (directory, rootPath, options) => {
|
|
80
|
-
await getUnusedImages(chalk, directory, rootPath, options);
|
|
75
|
+
await getUnusedImages(ora,chalk, directory, rootPath, options);
|
|
81
76
|
});
|
|
82
77
|
program.parse(process.argv);
|
|
83
78
|
})();
|