provisioning/tools/README-analyze-codebase.md

155 lines
6.2 KiB
Markdown
Raw Normal View History

2025-10-07 11:12:02 +01:00
# Codebase Analysis Script
Script to analyze the technology distribution in the provisioning codebase.
## Usage
### Basic Usage
```bash
# From provisioning directory (analyzes current directory)
cd provisioning
nu tools/analyze-codebase.nu
# From project root, analyze provisioning
nu provisioning/tools/analyze-codebase.nu --path provisioning
# Analyze any path
nu provisioning/tools/analyze-codebase.nu --path /absolute/path/to/directory
```
### Output Formats
```bash
# Table format (default) - colored, visual bars
nu provisioning/tools/analyze-codebase.nu --format table
# JSON format - for programmatic use
nu provisioning/tools/analyze-codebase.nu --format json
# Markdown format - for documentation
nu provisioning/tools/analyze-codebase.nu --format markdown
```
### From provisioning directory
```bash
cd provisioning
nu tools/analyze-codebase.nu
```
### Direct execution (if in PATH)
```bash
# Make it globally available (one time)
ln -sf "$(pwd)/provisioning/tools/analyze-codebase.nu" /usr/local/bin/analyze-codebase
# Then run from anywhere
analyze-codebase
analyze-codebase --format json
analyze-codebase --format markdown > CODEBASE_STATS.md
```
## Output
The script analyzes:
- **Nushell** (.nu files)
- **KCL** (.k files)
- **Rust** (.rs files)
- **Templates** (.j2, .tera files)
Across these sections:
- `core/` - CLI interface, core libraries
- `extensions/` - Providers, taskservs, clusters
- `platform/` - Rust services (orchestrator, control-center, etc.)
- `templates/` - Template files
- `kcl/` - KCL configuration schemas
## Example Output
### Table Format
```
📊 Analyzing Codebase: provisioning
📋 Lines of Code by Section
╭─────────────┬─────────┬────────────┬─────┬─────────┬─────┬──────────┬───────────┬───────────────┬───────────┬───────╮
│ section │ nushell │ nushell_pct│ kcl │ kcl_pct │ rust│ rust_pct │ templates │ templates_pct │ total │ │
├─────────────┼─────────┼────────────┼─────┼─────────┼─────┼──────────┼───────────┼───────────────┼───────────┼───────┤
│ core │ 53843 │ 99.87 │ 71 │ 0.13 │ 0 │ 0.00 │ 0 │ 0.00 │ 53914 │ │
│ extensions │ 10202 │ 43.21 │3946 │ 16.72 │ 0 │ 0.00 │ 9456 │ 40.05 │ 23604 │ │
│ platform │ 5759 │ 0.19 │ 0 │ 0.00 │2992107│ 99.81 │ 0 │ 0.00 │ 2997866 │ │
│ templates │ 4197 │ 72.11 │ 834 │ 14.33 │ 0 │ 0.00 │ 789 │ 13.56 │ 5820 │ │
│ kcl │ 0 │ 0.00 │5594 │ 100.00 │ 0 │ 0.00 │ 0 │ 0.00 │ 5594 │ │
╰─────────────┴─────────┴────────────┴─────┴─────────┴─────┴──────────┴───────────┴───────────────┴───────────┴───────╯
📊 Overall Technology Distribution
╭──────────────────────┬──────────┬────────────┬────────────────────────────────────────────────────╮
│ technology │ lines │ percentage │ visual │
├──────────────────────┼──────────┼────────────┼────────────────────────────────────────────────────┤
│ Nushell │ 74001 │ 2.40 │ █ │
│ KCL │ 10445 │ 0.34 │ │
│ Rust │ 2992107 │ 96.93 │ ████████████████████████████████████████████████ │
│ Templates (Tera) │ 10245 │ 0.33 │ │
╰──────────────────────┴──────────┴────────────┴────────────────────────────────────────────────────╯
📈 Total Lines of Code: 3086798
```
### JSON Format
```json
{
"sections": [...],
"totals": {
"nushell": 74001,
"kcl": 10445,
"rust": 2992107,
"templates": 10245,
"grand_total": 3086798
},
"percentages": {
"nushell": 2.40,
"kcl": 0.34,
"rust": 96.93,
"templates": 0.33
}
}
```
### Markdown Format
```markdown
# Codebase Analysis
## Technology Distribution
| Technology | Lines | Percentage |
|------------|-------|------------|
| Nushell | 74001 | 2.40% |
| KCL | 10445 | 0.34% |
| Rust | 2992107 | 96.93% |
| Templates | 10245 | 0.33% |
| **TOTAL** | **3086798** | **100%** |
```
## Requirements
- Nushell 0.107.1+
- Access to the provisioning directory
## What It Analyzes
- ✅ All `.nu` files (Nushell scripts)
- ✅ All `.k` files (KCL configuration)
- ✅ All `.rs` files (Rust source)
- ✅ All `.j2` and `.tera` files (Templates)
## Notes
- The script recursively searches all subdirectories
- Empty sections show 0 for all technologies
- Percentages are calculated per section and overall
- Visual bars are proportional to percentage (max 50 chars = 100%)