SuperAPI AI Directory

code-splitter

Coding & development

View repository

Updated 10-16 09:27

About this skill

Code Splitter - Component Code Splitter

Quick Start

# 1. 分析组件(建议模式 - 只生成报告)
py -3 .claude/skills/code-splitter/scripts/split_component.py \
  --input ./my-component/ \
  --dry-run

# 2. 查看报告后,生成实际组件
py -3 .claude/skills/code-splitter/scripts/component_generator.py \
  --input ./my-component/ \
  --output ./split/

System Requirements

  • Python 3.6+
  • The component directory contains index.jsx and index.module.css

two working modes

Mode 1: Suggestion Mode

Use split_component.py to analyze and generate a report without creating files:

py -3 scripts/split_component.py --input ./my-component/ --dry-run
py -3 scripts/split_component.py --input ./my-component/ --dry-run --output report.md
py -3 scripts/split_component.py --input ./my-component/ --dry-run --min-score 0.5

Mode 2: Generate Mode

Use component_generator.py to generate actual components:

py -3 scripts/component_generator.py --input ./my-component/ --output ./split/
py -3 scripts/component_generator.py --input ./my-component/ --output ./split/ --min-score 0.5
py -3 scripts/component_generator.py --input ./my-component/ --output ./split/ --dry-run

Analysis Dimensions

Identify splittable components based on four dimensions:

  1. Semantic class names: identify btn-*、card-*、header-* and other patterns
  2. DOM structure: detect containers wrapping multiple child elements
  3. Repetition patterns: find similar structures (such as multiple buttons)
  4. Position analysis: infer Header/Footer regions from CSS

Confidence interpretation

  • HIGH (≥0.8): strong recommendation to split, low risk
  • MEDIUM (0.5-0.8): can be split, may need minor adjustments
  • LOW (<0.5): consider carefully, it may be better to keep the current state

Output Structure

split-output/
├── app/
│   ├── index.jsx          # 主入口组件
│   └── index.module.css   # 主样式
├── card/                  # 拆分出的子组件
│   ├── index.jsx
│   └── index.module.css
└── generation-report.json # 生成报告

Working with Other Skills

  • psd-json-preview: handle generated large components
  • psd-component-splitter: further optimize the split results
  • frontend-code-review: review the generated component code

Reference Documentation

Known Limitations

  1. Only supports React function components (v2 supports Vue)
  2. Uses regex to parse JSX (covers 80% of common scenarios)
  3. Does not handle CSS-in-JS (only supports CSS Modules)
  4. v1 does not perform CSS coordinate conversion (copies style values as-is)
  5. Does not handle hooks dependencies (state remains in the original component)