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 featuresreact_ast_parser.py- React component AST parsing (regex implementation)dependency_graph.py- Dependency graph construction and circular dependency detectionpattern_detector.py- Similarity calculation and pattern detectionsplit_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
- Parsing capability: Uses regular expressions, does not support full AST
- Framework support: Mainly supports React, limited Vue support
- Similarity calculation: Based on feature matching, limited semantic analysis capability
- Performance: Analysis of large projects (>100 components) may be slow
Prerequisites
- Python 3.6+
- Input: generated React/Vue component directory