npm package: @sumit-wayne/code-score-cli
Description: Analyze JavaScript, TypeScript, and React code complexity and maintainability
Author: Sumit
Latest version: 1.0.0

# 🎯 code-score

> Analyze JavaScript, TypeScript, and React code complexity and maintainability

[![npm version](https://img.shields.io/npm/v/@sumit-wayne/code-score.svg)](https://www.npmjs.com/package/@sumit-wayne/code-score)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Node.js](https://img.shields.io/badge/node-%3E%3D14.0.0-brightgreen.svg)](https://nodejs.org/)

A powerful CLI tool that analyzes your codebase and provides actionable insights on code quality, complexity, and maintainability.

## ✨ Features

- 📊 **Cyclomatic Complexity** - Measure code complexity with industry-standard metrics
- 🔍 **Maintainability Index** - Microsoft's formula for code maintainability
- 📏 **Function Length Analysis** - Identify overly long functions
- 🪆 **Nesting Depth Detection** - Find deeply nested code blocks
- 💡 **Actionable Suggestions** - Get specific improvement recommendations
- 🎨 **Beautiful CLI Output** - Color-coded, table-based reports
- 📄 **JSON Export** - Machine-readable output for CI/CD integration
- ⚡ **Fast Analysis** - Built with performance in mind

## 🚀 Installation

### Global Installation (Recommended)
```bash
npm install -g @sumit-wayne/code-score
```

### Local Installation
```bash
npm install --save-dev @sumit-wayne/code-score
```

## 📖 Usage

### Basic Analysis
```bash
code-score analyze ./src
```

### Export to JSON
```bash
code-score analyze ./src -f json -o report.json
```

### Exclude Patterns
```bash
code-score analyze ./src -e "**/test/**" "**/dist/**" "**/*.spec.ts"
```

### Include Only Specific Files
```bash
code-score analyze ./src -i "**/*.ts" "**/*.tsx"
```

## 📊 Example Output
```
╔════════════════════════════════════════════════╗
║         CODE SCORE ANALYSIS REPORT            ║
╚════════════════════════════════════════════════╝

📊 PROJECT SUMMARY
──────────────────
Files Analyzed          │ 36
Lines of Code           │ 1,628
Average Complexity      │ 1.2
Average Maintainability │ 54.2
Risky Files             │ 2

🎯 OVERALL SCORE
────────────────
  ✅  Good: 7.8/10

Complexity      │ 9.4/10 │ Excellent
Maintainability │ 5.4/10 │ Fair
Code Quality    │ 8.1/10 │ Good
```

## 🎨 Metrics Explained

### Cyclomatic Complexity

Measures the number of independent paths through your code. Higher values indicate more complex, harder-to-test code.

- **1-5**: ✅ Simple, easy to test and maintain
- **6-10**: ⚠️ Moderate complexity
- **11-20**: ❌ High complexity, consider refactoring
- **21+**: 🔥 Very high, difficult to maintain

### Maintainability Index

Microsoft's formula combining complexity, code volume, and lines of code. Ranges from 0-100.

- **70-100**: ✅ Good maintainability
- **50-69**: ⚠️ Moderate maintainability  
- **0-49**: ❌ Difficult to maintain

### Code Quality Score

Combines nesting depth and function length metrics to evaluate overall code structure.

## 🔧 Programmatic API

You can also use code-score programmatically in your Node.js projects:
```typescript
import { ProjectAnalyzer } from '@sumit-wayne/code-score';

const analyzer = new ProjectAnalyzer({
  path: './src',
  exclude: ['**/node_modules/**', '**/dist/**'],
});

const result = await analyzer.analyze();

console.log(`Overall Score: ${result.score.overall}/10`);
console.log(`Files Analyzed: ${result.summary.totalFiles}`);
console.log(`Critical Issues: ${result.summary.issueCount.critical}`);
```

## 🛠️ Configuration

You can customize thresholds for different metrics:
```typescript
const analyzer = new ProjectAnalyzer({
  path: './src',
  thresholds: {
    complexity: {
      low: 5,
      medium: 10,
      high: 20,
      critical: 30,
    },
    nesting: {
      max: 4,
    },
    functionLength: {
      max: 50,
    },
    maintainability: {
      good: 70,
      moderate: 50,
      poor: 0,
    },
  },
});
```

## 📝 CI/CD Integration

### GitHub Actions
```yaml
name: Code Quality

on: [push, pull_request]

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '18'
      - run: npm install -g @sumit-wayne/code-score
      - run: code-score analyze ./src -f json -o report.json
      - uses: actions/upload-artifact@v2
        with:
          name: code-quality-report
          path: report.json
```

## 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## 📄 License

MIT © [Sumit](https://github.com/sumitt-wayne)

## 🔗 Links

- [NPM Package](https://www.npmjs.com/package/@sumit-wayne/code-score)
- [GitHub Repository](https://github.com/sumitt-wayne/code-score)
- [Report Issues](https://github.com/sumitt-wayne/code-score/issues)

## 🙏 Acknowledgments

Built with:
- [Babel](https://babeljs.io/) for AST parsing
- [Commander.js](https://github.com/tj/commander.js) for CLI
- [Chalk](https://github.com/chalk/chalk) for terminal styling
- [Ora](https://github.com/sindresorhus/ora) for loading spinners

---

**Made with ❤️ by Sumit for better code quality**