ct-lines
v1.0.0
Published
A command-line tool for counting lines of code, comments, and blank lines in files within a directory.
Downloads
6
Readme
ct-lines
A command-line tool for counting lines of code, comments, and blank lines in files within a directory. This tool is based on the vscode-counter VS Code extension and provides similar functionality in a CLI environment.
Features
- Counts lines of code, comments, and blank lines in files
- Supports multiple programming languages out of the box
- Customizable language definitions
- Respects
.gitignorefiles - Multiple output formats (text, JSON, CSV)
- Progress bar for long-running operations
- Configurable file inclusion/exclusion patterns
- Detailed statistics by language and directory
Installation
npm install -g ct-linesUsage
ct-lines <directory> [options]Options
-i, --include <pattern>: Glob patterns for files to include (can be specified multiple times). Default:['**/*']-e, --exclude <pattern>: Glob patterns for files/directories to exclude (can be specified multiple times)--use-gitignore: Use.gitignorefiles found in the target directory to exclude files. Default:true--language-conf <path>: Path to a custom JSON file defining or overriding language configurations-f, --output-format <format>: Format for the summary output. Options:text,json,csv. Default:text-o, --output-dir <path>: Directory to save detailed results files (results.json, results.txt, etc.)--encoding <encoding>: File encoding to use when reading files. Default:utf8--ignore-unsupported: Ignore files for which no language definition is found. Default:true--include-incomplete-line: Count the last line even if it doesn't end with a newline. Default:false--print-commas: Print numbers with commas. Default:true
Examples
Count lines in the current directory:
ct-lines .Count lines in a specific directory, excluding test files:
ct-lines src --exclude "**/*.test.*" --exclude "**/__tests__/**"Count lines and save results in multiple formats:
ct-lines . --output-dir resultsUse a custom language configuration:
ct-lines . --language-conf custom-languages.jsonLanguage Configuration
The tool comes with built-in language definitions for common programming languages. You can override or extend these definitions by providing a custom JSON file with the --language-conf option.
Example language configuration:
{
"typescript": {
"aliases": ["ts"],
"extensions": [".ts", ".tsx"],
"lineComments": ["//"],
"blockComments": [["/*", "*/"]],
"blockStrings": [["`", "`"]],
"lineStrings": ["'", "\""]
}
}Output Formats
Text Format
The default text format provides a human-readable table with statistics organized by language, directory, and individual files.
JSON Format
The JSON format provides a structured representation of the results, including:
- Total statistics
- Statistics by language
- Statistics by directory
- Individual file statistics
CSV Format
The CSV format provides a tabular representation of the results, with one row per file and columns for:
- Filename
- Language
- Code lines per language
- Comment lines
- Blank lines
- Total lines
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache License, Version 2.0.
See the LICENSE file for the full license text.
Versioning and Release Process
This project uses semantic-release to automate version management and package publishing. The release process is triggered on every push to the main branch and follows the Angular Commit Message Convention.
How It Works
- Analyzes commit messages since the last release
- Determines the next version number based on the types of changes
- Generates/updates the CHANGELOG.md
- Creates a new GitHub release with release notes
- Updates package.json with the new version
- Publishes to npm (if configured)
Commit Message Convention
We follow the Angular Commit Message Convention. Example:
feat(cli): add new option for output format
fix(core): handle empty files gracefullyBreaking changes should include BREAKING CHANGE: in the commit body or a ! after the type/scope.
Manual Release
To trigger a release manually:
- Ensure you're on the main branch
- Run:
npx semantic-releaseSee .releaserc.json for configuration details.
