@ivorisnoob/linecount 1.0.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/LICENSE +21 -0
- package/README.md +180 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +32 -0
- package/dist/cli.js.map +1 -0
- package/dist/comments.d.ts +8 -0
- package/dist/comments.d.ts.map +1 -0
- package/dist/comments.js +229 -0
- package/dist/comments.js.map +1 -0
- package/dist/counter.d.ts +29 -0
- package/dist/counter.d.ts.map +1 -0
- package/dist/counter.js +84 -0
- package/dist/counter.js.map +1 -0
- package/dist/defaults.d.ts +4 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +184 -0
- package/dist/defaults.js.map +1 -0
- package/dist/formatter.d.ts +6 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +48 -0
- package/dist/formatter.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# linecount
|
|
2
|
+
|
|
3
|
+
A fast, intelligent line counter that automatically ignores common build artifacts, dependencies, and version control files. Built as a modern alternative to CLOC with sensible defaults for contemporary development workflows.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Fast recursive directory scanning with async I/O
|
|
8
|
+
- Smart defaults that automatically ignore build artifacts and dependencies
|
|
9
|
+
- Comment detection for 30+ programming languages
|
|
10
|
+
- Clean, colorized table output
|
|
11
|
+
- Works as both a CLI tool and importable library
|
|
12
|
+
- Configurable ignore patterns and directories
|
|
13
|
+
- Zero runtime dependencies
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Install globally to use as a command-line tool:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g linecount
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or install locally in your project:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install linecount
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Command Line
|
|
32
|
+
|
|
33
|
+
Count lines in the current directory:
|
|
34
|
+
```bash
|
|
35
|
+
linecount
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Count lines in a specific directory:
|
|
39
|
+
```bash
|
|
40
|
+
linecount ./src
|
|
41
|
+
linecount /path/to/project
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Show help information:
|
|
45
|
+
```bash
|
|
46
|
+
linecount --help
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### As a Library
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { LineCounter } from 'linecount';
|
|
53
|
+
|
|
54
|
+
const counter = new LineCounter();
|
|
55
|
+
const result = await counter.count('./my-project');
|
|
56
|
+
|
|
57
|
+
console.log(`Total files: ${result.totalFiles}`);
|
|
58
|
+
console.log(`Total lines: ${result.totalLines}`);
|
|
59
|
+
console.log(`Code lines: ${result.totalCode}`);
|
|
60
|
+
console.log(`Comment lines: ${result.totalComments}`);
|
|
61
|
+
console.log(`Blank lines: ${result.totalBlank}`);
|
|
62
|
+
|
|
63
|
+
// Access per-extension statistics
|
|
64
|
+
for (const [ext, stats] of result.byExtension) {
|
|
65
|
+
console.log(`${ext}: ${stats.code} lines of code`);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Custom Configuration
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { LineCounter } from 'linecount';
|
|
73
|
+
|
|
74
|
+
const counter = new LineCounter({
|
|
75
|
+
ignoreDirs: new Set(['node_modules', 'custom-dir']),
|
|
76
|
+
ignorePatterns: [/\.test\.js$/, /\.spec\.ts$/],
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const result = await counter.count('./src');
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## What Gets Ignored by Default
|
|
83
|
+
|
|
84
|
+
### Directories
|
|
85
|
+
|
|
86
|
+
**Package managers and dependencies:**
|
|
87
|
+
- node_modules, bower_components, vendor, Pods, Carthage
|
|
88
|
+
- .pub-cache, site-packages, __pypackages__
|
|
89
|
+
|
|
90
|
+
**Version control:**
|
|
91
|
+
- .git, .svn, .hg
|
|
92
|
+
|
|
93
|
+
**IDE and editor folders:**
|
|
94
|
+
- .idea, .vscode, .vs, .cursor, .windsurf
|
|
95
|
+
|
|
96
|
+
**Build outputs:**
|
|
97
|
+
- dist, build, out, target, bin, obj, Debug, Release
|
|
98
|
+
- DerivedData, .build, cmake-build-debug, cmake-build-release
|
|
99
|
+
|
|
100
|
+
**Test coverage:**
|
|
101
|
+
- coverage, .nyc_output, TestResults
|
|
102
|
+
|
|
103
|
+
**Cache directories:**
|
|
104
|
+
- .cache, .parcel-cache, .next, .nuxt, .turbo
|
|
105
|
+
- __pycache__, .pytest_cache, .mypy_cache, .ruff_cache
|
|
106
|
+
- .gradle, .m2, .dart_tool
|
|
107
|
+
|
|
108
|
+
**Framework-specific:**
|
|
109
|
+
- .terraform, .vagrant, .stack-work, .elixir_ls
|
|
110
|
+
|
|
111
|
+
### Files
|
|
112
|
+
|
|
113
|
+
**Lock files:**
|
|
114
|
+
- package-lock.json, yarn.lock, pnpm-lock.yaml
|
|
115
|
+
- Gemfile.lock, Cargo.lock, Podfile.lock, composer.lock, poetry.lock
|
|
116
|
+
|
|
117
|
+
**Minified and bundled files:**
|
|
118
|
+
- *.min.js, *.bundle.js, *.map
|
|
119
|
+
|
|
120
|
+
**Generated files:**
|
|
121
|
+
- *.generated.swift, *.g.dart, *.pb.go, *_pb2.py
|
|
122
|
+
- *.designer.cs, AssemblyInfo.cs
|
|
123
|
+
|
|
124
|
+
**Config and ignore files:**
|
|
125
|
+
- .gitignore, .gitattributes, .npmignore, .dockerignore
|
|
126
|
+
- .cursorignore, .cursorrules, .editorconfig
|
|
127
|
+
|
|
128
|
+
**Binary and media files:**
|
|
129
|
+
- Images: jpg, png, gif, svg, ico, webp
|
|
130
|
+
- Videos: mp4, avi, mov, wmv
|
|
131
|
+
- Archives: zip, tar, gz, rar, 7z
|
|
132
|
+
- Documents: pdf, doc, docx, xls, xlsx
|
|
133
|
+
- Executables: exe, dll, so, dylib, apk, ipa
|
|
134
|
+
|
|
135
|
+
## Supported Languages for Comment Detection
|
|
136
|
+
|
|
137
|
+
The tool accurately detects and counts comments in:
|
|
138
|
+
|
|
139
|
+
**C-style comments (// and /* */):**
|
|
140
|
+
JavaScript, TypeScript, Java, C, C++, C#, Go, Rust, Swift, Kotlin, PHP
|
|
141
|
+
|
|
142
|
+
**Hash comments (#):**
|
|
143
|
+
Python, Ruby, Shell scripts (bash, zsh), YAML, TOML, Perl, Elixir, R
|
|
144
|
+
|
|
145
|
+
**SQL comments (-- and /* */):**
|
|
146
|
+
SQL, Lua
|
|
147
|
+
|
|
148
|
+
**Other languages:**
|
|
149
|
+
HTML/XML, CSS/SCSS/LESS, Haskell, OCaml, Lisp, Clojure, Erlang, Vim script, MATLAB
|
|
150
|
+
|
|
151
|
+
## Output Format
|
|
152
|
+
|
|
153
|
+
The tool displays results in a clean table format:
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
Language Files Lines Blank Comment Code
|
|
157
|
+
.ts 6 450 50 80 320
|
|
158
|
+
.js 3 200 25 30 145
|
|
159
|
+
.json 2 80 5 0 75
|
|
160
|
+
Total 11 730 80 110 540
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Why linecount?
|
|
164
|
+
|
|
165
|
+
Unlike traditional line counters, linecount is built for modern development:
|
|
166
|
+
|
|
167
|
+
- Automatically ignores everything you don't want to count
|
|
168
|
+
- No configuration needed for most projects
|
|
169
|
+
- Understands modern frameworks and tooling (Next.js, Flutter, Rust, etc.)
|
|
170
|
+
- Fast async I/O for large codebases
|
|
171
|
+
- Clean, readable output with color coding
|
|
172
|
+
- Can be used programmatically in Node.js applications
|
|
173
|
+
|
|
174
|
+
## Requirements
|
|
175
|
+
|
|
176
|
+
Node.js 18.0.0 or higher
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { LineCounter } from './counter.js';
|
|
4
|
+
import { ResultFormatter } from './formatter.js';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
8
|
+
console.log(chalk.cyan.bold('\n📊 linecount') + chalk.gray(' - A fast, intelligent line counter\n'));
|
|
9
|
+
console.log(chalk.white('Usage:'));
|
|
10
|
+
console.log(chalk.gray(' linecount [path] ') + 'Count lines in the specified directory');
|
|
11
|
+
console.log(chalk.gray(' linecount ') + 'Count lines in the current directory');
|
|
12
|
+
console.log(chalk.gray(' linecount --help ') + 'Show this help message\n');
|
|
13
|
+
console.log(chalk.white('Examples:'));
|
|
14
|
+
console.log(chalk.gray(' linecount ') + 'Count lines in current directory');
|
|
15
|
+
console.log(chalk.gray(' linecount ./src ') + 'Count lines in src directory');
|
|
16
|
+
console.log(chalk.gray(' linecount /path/to/project ') + 'Count lines in specific project\n');
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
19
|
+
const targetPath = args[0] ? resolve(args[0]) : process.cwd();
|
|
20
|
+
console.log(chalk.cyan('\n📊 Counting lines in: ') + chalk.white(targetPath));
|
|
21
|
+
const counter = new LineCounter();
|
|
22
|
+
const formatter = new ResultFormatter();
|
|
23
|
+
try {
|
|
24
|
+
const result = await counter.count(targetPath);
|
|
25
|
+
console.log(formatter.format(result));
|
|
26
|
+
console.log(chalk.green('✓ ') + chalk.gray(`Analyzed ${result.totalFiles} files\n`));
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(chalk.red('✗ Error: ') + (error instanceof Error ? error.message : 'Unknown error'));
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|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LineEnd: RegExp[];
|
|
5
|
+
}
|
|
6
|
+
export declare const COMMENT_PATTERNS: Record<string, CommentPatterns>;
|
|
7
|
+
export declare function countComments(lines: string[], ext: string): number;
|
|
8
|
+
//# sourceMappingURL=comments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../src/comments.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAoM5D,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAkClE"}
|
package/dist/comments.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
export const COMMENT_PATTERNS = {
|
|
2
|
+
'.js': {
|
|
3
|
+
singleLine: [/^\s*\/\//],
|
|
4
|
+
multiLineStart: [/^\s*\/\*/],
|
|
5
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
6
|
+
},
|
|
7
|
+
'.jsx': {
|
|
8
|
+
singleLine: [/^\s*\/\//],
|
|
9
|
+
multiLineStart: [/^\s*\/\*/],
|
|
10
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
11
|
+
},
|
|
12
|
+
'.ts': {
|
|
13
|
+
singleLine: [/^\s*\/\//],
|
|
14
|
+
multiLineStart: [/^\s*\/\*/],
|
|
15
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
16
|
+
},
|
|
17
|
+
'.tsx': {
|
|
18
|
+
singleLine: [/^\s*\/\//],
|
|
19
|
+
multiLineStart: [/^\s*\/\*/],
|
|
20
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
21
|
+
},
|
|
22
|
+
'.java': {
|
|
23
|
+
singleLine: [/^\s*\/\//],
|
|
24
|
+
multiLineStart: [/^\s*\/\*/],
|
|
25
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
26
|
+
},
|
|
27
|
+
'.c': {
|
|
28
|
+
singleLine: [/^\s*\/\//],
|
|
29
|
+
multiLineStart: [/^\s*\/\*/],
|
|
30
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
31
|
+
},
|
|
32
|
+
'.cpp': {
|
|
33
|
+
singleLine: [/^\s*\/\//],
|
|
34
|
+
multiLineStart: [/^\s*\/\*/],
|
|
35
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
36
|
+
},
|
|
37
|
+
'.cs': {
|
|
38
|
+
singleLine: [/^\s*\/\//],
|
|
39
|
+
multiLineStart: [/^\s*\/\*/],
|
|
40
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
41
|
+
},
|
|
42
|
+
'.go': {
|
|
43
|
+
singleLine: [/^\s*\/\//],
|
|
44
|
+
multiLineStart: [/^\s*\/\*/],
|
|
45
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
46
|
+
},
|
|
47
|
+
'.rs': {
|
|
48
|
+
singleLine: [/^\s*\/\//],
|
|
49
|
+
multiLineStart: [/^\s*\/\*/],
|
|
50
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
51
|
+
},
|
|
52
|
+
'.swift': {
|
|
53
|
+
singleLine: [/^\s*\/\//],
|
|
54
|
+
multiLineStart: [/^\s*\/\*/],
|
|
55
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
56
|
+
},
|
|
57
|
+
'.kt': {
|
|
58
|
+
singleLine: [/^\s*\/\//],
|
|
59
|
+
multiLineStart: [/^\s*\/\*/],
|
|
60
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
61
|
+
},
|
|
62
|
+
'.php': {
|
|
63
|
+
singleLine: [/^\s*\/\//, /^\s*#/],
|
|
64
|
+
multiLineStart: [/^\s*\/\*/],
|
|
65
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
66
|
+
},
|
|
67
|
+
'.py': {
|
|
68
|
+
singleLine: [/^\s*#/],
|
|
69
|
+
multiLineStart: [/^\s*"""/, /^\s*'''/],
|
|
70
|
+
multiLineEnd: [/"""\s*$/, /'''\s*$/],
|
|
71
|
+
},
|
|
72
|
+
'.rb': {
|
|
73
|
+
singleLine: [/^\s*#/],
|
|
74
|
+
multiLineStart: [/^\s*=begin/],
|
|
75
|
+
multiLineEnd: [/^\s*=end/],
|
|
76
|
+
},
|
|
77
|
+
'.sh': {
|
|
78
|
+
singleLine: [/^\s*#/],
|
|
79
|
+
multiLineStart: [],
|
|
80
|
+
multiLineEnd: [],
|
|
81
|
+
},
|
|
82
|
+
'.bash': {
|
|
83
|
+
singleLine: [/^\s*#/],
|
|
84
|
+
multiLineStart: [],
|
|
85
|
+
multiLineEnd: [],
|
|
86
|
+
},
|
|
87
|
+
'.zsh': {
|
|
88
|
+
singleLine: [/^\s*#/],
|
|
89
|
+
multiLineStart: [],
|
|
90
|
+
multiLineEnd: [],
|
|
91
|
+
},
|
|
92
|
+
'.yaml': {
|
|
93
|
+
singleLine: [/^\s*#/],
|
|
94
|
+
multiLineStart: [],
|
|
95
|
+
multiLineEnd: [],
|
|
96
|
+
},
|
|
97
|
+
'.yml': {
|
|
98
|
+
singleLine: [/^\s*#/],
|
|
99
|
+
multiLineStart: [],
|
|
100
|
+
multiLineEnd: [],
|
|
101
|
+
},
|
|
102
|
+
'.toml': {
|
|
103
|
+
singleLine: [/^\s*#/],
|
|
104
|
+
multiLineStart: [],
|
|
105
|
+
multiLineEnd: [],
|
|
106
|
+
},
|
|
107
|
+
'.sql': {
|
|
108
|
+
singleLine: [/^\s*--/],
|
|
109
|
+
multiLineStart: [/^\s*\/\*/],
|
|
110
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
111
|
+
},
|
|
112
|
+
'.lua': {
|
|
113
|
+
singleLine: [/^\s*--/],
|
|
114
|
+
multiLineStart: [/^\s*--\[\[/],
|
|
115
|
+
multiLineEnd: [/\]\]\s*$/],
|
|
116
|
+
},
|
|
117
|
+
'.vim': {
|
|
118
|
+
singleLine: [/^\s*"/],
|
|
119
|
+
multiLineStart: [],
|
|
120
|
+
multiLineEnd: [],
|
|
121
|
+
},
|
|
122
|
+
'.el': {
|
|
123
|
+
singleLine: [/^\s*;/],
|
|
124
|
+
multiLineStart: [],
|
|
125
|
+
multiLineEnd: [],
|
|
126
|
+
},
|
|
127
|
+
'.clj': {
|
|
128
|
+
singleLine: [/^\s*;/],
|
|
129
|
+
multiLineStart: [],
|
|
130
|
+
multiLineEnd: [],
|
|
131
|
+
},
|
|
132
|
+
'.ex': {
|
|
133
|
+
singleLine: [/^\s*#/],
|
|
134
|
+
multiLineStart: [],
|
|
135
|
+
multiLineEnd: [],
|
|
136
|
+
},
|
|
137
|
+
'.exs': {
|
|
138
|
+
singleLine: [/^\s*#/],
|
|
139
|
+
multiLineStart: [],
|
|
140
|
+
multiLineEnd: [],
|
|
141
|
+
},
|
|
142
|
+
'.erl': {
|
|
143
|
+
singleLine: [/^\s*%/],
|
|
144
|
+
multiLineStart: [],
|
|
145
|
+
multiLineEnd: [],
|
|
146
|
+
},
|
|
147
|
+
'.hs': {
|
|
148
|
+
singleLine: [/^\s*--/],
|
|
149
|
+
multiLineStart: [/^\s*\{-/],
|
|
150
|
+
multiLineEnd: [/-\}\s*$/],
|
|
151
|
+
},
|
|
152
|
+
'.ml': {
|
|
153
|
+
singleLine: [],
|
|
154
|
+
multiLineStart: [/^\s*\(\*/],
|
|
155
|
+
multiLineEnd: [/\*\)\s*$/],
|
|
156
|
+
},
|
|
157
|
+
'.r': {
|
|
158
|
+
singleLine: [/^\s*#/],
|
|
159
|
+
multiLineStart: [],
|
|
160
|
+
multiLineEnd: [],
|
|
161
|
+
},
|
|
162
|
+
'.m': {
|
|
163
|
+
singleLine: [/^\s*%/],
|
|
164
|
+
multiLineStart: [/^\s*%\{/],
|
|
165
|
+
multiLineEnd: [/^\s*%\}/],
|
|
166
|
+
},
|
|
167
|
+
'.html': {
|
|
168
|
+
singleLine: [],
|
|
169
|
+
multiLineStart: [/^\s*<!--/],
|
|
170
|
+
multiLineEnd: [/-->\s*$/],
|
|
171
|
+
},
|
|
172
|
+
'.xml': {
|
|
173
|
+
singleLine: [],
|
|
174
|
+
multiLineStart: [/^\s*<!--/],
|
|
175
|
+
multiLineEnd: [/-->\s*$/],
|
|
176
|
+
},
|
|
177
|
+
'.css': {
|
|
178
|
+
singleLine: [],
|
|
179
|
+
multiLineStart: [/^\s*\/\*/],
|
|
180
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
181
|
+
},
|
|
182
|
+
'.scss': {
|
|
183
|
+
singleLine: [/^\s*\/\//],
|
|
184
|
+
multiLineStart: [/^\s*\/\*/],
|
|
185
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
186
|
+
},
|
|
187
|
+
'.sass': {
|
|
188
|
+
singleLine: [/^\s*\/\//],
|
|
189
|
+
multiLineStart: [],
|
|
190
|
+
multiLineEnd: [],
|
|
191
|
+
},
|
|
192
|
+
'.less': {
|
|
193
|
+
singleLine: [/^\s*\/\//],
|
|
194
|
+
multiLineStart: [/^\s*\/\*/],
|
|
195
|
+
multiLineEnd: [/\*\/\s*$/],
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
export function countComments(lines, ext) {
|
|
199
|
+
const patterns = COMMENT_PATTERNS[ext];
|
|
200
|
+
if (!patterns)
|
|
201
|
+
return 0;
|
|
202
|
+
let commentLines = 0;
|
|
203
|
+
let inMultiLineComment = false;
|
|
204
|
+
for (const line of lines) {
|
|
205
|
+
const trimmed = line.trim();
|
|
206
|
+
if (trimmed === '')
|
|
207
|
+
continue;
|
|
208
|
+
if (inMultiLineComment) {
|
|
209
|
+
commentLines++;
|
|
210
|
+
if (patterns.multiLineEnd.some((pattern) => pattern.test(line))) {
|
|
211
|
+
inMultiLineComment = false;
|
|
212
|
+
}
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (patterns.multiLineStart.some((pattern) => pattern.test(line))) {
|
|
216
|
+
commentLines++;
|
|
217
|
+
if (!patterns.multiLineEnd.some((pattern) => pattern.test(line))) {
|
|
218
|
+
inMultiLineComment = true;
|
|
219
|
+
}
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (patterns.singleLine.some((pattern) => pattern.test(line))) {
|
|
223
|
+
commentLines++;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return commentLines;
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=comments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments.js","sourceRoot":"","sources":["../src/comments.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,gBAAgB,GAAoC;IAC/D,KAAK,EAAE;QACL,UAAU,EAAE,CAAC,UAAU,CAAC;QACxB,cAAc,EAAE,CAAC,UAAU,CAAC;QAC5B,YAAY,EAAE,CAAC,UAAU,CAAC;KAC3B;IACD,MAAM,EAAE;QACN,UAAU,EAAE,CAAC,UAAU,CAAC;QACxB,cAAc,EAAE,CAAC,UAAU,CAAC;QAC5B,YAAY,EAAE,CAAC,UAAU,CAAC;KAC3B;IACD,KAAK,EAAE;QACL,UAAU,EAAE,CAAC,UAAU,CAAC;QACxB,cAAc,EAAE,CAAC,UAAU,CAAC;QAC5B,YAAY,EAAE,CAAC,UAAU,CAAC;KAC3B;IACD,MAAM,EAAE;QACN,UAAU,EAAE,CAAC,UAAU,CAAC;QACxB,cAAc,EAAE,CAAC,UAAU,CAAC;QAC5B,YAAY,EAAE,CAAC,UAAU,CAAC;KAC3B;IACD,OAAO,EAAE;QACP,UAAU,EAAE,CAAC,UAAU,CAAC;QACxB,cAAc,EAAE,CAAC,UAAU,CAAC;QAC5B,YAAY,EAAE,CAAC,UAAU,CAAC;KAC3B;IACD,IAAI,EAAE;QACJ,UAAU,EAAE,CAAC,UAAU,CAAC;QACxB,cAAc,EAAE,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CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;gBACjE,kBAAkB,GAAG,IAAI,CAAC;YAC5B,CAAC;YACD,SAAS;QACX,CAAC;QAED,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YAC9D,YAAY,EAAE,CAAC;YACf,SAAS;QACX,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface CountResult {
|
|
2
|
+
totalFiles: number;
|
|
3
|
+
totalLines: number;
|
|
4
|
+
totalBlank: number;
|
|
5
|
+
totalCode: number;
|
|
6
|
+
totalComments: number;
|
|
7
|
+
byExtension: Map<string, ExtensionStats>;
|
|
8
|
+
}
|
|
9
|
+
export interface ExtensionStats {
|
|
10
|
+
files: number;
|
|
11
|
+
lines: number;
|
|
12
|
+
blank: number;
|
|
13
|
+
code: number;
|
|
14
|
+
comments: number;
|
|
15
|
+
}
|
|
16
|
+
export interface CountOptions {
|
|
17
|
+
ignoreDirs?: Set<string>;
|
|
18
|
+
ignorePatterns?: RegExp[];
|
|
19
|
+
}
|
|
20
|
+
export declare class LineCounter {
|
|
21
|
+
private ignoreDirs;
|
|
22
|
+
private ignorePatterns;
|
|
23
|
+
constructor(options?: CountOptions);
|
|
24
|
+
count(rootPath: string): Promise<CountResult>;
|
|
25
|
+
private processDirectory;
|
|
26
|
+
private shouldCountFile;
|
|
27
|
+
private processFile;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=counter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,cAAc,CAAW;gBAErB,OAAO,GAAE,YAAiB;IAKhC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;YAcrC,gBAAgB;IAkB9B,OAAO,CAAC,eAAe;YAgBT,WAAW;CAqC1B"}
|
package/dist/counter.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { readdir, readFile } from 'fs/promises';
|
|
2
|
+
import { join, extname } from 'path';
|
|
3
|
+
import { DEFAULT_IGNORE_DIRS, DEFAULT_IGNORE_PATTERNS, BINARY_EXTENSIONS, } from './defaults.js';
|
|
4
|
+
import { countComments } from './comments.js';
|
|
5
|
+
export class LineCounter {
|
|
6
|
+
ignoreDirs;
|
|
7
|
+
ignorePatterns;
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.ignoreDirs = options.ignoreDirs || DEFAULT_IGNORE_DIRS;
|
|
10
|
+
this.ignorePatterns = options.ignorePatterns || DEFAULT_IGNORE_PATTERNS;
|
|
11
|
+
}
|
|
12
|
+
async count(rootPath) {
|
|
13
|
+
const result = {
|
|
14
|
+
totalFiles: 0,
|
|
15
|
+
totalLines: 0,
|
|
16
|
+
totalBlank: 0,
|
|
17
|
+
totalCode: 0,
|
|
18
|
+
totalComments: 0,
|
|
19
|
+
byExtension: new Map(),
|
|
20
|
+
};
|
|
21
|
+
await this.processDirectory(rootPath, result);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
async processDirectory(dirPath, result) {
|
|
25
|
+
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
const fullPath = join(dirPath, entry.name);
|
|
28
|
+
if (entry.isDirectory()) {
|
|
29
|
+
if (!this.ignoreDirs.has(entry.name)) {
|
|
30
|
+
await this.processDirectory(fullPath, result);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (entry.isFile()) {
|
|
34
|
+
if (this.shouldCountFile(entry.name)) {
|
|
35
|
+
await this.processFile(fullPath, result);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
shouldCountFile(filename) {
|
|
41
|
+
const ext = extname(filename).slice(1);
|
|
42
|
+
if (BINARY_EXTENSIONS.has(ext)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
for (const pattern of this.ignorePatterns) {
|
|
46
|
+
if (pattern.test(filename)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
async processFile(filePath, result) {
|
|
53
|
+
try {
|
|
54
|
+
const content = await readFile(filePath, 'utf-8');
|
|
55
|
+
const lines = content.split('\n');
|
|
56
|
+
const blankLines = lines.filter((line) => line.trim() === '').length;
|
|
57
|
+
const ext = extname(filePath) || 'no-extension';
|
|
58
|
+
const commentLines = countComments(lines, ext);
|
|
59
|
+
const codeLines = lines.length - blankLines - commentLines;
|
|
60
|
+
if (!result.byExtension.has(ext)) {
|
|
61
|
+
result.byExtension.set(ext, {
|
|
62
|
+
files: 0,
|
|
63
|
+
lines: 0,
|
|
64
|
+
blank: 0,
|
|
65
|
+
code: 0,
|
|
66
|
+
comments: 0,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const stats = result.byExtension.get(ext);
|
|
70
|
+
stats.files++;
|
|
71
|
+
stats.lines += lines.length;
|
|
72
|
+
stats.blank += blankLines;
|
|
73
|
+
stats.code += codeLines;
|
|
74
|
+
stats.comments += commentLines;
|
|
75
|
+
result.totalFiles++;
|
|
76
|
+
result.totalLines += lines.length;
|
|
77
|
+
result.totalBlank += blankLines;
|
|
78
|
+
result.totalCode += codeLines;
|
|
79
|
+
result.totalComments += commentLines;
|
|
80
|
+
}
|
|
81
|
+
catch (error) { }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=counter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAQ,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAwB9C,MAAM,OAAO,WAAW;IACd,UAAU,CAAc;IACxB,cAAc,CAAW;IAEjC,YAAY,UAAwB,EAAE;QACpC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mBAAmB,CAAC;QAC5D,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,uBAAuB,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,QAAgB;QAC1B,MAAM,MAAM,GAAgB;YAC1B,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,CAAC;YACb,SAAS,EAAE,CAAC;YAC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,IAAI,YAAY,CAAC;YAE/B,MAAM,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,UAAU,IAAI,KAAK,CAAC,MAAM,CAAC;YAClC,MAAM,CAAC,UAAU,IAAI,UAAU,CAAC;YAChC,MAAM,CAAC,SAAS,IAAI,SAAS,CAAC;YAC9B,MAAM,CAAC,aAAa,IAAI,YAAY,CAAC;QACvC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC,CAAA,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,aAuG9B,CAAC;AAEH,eAAO,MAAM,uBAAuB,UAuDnC,CAAC;AAEF,eAAO,MAAM,iBAAiB,aAsB5B,CAAC"}
|
package/dist/defaults.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
export const DEFAULT_IGNORE_DIRS = new Set([
|
|
2
|
+
'node_modules',
|
|
3
|
+
'bower_components',
|
|
4
|
+
'.git',
|
|
5
|
+
'.svn',
|
|
6
|
+
'.hg',
|
|
7
|
+
'.idea',
|
|
8
|
+
'.vscode',
|
|
9
|
+
'.vs',
|
|
10
|
+
'.cursor',
|
|
11
|
+
'.windsurf',
|
|
12
|
+
'dist',
|
|
13
|
+
'build',
|
|
14
|
+
'out',
|
|
15
|
+
'target',
|
|
16
|
+
'coverage',
|
|
17
|
+
'.nyc_output',
|
|
18
|
+
'__pycache__',
|
|
19
|
+
'.pytest_cache',
|
|
20
|
+
'.tox',
|
|
21
|
+
'venv',
|
|
22
|
+
'.venv',
|
|
23
|
+
'env',
|
|
24
|
+
'.env',
|
|
25
|
+
'vendor',
|
|
26
|
+
'tmp',
|
|
27
|
+
'temp',
|
|
28
|
+
'.cache',
|
|
29
|
+
'.parcel-cache',
|
|
30
|
+
'.next',
|
|
31
|
+
'.nuxt',
|
|
32
|
+
'.output',
|
|
33
|
+
'.vercel',
|
|
34
|
+
'.netlify',
|
|
35
|
+
'Pods',
|
|
36
|
+
'Carthage',
|
|
37
|
+
'.build',
|
|
38
|
+
'DerivedData',
|
|
39
|
+
'.swiftpm',
|
|
40
|
+
'xcuserdata',
|
|
41
|
+
'Packages',
|
|
42
|
+
'bin',
|
|
43
|
+
'obj',
|
|
44
|
+
'Debug',
|
|
45
|
+
'Release',
|
|
46
|
+
'x64',
|
|
47
|
+
'x86',
|
|
48
|
+
'.vs',
|
|
49
|
+
'TestResults',
|
|
50
|
+
'packages',
|
|
51
|
+
'.gradle',
|
|
52
|
+
'.m2',
|
|
53
|
+
'.mvn',
|
|
54
|
+
'gradle',
|
|
55
|
+
'cmake-build-debug',
|
|
56
|
+
'cmake-build-release',
|
|
57
|
+
'CMakeFiles',
|
|
58
|
+
'.dart_tool',
|
|
59
|
+
'.flutter-plugins',
|
|
60
|
+
'.flutter-plugins-dependencies',
|
|
61
|
+
'.pub-cache',
|
|
62
|
+
'.pub',
|
|
63
|
+
'android/.gradle',
|
|
64
|
+
'ios/Pods',
|
|
65
|
+
'Godeps',
|
|
66
|
+
'_obj',
|
|
67
|
+
'_test',
|
|
68
|
+
'pkg',
|
|
69
|
+
'deps',
|
|
70
|
+
'_build',
|
|
71
|
+
'ebin',
|
|
72
|
+
'priv/static',
|
|
73
|
+
'.elixir_ls',
|
|
74
|
+
'.mix',
|
|
75
|
+
'.hex',
|
|
76
|
+
'.rebar3',
|
|
77
|
+
'_opam',
|
|
78
|
+
'_esy',
|
|
79
|
+
'esy.lock',
|
|
80
|
+
'.stack-work',
|
|
81
|
+
'.cabal-sandbox',
|
|
82
|
+
'dist-newstyle',
|
|
83
|
+
'.terraform',
|
|
84
|
+
'.vagrant',
|
|
85
|
+
'venv',
|
|
86
|
+
'virtualenv',
|
|
87
|
+
'.pytest_cache',
|
|
88
|
+
'.mypy_cache',
|
|
89
|
+
'.ruff_cache',
|
|
90
|
+
'__pypackages__',
|
|
91
|
+
'site-packages',
|
|
92
|
+
'.bundle',
|
|
93
|
+
'log',
|
|
94
|
+
'logs',
|
|
95
|
+
'tmp',
|
|
96
|
+
'.sass-cache',
|
|
97
|
+
'.jekyll-cache',
|
|
98
|
+
'_site',
|
|
99
|
+
'.docusaurus',
|
|
100
|
+
'.astro',
|
|
101
|
+
'public',
|
|
102
|
+
'.turbo',
|
|
103
|
+
'.contentlayer',
|
|
104
|
+
]);
|
|
105
|
+
export const DEFAULT_IGNORE_PATTERNS = [
|
|
106
|
+
/\.min\.js$/,
|
|
107
|
+
/\.bundle\.js$/,
|
|
108
|
+
/\.map$/,
|
|
109
|
+
/\.lock$/,
|
|
110
|
+
/package-lock\.json$/,
|
|
111
|
+
/yarn\.lock$/,
|
|
112
|
+
/pnpm-lock\.yaml$/,
|
|
113
|
+
/Podfile\.lock$/,
|
|
114
|
+
/Gemfile\.lock$/,
|
|
115
|
+
/Cargo\.lock$/,
|
|
116
|
+
/composer\.lock$/,
|
|
117
|
+
/poetry\.lock$/,
|
|
118
|
+
/Pipfile\.lock$/,
|
|
119
|
+
/go\.sum$/,
|
|
120
|
+
/\.log$/,
|
|
121
|
+
/\.pid$/,
|
|
122
|
+
/\.seed$/,
|
|
123
|
+
/\.pid\.lock$/,
|
|
124
|
+
/\.gitignore$/,
|
|
125
|
+
/\.gitattributes$/,
|
|
126
|
+
/\.gitmodules$/,
|
|
127
|
+
/\.npmignore$/,
|
|
128
|
+
/\.dockerignore$/,
|
|
129
|
+
/\.eslintignore$/,
|
|
130
|
+
/\.prettierignore$/,
|
|
131
|
+
/\.cursorignore$/,
|
|
132
|
+
/\.cursorrules$/,
|
|
133
|
+
/\.editorconfig$/,
|
|
134
|
+
/\.xcworkspace$/,
|
|
135
|
+
/\.xcodeproj$/,
|
|
136
|
+
/\.pbxproj$/,
|
|
137
|
+
/\.storyboard$/,
|
|
138
|
+
/\.xib$/,
|
|
139
|
+
/\.nib$/,
|
|
140
|
+
/\.swiftmodule$/,
|
|
141
|
+
/\.swiftdoc$/,
|
|
142
|
+
/\.dSYM$/,
|
|
143
|
+
/\.generated\.swift$/,
|
|
144
|
+
/\.pb\.go$/,
|
|
145
|
+
/\.pb\.h$/,
|
|
146
|
+
/\.pb\.cc$/,
|
|
147
|
+
/_pb2\.py$/,
|
|
148
|
+
/\.g\.dart$/,
|
|
149
|
+
/\.freezed\.dart$/,
|
|
150
|
+
/\.gr\.dart$/,
|
|
151
|
+
/\.config\.dart$/,
|
|
152
|
+
/\.g\.cs$/,
|
|
153
|
+
/\.designer\.cs$/,
|
|
154
|
+
/AssemblyInfo\.cs$/,
|
|
155
|
+
/\.meta$/,
|
|
156
|
+
/\.prefab$/,
|
|
157
|
+
/\.asset$/,
|
|
158
|
+
/\.unity$/,
|
|
159
|
+
/\.unitypackage$/,
|
|
160
|
+
];
|
|
161
|
+
export const BINARY_EXTENSIONS = new Set([
|
|
162
|
+
'exe', 'dll', 'so', 'dylib', 'bin', 'app', 'dmg', 'pkg',
|
|
163
|
+
'jpg', 'jpeg', 'png', 'gif', 'bmp', 'ico', 'svg', 'webp', 'tiff', 'psd', 'ai',
|
|
164
|
+
'mp3', 'mp4', 'avi', 'mov', 'wmv', 'flv', 'wav', 'ogg', 'webm', 'm4a', 'aac',
|
|
165
|
+
'zip', 'tar', 'gz', 'rar', '7z', 'bz2', 'xz', 'tgz', 'tbz2',
|
|
166
|
+
'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp',
|
|
167
|
+
'ttf', 'otf', 'woff', 'woff2', 'eot',
|
|
168
|
+
'class', 'jar', 'war', 'ear', 'aar', 'apk', 'ipa',
|
|
169
|
+
'pyc', 'pyo', 'pyd', 'whl',
|
|
170
|
+
'o', 'a', 'lib', 'obj', 'pdb', 'ilk', 'exp', 'idb',
|
|
171
|
+
'dex', 'odex', 'vdex',
|
|
172
|
+
'beam', 'boot',
|
|
173
|
+
'rlib', 'rmeta',
|
|
174
|
+
'wasm',
|
|
175
|
+
'node',
|
|
176
|
+
'vsix',
|
|
177
|
+
'nupkg',
|
|
178
|
+
'gem',
|
|
179
|
+
'db', 'sqlite', 'sqlite3', 'mdb',
|
|
180
|
+
'dat', 'data', 'sav', 'bak',
|
|
181
|
+
'DS_Store',
|
|
182
|
+
'Thumbs.db',
|
|
183
|
+
]);
|
|
184
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IACzC,cAAc;IACd,kBAAkB;IAClB,MAAM;IACN,MAAM;IACN,KAAK;IACL,OAAO;IACP,SAAS;IACT,KAAK;IACL,SAAS;IACT,WAAW;IACX,MAAM;IACN,OAAO;IACP,KAAK;IACL,QAAQ;IACR,UAAU;IACV,aAAa;IACb,aAAa;IACb,eAAe;IACf,MAAM;IACN,MAAM;IACN,OAAO;IACP,KAAK;IACL,MAAM;IACN,QAAQ;IACR,KAAK;IACL,MAAM;IACN,QAAQ;IACR,eAAe;IACf,OAAO;IACP,OAAO;IACP,SAAS;IACT,SAAS;IACT,UAAU;IACV,MAAM;IACN,UAAU;IACV,QAAQ;IACR,aAAa;IACb,UAAU;IACV,YAAY;IACZ,UAAU;IACV,KAAK;IACL,KAAK;IACL,OAAO;IACP,SAAS;IACT,KAAK;IACL,KAAK;IACL,KAAK;IACL,aAAa;IACb,UAAU;IACV,SAAS;IACT,KAAK;IACL,MAAM;IACN,QAAQ;IACR,mBAAmB;IACnB,qBAAqB;IACrB,YAAY;IACZ,YAAY;IACZ,kBAAkB;IAClB,+BAA+B;IAC/B,YAAY;IACZ,MAAM;IACN,iBAAiB;IACjB,UAAU;IACV,QAAQ;IACR,MAAM;IACN,OAAO;IACP,KAAK;IACL,MAAM;IACN,QAAQ;IACR,MAAM;IACN,aAAa;IACb,YAAY;IACZ,MAAM;IACN,MAAM;IACN,SAA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,WAAW,GAAG,MAAM;IA6CnC,OAAO,CAAC,eAAe;CAIxB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import Table from 'cli-table3';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
export class ResultFormatter {
|
|
4
|
+
format(result) {
|
|
5
|
+
const table = new Table({
|
|
6
|
+
head: [
|
|
7
|
+
chalk.cyan.bold('Language'),
|
|
8
|
+
chalk.cyan.bold('Files'),
|
|
9
|
+
chalk.cyan.bold('Lines'),
|
|
10
|
+
chalk.cyan.bold('Blank'),
|
|
11
|
+
chalk.cyan.bold('Comment'),
|
|
12
|
+
chalk.cyan.bold('Code'),
|
|
13
|
+
],
|
|
14
|
+
style: {
|
|
15
|
+
head: [],
|
|
16
|
+
border: ['gray'],
|
|
17
|
+
},
|
|
18
|
+
colAligns: ['left', 'right', 'right', 'right', 'right', 'right'],
|
|
19
|
+
});
|
|
20
|
+
const sorted = Array.from(result.byExtension.entries()).sort((a, b) => b[1].code - a[1].code);
|
|
21
|
+
for (const [ext, stats] of sorted) {
|
|
22
|
+
const lang = this.formatExtension(ext);
|
|
23
|
+
table.push([
|
|
24
|
+
chalk.white(lang),
|
|
25
|
+
chalk.yellow(stats.files.toLocaleString()),
|
|
26
|
+
chalk.blue(stats.lines.toLocaleString()),
|
|
27
|
+
chalk.gray(stats.blank.toLocaleString()),
|
|
28
|
+
chalk.magenta(stats.comments.toLocaleString()),
|
|
29
|
+
chalk.green(stats.code.toLocaleString()),
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
table.push([
|
|
33
|
+
chalk.bold.white('Total'),
|
|
34
|
+
chalk.bold.yellow(result.totalFiles.toLocaleString()),
|
|
35
|
+
chalk.bold.blue(result.totalLines.toLocaleString()),
|
|
36
|
+
chalk.bold.gray(result.totalBlank.toLocaleString()),
|
|
37
|
+
chalk.bold.magenta(result.totalComments.toLocaleString()),
|
|
38
|
+
chalk.bold.green(result.totalCode.toLocaleString()),
|
|
39
|
+
]);
|
|
40
|
+
return '\n' + table.toString() + '\n';
|
|
41
|
+
}
|
|
42
|
+
formatExtension(ext) {
|
|
43
|
+
if (ext === 'no-extension')
|
|
44
|
+
return '(no extension)';
|
|
45
|
+
return ext.startsWith('.') ? ext : `.${ext}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,OAAO,eAAe;IAC1B,MAAM,CAAC,MAAmB;QACxB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC;YACtB,IAAI,EAAE;gBACJ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;gBAC3B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;gBACxB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;gBACxB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;gBACxB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;gBAC1B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;aACxB;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,EAAE;gBACR,MAAM,EAAE,CAAC,MAAM,CAAC;aACjB;YACD,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;SACjE,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAC1D,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IA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EAAE,GAAG,IAAI,CAAC;IACxC,CAAC;IAEO,eAAe,CAAC,GAAW;QACjC,IAAI,GAAG,KAAK,cAAc;YAAE,OAAO,gBAAgB,CAAC;QACpD,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;IAC/C,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { LineCounter } from './counter.js';
|
|
2
|
+
export { ResultFormatter } from './formatter.js';
|
|
3
|
+
export type { CountResult, ExtensionStats, CountOptions } from './counter.js';
|
|
4
|
+
export { DEFAULT_IGNORE_DIRS, DEFAULT_IGNORE_PATTERNS, BINARY_EXTENSIONS, } from './defaults.js';
|
|
5
|
+
export { countComments, COMMENT_PATTERNS } from './comments.js';
|
|
6
|
+
export type { CommentPatterns } from './comments.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { LineCounter } from './counter.js';
|
|
2
|
+
export { ResultFormatter } from './formatter.js';
|
|
3
|
+
export { DEFAULT_IGNORE_DIRS, DEFAULT_IGNORE_PATTERNS, BINARY_EXTENSIONS, } from './defaults.js';
|
|
4
|
+
export { countComments, COMMENT_PATTERNS } from './comments.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ivorisnoob/linecount",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A fast, smart line counter that automatically ignores common build artifacts and dependencies",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"linecount": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"dev": "tsc --watch",
|
|
25
|
+
"start": "node dist/cli.js",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"cloc",
|
|
30
|
+
"lines",
|
|
31
|
+
"code",
|
|
32
|
+
"counter",
|
|
33
|
+
"loc",
|
|
34
|
+
"sloc",
|
|
35
|
+
"line-counter",
|
|
36
|
+
"code-analysis",
|
|
37
|
+
"statistics"
|
|
38
|
+
],
|
|
39
|
+
"author": "",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/ivorisnoob/linecount.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/ivorisnoob/linecount/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/ivorisnoob/linecount#readme",
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=18.0.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"chalk": "^5.3.0",
|
|
54
|
+
"cli-table3": "^0.6.3"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^20.0.0",
|
|
58
|
+
"typescript": "^5.0.0"
|
|
59
|
+
}
|
|
60
|
+
}
|