qleaner 1.0.10 → 1.0.11

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 CHANGED
@@ -1,14 +1,15 @@
1
1
  # Qleaner
2
2
 
3
- A powerful CLI tool to analyze and clean up your React codebase by finding unused files and listing all imports. Built with Node.js and Babel AST parsing.
3
+ A powerful CLI tool to analyze and clean up your React codebase by finding unused files and listing all imports.
4
4
 
5
5
  ## Features
6
6
 
7
7
  - 🔍 **Scan for unused files**: Identify files that are not imported anywhere in your project
8
- - 📋 **List all imports**: Get a complete list of all import statements in your codebase
8
+ - 📋 **List all imports**: Get a complete list of all import statements in your codebase with file locations
9
9
  - 🎯 **File listing**: List all files in your project
10
+ - 📊 **Table output**: Display results in formatted tables for better readability
10
11
  - ⚙️ **Flexible configuration**: Exclude directories and files from scanning
11
- - 🚀 **Fast performance**: Uses fast-glob for efficient file scanning
12
+ - 🚀 **Fast performance**: Efficient file scanning across large codebases
12
13
  - 💪 **TypeScript support**: Works with TypeScript, JavaScript, JSX, and TSX files
13
14
 
14
15
  ## Installation
@@ -40,6 +41,7 @@ qleaner qlean-list <path> [options]
40
41
  - `-e, --exclude-dir <dir...>` - Exclude directories from the scan
41
42
  - `-f, --exclude-file <file...>` - Exclude files from the scan
42
43
  - `-F, --exclude-file-print <file...>` - Do not print the excluded files
44
+ - `-t, --table` - Display results in a formatted table
43
45
 
44
46
  **Examples:**
45
47
 
@@ -50,11 +52,17 @@ qleaner qlean-list src --list-files
50
52
  # List all imports in src directory
51
53
  qleaner qlean-list src --list-imports
52
54
 
55
+ # List both files and imports in table format
56
+ qleaner qlean-list src --list-files --list-imports --table
57
+
53
58
  # List files excluding node_modules and dist
54
59
  qleaner qlean-list src --list-files -e node_modules dist
55
60
 
56
61
  # List imports excluding specific files
57
62
  qleaner qlean-list src --list-imports -f "**/*.test.js" "**/*.spec.js"
63
+
64
+ # List with table output
65
+ qleaner qlean-list src --list-files --list-imports --table
58
66
  ```
59
67
 
60
68
  ### Scan for Unused Files
@@ -69,6 +77,7 @@ qleaner qlean-scan <path> [options]
69
77
  - `-e, --exclude-dir <dir...>` - Exclude directories from the scan
70
78
  - `-f, --exclude-file <file...>` - Exclude files from the scan
71
79
  - `-F, --exclude-file-print <files...>` - Do not print the excluded files
80
+ - `-t, --table` - Display results in a formatted table
72
81
 
73
82
  **Examples:**
74
83
 
@@ -76,6 +85,9 @@ qleaner qlean-scan <path> [options]
76
85
  # Scan src directory for unused files
77
86
  qleaner qlean-scan src
78
87
 
88
+ # Display unused files in a table format
89
+ qleaner qlean-scan src --table
90
+
79
91
  # Scan excluding test directories
80
92
  qleaner qlean-scan src -e __tests__ __mocks__ test
81
93
 
@@ -84,14 +96,31 @@ qleaner qlean-scan src -f "**/*.test.js" "**/*.stories.js"
84
96
 
85
97
  # Scan with multiple exclusions
86
98
  qleaner qlean-scan src -e node_modules dist -f "**/*.config.js"
99
+
100
+ # Scan with table output and exclusions
101
+ qleaner qlean-scan src --table -e __tests__ dist -f "**/*.config.js"
87
102
  ```
88
103
 
104
+ ## Output Formats
105
+
106
+ Qleaner provides two output formats:
107
+
108
+ 1. **Standard output**: Color-coded text output
109
+ - Green for files
110
+ - Yellow for imports
111
+ - Red for unused files
112
+
113
+ 2. **Table output**: Formatted tables with organized columns (use `--table` flag)
114
+ - Import tables show: File, Line, Column, and Import path
115
+ - File tables show: File path
116
+ - Unused files table shows: Unused file paths
117
+
89
118
  ## How It Works
90
119
 
91
- 1. **File Discovery**: Uses `fast-glob` to recursively find all `.tsx`, `.ts`, `.js`, and `.jsx` files in the specified directory
92
- 2. **AST Parsing**: Uses Babel parser to parse files and extract import statements
120
+ 1. **File Discovery**: Recursively finds all `.tsx`, `.ts`, `.js`, and `.jsx` files in the specified directory
121
+ 2. **Import Extraction**: Parses files and extracts all import statements
93
122
  3. **Analysis**: Compares file paths with import paths to identify unused files
94
- 4. **Reporting**: Outputs the results based on the selected command and options
123
+ 4. **Reporting**: Outputs the results in standard or table format based on your preferences
95
124
 
96
125
  ## Supported File Types
97
126
 
@@ -106,6 +135,7 @@ qleaner qlean-scan src -e node_modules dist -f "**/*.config.js"
106
135
  - 📊 **Code analysis**: Understand import patterns and dependencies in your codebase
107
136
  - 🔍 **Project audit**: Identify orphaned files that may have been forgotten
108
137
  - 📦 **Bundle optimization**: Find files that can be removed to reduce bundle size
138
+ - 🎯 **Maintenance**: Keep your codebase clean and maintainable
109
139
 
110
140
  ## Configuration
111
141
 
@@ -115,6 +145,31 @@ You can exclude directories and files from scanning using the command-line optio
115
145
  - Excluding third-party libraries
116
146
  - Excluding configuration files
117
147
 
148
+ **Common exclusions:**
149
+ - Test files: `-f "**/*.test.*" "**/*.spec.*"`
150
+ - Storybook files: `-f "**/*.stories.*"`
151
+ - Test directories: `-e __tests__ __mocks__ test`
152
+ - Build outputs: `-e dist build .next`
153
+ - Configuration files: `-f "**/*.config.*"`
154
+ - Third-party code: `-e node_modules vendor`
155
+
156
+ ## Tips and Best Practices
157
+
158
+ 1. **Start with a small scope**: Begin by scanning a specific directory before scanning the entire project
159
+ 2. **Use exclusions**: Exclude test files and build outputs when scanning for unused files
160
+ 3. **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)
161
+ 4. **Use table format**: The table format is easier to read for large results
162
+ 5. **Combine options**: Use multiple flags together for comprehensive analysis
163
+ 6. **Check dynamic imports**: Files imported using dynamic imports (`import()`) may appear as unused but are actually needed
164
+
165
+ ## Important Notes
166
+
167
+ ⚠️ **Warning**: Always review files before deletion. Some files might be:
168
+ - Used dynamically (dynamic imports)
169
+ - Referenced in configuration files
170
+ - Required for build processes
171
+ - Used as entry points that aren't directly imported
172
+
118
173
  ## Requirements
119
174
 
120
175
  - Node.js 14+
package/bin/cli.js CHANGED
@@ -48,7 +48,7 @@ async function loadChalk() {
48
48
  .option("-f, --exclude-file <file...>", "Exclude files from the scan")
49
49
  .option(
50
50
  "-F, --exclude-file-print <files...>",
51
- "Do not Print the excluded files"
51
+ "Scan but don't print the excluded files"
52
52
  )
53
53
  .option("-t, --table", "Print the results in a table")
54
54
  .action(async (path, options) => {
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.10",
4
+ "version": "1.0.11",
5
5
  "main": "command.js",
6
6
  "bin": "./bin/cli.js",
7
7
  "scripts": {
@@ -17,6 +17,7 @@
17
17
  "chalk": "^5.6.2",
18
18
  "cli-table3": "^0.6.5",
19
19
  "commander": "^14.0.2",
20
- "fast-glob": "^3.3.3"
20
+ "fast-glob": "^3.3.3",
21
+ "prompts": "^2.4.2"
21
22
  }
22
23
  }
package/utils/utils.js ADDED
@@ -0,0 +1,57 @@
1
+ const prompts = require('prompts');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ async function askDeleteFiles(files) {
6
+ const response = await prompts({
7
+ type: 'multiselect',
8
+ name: 'toDelete',
9
+ message: 'Select unused files to delete or move to .trash directory',
10
+ choices: files.map(file => ({
11
+ title: file,
12
+ value: file,
13
+ }))
14
+ })
15
+ if(response && response.toDelete && response.toDelete.length > 0) {
16
+ const method = await prompts({
17
+ type: 'select',
18
+ name: 'method',
19
+ message: 'Select a method to delete the files',
20
+ choices: [
21
+ { title: 'Move to .trash directory', value: 'moveToTrash' },
22
+ { title: 'Delete files', value: 'deleteFiles' },
23
+ ]
24
+ })
25
+ if(method.method === 'moveToTrash') {
26
+ return await moveToTrash(response.toDelete);
27
+ } else if(method.method === 'deleteFiles') {
28
+ return await deleteFiles(response.toDelete);
29
+ }
30
+ }
31
+ return response && response.toDelete ? response.toDelete : [];
32
+ }
33
+
34
+ async function moveToTrash(files) {
35
+ const trashDir = path.join(process.cwd(), '.trash');
36
+
37
+ if(!fs.existsSync(trashDir)) {
38
+ fs.mkdirSync(trashDir);
39
+ }
40
+
41
+ for(const file of files) {
42
+ const fileName = path.basename(file);
43
+ const destination = path.join(trashDir, fileName);
44
+ fs.renameSync(file, destination);
45
+ }
46
+
47
+ console.log(`Moved ${files.length} files to .trash directory`);
48
+ }
49
+
50
+ async function deleteFiles(files) {
51
+ for(const file of files) {
52
+ fs.unlinkSync(file);
53
+ }
54
+ console.log(`Deleted ${files.length} files`);
55
+ }
56
+
57
+ module.exports = askDeleteFiles;