codeinf 1.0.3 → 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.
Files changed (3) hide show
  1. package/bin/cli.js +35 -20
  2. package/index.js +28 -9
  3. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -27,12 +27,14 @@ function parseArgs(args) {
27
27
  const options = {
28
28
  path: '.',
29
29
  extensions: [],
30
- ignore: [],
30
+ ignoreDirs: [],
31
+ ignoreFiles: [],
31
32
  format: 'table',
32
33
  top: 10,
33
34
  help: false,
34
35
  version: false,
35
- noColor: false
36
+ noColor: false,
37
+ includeNodeModules: false
36
38
  };
37
39
 
38
40
  for (let i = 0; i < args.length; i++) {
@@ -58,11 +60,16 @@ function parseArgs(args) {
58
60
  });
59
61
  }
60
62
  break;
61
- case '-i':
62
- case '--ignore':
63
+ case '--ignore-dir':
63
64
  i++;
64
65
  if (args[i]) {
65
- options.ignore = args[i].split(',').map(s => s.trim());
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());
66
73
  }
67
74
  break;
68
75
  case '-f':
@@ -85,6 +92,9 @@ function parseArgs(args) {
85
92
  case '--no-color':
86
93
  options.noColor = true;
87
94
  break;
95
+ case '--include-node-modules':
96
+ options.includeNodeModules = true;
97
+ break;
88
98
  default:
89
99
  if (!arg.startsWith('-') && options.path === '.') {
90
100
  options.path = arg;
@@ -103,22 +113,25 @@ function showHelp() {
103
113
  ${c('Usage:', 'yellow')} codeinf [path] [options]
104
114
 
105
115
  ${c('Options:', 'yellow')}
106
- -h, --help Show this help message
107
- -v, --version Show version
108
- -e, --ext <exts> Filter by file extensions (comma-separated)
109
- -i, --ignore <patterns> Additional ignore patterns (comma-separated)
110
- -f, --format <format> Output format: ${c('table', 'green')}, ${c('json', 'green')}
111
- --json Output as JSON
112
- -t, --top <number> Number of largest files to show (default: 10)
113
- --no-color Disable colored output
116
+ -h, --help Show this help message
117
+ -v, --version Show version
118
+ -e, --ext <exts> Filter by file extensions (comma-separated)
119
+ --ignore-dir <dirs> Ignore directories (comma-separated)
120
+ --ignore-file <files> Ignore files by name (comma-separated)
121
+ -f, --format <format> Output format: ${c('table', 'green')}, ${c('json', 'green')}
122
+ --json Output as JSON
123
+ -t, --top <number> Number of largest files to show (default: 10)
124
+ --no-color Disable colored output
125
+ --include-node-modules Include node_modules in analysis (default: ignored)
114
126
 
115
127
  ${c('Examples:', 'yellow')}
116
- ${c('codeinf', 'cyan')} Analyze current directory
117
- ${c('codeinf ./src', 'cyan')} Analyze src directory
118
- ${c('codeinf -e js,ts', 'cyan')} Analyze only JS and TS files
119
- ${c('codeinf -e .js --json', 'cyan')} Output JS stats as JSON
120
- ${c('codeinf -i "test,dist"', 'cyan')} Ignore test and dist folders
121
- ${c('codeinf -t 20', 'cyan')} Show top 20 largest files
128
+ ${c('codeinf', 'cyan')} Analyze current directory
129
+ ${c('codeinf ./src', 'cyan')} Analyze src directory
130
+ ${c('codeinf -e js,ts', 'cyan')} Analyze only JS and TS files
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
133
+ ${c('codeinf -t 20', 'cyan')} Show top 20 largest files
134
+ ${c('codeinf --include-node-modules', 'cyan')} Include node_modules
122
135
  `);
123
136
  }
124
137
 
@@ -260,7 +273,9 @@ async function main() {
260
273
  try {
261
274
  const result = analyze(options.path, {
262
275
  extensions: options.extensions,
263
- ignore: options.ignore
276
+ ignoreDirs: options.ignoreDirs,
277
+ ignoreFiles: options.ignoreFiles,
278
+ includeNodeModules: options.includeNodeModules
264
279
  });
265
280
 
266
281
  if (options.format === 'json') {
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 shouldIgnore(filePath, ignorePatterns = []) {
30
+ function shouldIgnoreDir(dirPath, ignorePatterns = []) {
31
31
  const allIgnores = [...DEFAULT_IGNORES, ...ignorePatterns];
32
- const parts = filePath.split(path.sep);
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,19 +73,37 @@ function getFileStats(filePath) {
72
73
  function scanDirectory(dir, options = {}) {
73
74
  const {
74
75
  extensions = [],
75
- ignore = [],
76
- recursive = true
76
+ ignoreDirs = [],
77
+ ignoreFiles = [],
78
+ recursive = true,
79
+ includeNodeModules = false
77
80
  } = options;
78
81
 
82
+ // Build ignore list for directories
83
+ const dirIgnores = includeNodeModules
84
+ ? ignoreDirs
85
+ : [...ignoreDirs, 'node_modules'];
86
+
79
87
  const results = [];
80
88
 
81
89
  function scan(currentPath) {
82
- if (shouldIgnore(currentPath, ignore)) {
83
- return;
84
- }
85
-
90
+ const fileName = path.basename(currentPath);
91
+
86
92
  try {
87
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
+ }
88
107
 
89
108
  if (stats.isDirectory()) {
90
109
  if (recursive) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeinf",
3
- "version": "1.0.3",
3
+ "version": "1.0.7",
4
4
  "description": "A CLI tool to analyze code statistics like lines of code, file counts, and more with filtering capabilities",
5
5
  "main": "index.js",
6
6
  "bin": "./bin/cli.js",