SuperAPI AI Directory

component-analyzer

Coding & development

View repository

Updated 10-16 09:59

About this skill

Component Analyzer - Component Code Analyzer

Used to analyze React/Vue component code, automatically parse component structure, build dependency graphs, detect duplicate patterns, and generate intelligent splitting suggestions.

Quick Start

Basic Usage

# 分析 React 组件目录(JSON 格式输出)
py -3 .claude/skills/component-analyzer/scripts/analyze_components.py \
  --input ./react-components \
  --output ./analysis-report.json

# Markdown 格式报告
py -3 .claude/skills/component-analyzer/scripts/analyze_components.py \
  --input ./react-components \
  --format markdown

Use with psd-component-splitter

# 第一步:PSD 拆分为组件
py -3 .claude/skills/psd-component-splitter/scripts/split_components.py \
  --json layer-tree.json --images sliced-images/ \
  --out ./split-components/ --framework react

# 第二步:分析生成的组件
py -3 .claude/skills/component-analyzer/scripts/analyze_components.py \
  --input ./split-components/ --output ./component-analysis.json

Command-line Arguments

Argument Short Required Default Description
--input -i ✅ - Component directory path
--output -o ❌ stdout Output file path
--format -f ❌ json Output format:json or markdown
--framework - ❌ react Framework:react or vue
--threshold -t ❌ 0.7 Similarity threshold (0.0-1.0)
--verbose -v ❌ - Show detailed progress

Core Features

1. Component Structure Analysis

  • Parse Import/Export statements
  • Extract Props signatures
  • Analyze JSX element structure
  • Detect CSS Module usage

2. Dependency Graph Construction

  • Scan directories to collect components
  • Parse dependencies between components
  • Detect circular dependencies
  • Identify entry components

3. Duplicate Pattern Detection

  • Props signature similarity (40%)
  • JSX structure similarity (40%)
  • CSS Module usage (20%)
  • Hierarchical clustering algorithm grouping

4. Intelligent Splitting Suggestions

  • Extract subcomponents - Identify reusable duplicate JSX
  • Merge components - Discover similar components that can be merged
  • Props refactoring - Unify component interfaces
  • Style separation - Extract shared styles
  • Architecture optimization - Detect deep nesting

Output Examples

JSON Format

{
  "summary": {
    "total_components": 12,
    "patterns_detected": 4,
    "suggestions_count": 8
  },
  "dependency_graph": {
    "nodes": [...],
    "edges": [...]
  },
  "patterns": [...],
  "suggestions": [...]
}

Markdown Format

Includes overview statistics, detailed suggestion list, and dependency graph visualization.

Module Description

scripts/

  • analyze_components.py - CLI entry point, integrates all features
  • react_ast_parser.py - React component AST parsing (regex implementation)
  • dependency_graph.py - Dependency graph construction and circular dependency detection
  • pattern_detector.py - Similarity calculation and pattern detection
  • split_suggester.py - Splitting suggestion generation and formatted output

Implementation Details

See references/IMPLEMENTATION.md for:

  • Similarity calculation algorithm
  • Regex parsing patterns
  • Data structure definitions
  • Extension development guide

Limitations

  1. Parsing capability: Uses regular expressions, does not support full AST
  2. Framework support: Mainly supports React, limited Vue support
  3. Similarity calculation: Based on feature matching, limited semantic analysis capability
  4. Performance: Analysis of large projects (>100 components) may be slow

Prerequisites

  • Python 3.6+
  • Input: generated React/Vue component directory