codeinf 1.0.4 → 1.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.
- package/bin/cli.js +16 -8
- package/index.js +25 -12
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -27,7 +27,8 @@ function parseArgs(args) {
|
|
|
27
27
|
const options = {
|
|
28
28
|
path: '.',
|
|
29
29
|
extensions: [],
|
|
30
|
-
|
|
30
|
+
ignoreDirs: [],
|
|
31
|
+
ignoreFiles: [],
|
|
31
32
|
format: 'table',
|
|
32
33
|
top: 10,
|
|
33
34
|
help: false,
|
|
@@ -59,11 +60,16 @@ function parseArgs(args) {
|
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
break;
|
|
62
|
-
case '-
|
|
63
|
-
case '--ignore':
|
|
63
|
+
case '--ignore-dir':
|
|
64
64
|
i++;
|
|
65
65
|
if (args[i]) {
|
|
66
|
-
options.
|
|
66
|
+
options.ignoreDirs = args[i].split(',').map(s => s.trim());
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case '--ignore-file':
|
|
70
|
+
i++;
|
|
71
|
+
if (args[i]) {
|
|
72
|
+
options.ignoreFiles = args[i].split(',').map(s => s.trim());
|
|
67
73
|
}
|
|
68
74
|
break;
|
|
69
75
|
case '-f':
|
|
@@ -110,7 +116,8 @@ function showHelp() {
|
|
|
110
116
|
-h, --help Show this help message
|
|
111
117
|
-v, --version Show version
|
|
112
118
|
-e, --ext <exts> Filter by file extensions (comma-separated)
|
|
113
|
-
|
|
119
|
+
--ignore-dir <dirs> Ignore directories (comma-separated)
|
|
120
|
+
--ignore-file <files> Ignore files by name (comma-separated)
|
|
114
121
|
-f, --format <format> Output format: ${c('table', 'green')}, ${c('json', 'green')}
|
|
115
122
|
--json Output as JSON
|
|
116
123
|
-t, --top <number> Number of largest files to show (default: 10)
|
|
@@ -121,8 +128,8 @@ function showHelp() {
|
|
|
121
128
|
${c('codeinf', 'cyan')} Analyze current directory
|
|
122
129
|
${c('codeinf ./src', 'cyan')} Analyze src directory
|
|
123
130
|
${c('codeinf -e js,ts', 'cyan')} Analyze only JS and TS files
|
|
124
|
-
${c('codeinf -
|
|
125
|
-
${c('codeinf -
|
|
131
|
+
${c('codeinf --ignore-dir test,dist', 'cyan')} Ignore test and dist folders
|
|
132
|
+
${c('codeinf --ignore-file config.js,test.ts', 'cyan')} Ignore specific files
|
|
126
133
|
${c('codeinf -t 20', 'cyan')} Show top 20 largest files
|
|
127
134
|
${c('codeinf --include-node-modules', 'cyan')} Include node_modules
|
|
128
135
|
`);
|
|
@@ -266,7 +273,8 @@ async function main() {
|
|
|
266
273
|
try {
|
|
267
274
|
const result = analyze(options.path, {
|
|
268
275
|
extensions: options.extensions,
|
|
269
|
-
|
|
276
|
+
ignoreDirs: options.ignoreDirs,
|
|
277
|
+
ignoreFiles: options.ignoreFiles,
|
|
270
278
|
includeNodeModules: options.includeNodeModules
|
|
271
279
|
});
|
|
272
280
|
|
package/index.js
CHANGED
|
@@ -27,11 +27,12 @@ const DEFAULT_IGNORES = [
|
|
|
27
27
|
* @param {string[]} ignorePatterns - Patterns to ignore
|
|
28
28
|
* @returns {boolean}
|
|
29
29
|
*/
|
|
30
|
-
function
|
|
30
|
+
function shouldIgnoreDir(dirPath, ignorePatterns = []) {
|
|
31
31
|
const allIgnores = [...DEFAULT_IGNORES, ...ignorePatterns];
|
|
32
|
-
const parts =
|
|
32
|
+
const parts = dirPath.split(path.sep);
|
|
33
|
+
// Check if any part of the path matches an ignore pattern
|
|
33
34
|
return allIgnores.some(pattern =>
|
|
34
|
-
parts.some(part => part === pattern || part.match(new RegExp(pattern)))
|
|
35
|
+
parts.some(part => part === pattern || (pattern.includes('*') && part.match(new RegExp(pattern.replace(/\*/g, '.*')))))
|
|
35
36
|
);
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -72,25 +73,37 @@ function getFileStats(filePath) {
|
|
|
72
73
|
function scanDirectory(dir, options = {}) {
|
|
73
74
|
const {
|
|
74
75
|
extensions = [],
|
|
75
|
-
|
|
76
|
+
ignoreDirs = [],
|
|
77
|
+
ignoreFiles = [],
|
|
76
78
|
recursive = true,
|
|
77
79
|
includeNodeModules = false
|
|
78
80
|
} = options;
|
|
79
81
|
|
|
80
|
-
//
|
|
81
|
-
const
|
|
82
|
-
?
|
|
83
|
-
: [...
|
|
82
|
+
// Build ignore list for directories
|
|
83
|
+
const dirIgnores = includeNodeModules
|
|
84
|
+
? ignoreDirs
|
|
85
|
+
: [...ignoreDirs, 'node_modules'];
|
|
84
86
|
|
|
85
87
|
const results = [];
|
|
86
88
|
|
|
87
89
|
function scan(currentPath) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
90
|
+
const fileName = path.basename(currentPath);
|
|
91
|
+
|
|
92
92
|
try {
|
|
93
93
|
const stats = fs.statSync(currentPath);
|
|
94
|
+
const isDir = stats.isDirectory();
|
|
95
|
+
|
|
96
|
+
// Check if directory should be ignored
|
|
97
|
+
if (isDir) {
|
|
98
|
+
if (shouldIgnoreDir(currentPath, dirIgnores)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
// Check if file should be ignored by name
|
|
103
|
+
if (ignoreFiles.includes(fileName)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
94
107
|
|
|
95
108
|
if (stats.isDirectory()) {
|
|
96
109
|
if (recursive) {
|
package/package.json
CHANGED