This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
See spec.md for the full design specification.
Always update spec.md after modifying any functionality, commands, flags, or output formats.
npm run build # Build with tsup (required before running e2e tests)
npm run dev # Watch mode
npm run test # Run all tests with vitest
npm run typecheck # TypeScript type check
node dist/index.js # Run built CLITo run a single test file:
npx vitest run src/__tests__/cli.test.tsNote: The e2e tests in src/__tests__/cli.test.ts run against the built dist/index.js — always npm run build first.
CLI invocation
→ src/index.ts (parses global flags, dispatches to command)
→ src/commands/*.ts (command logic)
→ src/data/version.ts (resolves antd version: --flag > node_modules > package.json > fallback)
→ src/data/loader.ts (loads data/v4.json | v5.json | v6.json)
→ src/output/ (formats output as text/json/markdown)
- Create
src/commands/<name>.tsexportingregisterXxxCommand(program: Command): void - Import and call it in
src/index.tsunder the appropriate comment block - Follow the pattern: read global opts via
program.opts<GlobalOptions>(), calldetectVersion(), load metadata, thenoutput()orprintError()
src/types.ts— All shared types (ComponentData,MetadataStore,GlobalOptions,CLIError) and thelocalize()helper for en/zh switchingsrc/data/loader.ts—loadMetadata(majorVersion)loads bundled JSON;findComponent()does case-insensitive lookupsrc/data/version.ts—detectVersion(flagVersion?)returns{ version, majorVersion, source }; also exportscompare()andvalid()semver helperssrc/output/error.ts—createError(),printError(),fuzzyMatch()(Levenshtein-based typo suggestions), andErrorCodesconstantssrc/output/formatter.ts—output(data, format)andformatTable(headers, rows, format)for aligned text/markdown/json tablessrc/utils/scan.ts—collectFiles(dir)andgetJSXElementName(node)used bylintandusagecommands
src/
index.ts # CLI entry point, registers all commands
types.ts # Shared TypeScript types + localize() helper
commands/ # One file per command (list, info, demo, token, semantic, changelog/diff, doctor, usage, lint, migrate, mcp)
mcp/ # MCP server: tools.ts (7 tool definitions + handlers), prompts.ts (prompt constants)
data/ # loader.ts, version.ts, cache.ts
output/ # formatter.ts, error.ts
utils/ # scan.ts (file collection + antd import parsing)
__tests__/ # e2e CLI tests (require built dist/), unit tests in commands/ subdir
data/
v4.json # Bundled antd v4 metadata
v5.json # Bundled antd v5 metadata
v6.json # Bundled antd v6 metadata
scripts/
extract.ts # Data extraction from antd source checkout
extractors/ # Per-data-type extractor modules
- TypeScript + Node.js (ESM,
"type": "module") - CLI framework:
commander - Build:
tsup - Tests:
vitest - Node minimum: 20+
- Never commit directly to main. Always create a feature branch and submit a PR.
Every publish (including beta/pre-release) must follow this checklist:
- Update
CHANGELOG.mdwith a version section describing all changes - Run tests (
npm run test) npm publish --otp=<code>(add--tag betafor pre-releases)git tag v{version} && git push origin v{version}- Create GitHub Release:
gh release create v{version} --title "v{version}" --notes "<changelog content>"(add--prereleasefor beta)
CHANGELOG.md and GitHub Release notes must have identical content. Never use auto-generated release notes — always write them manually to match the CHANGELOG.
Tests must NEVER cause real-world side effects. Any function that interacts with external services (GitHub API, npm registry, network requests, file system outside temp dirs, etc.) must be fully mocked in tests. Specifically:
submitViaGh,checkGhAvailableand any function that callsghCLI or creates GitHub issues must usevi.fn()with a safe default implementation (e.g.vi.fn(() => false)), nevervi.fn(actualFunction)which would use the real function as fallbackvi.restoreAllMocks()resets mocks to their default implementation — if the default is the real function, it will execute after restore. Always use safe no-op defaults invi.mock()factories- Network-calling functions (
node:https,fetch, etc.) must be mocked to prevent real HTTP requests - Tests that create temp files/directories must clean up in
finallyblocks orafterEach
- All commands support
--format json|text|markdownand--lang en|zh - JSON output must be machine-parseable with no decoration
- Error output follows the standard shape:
{ error, code, message, suggestion }; errors go to stderr, normal output to stdout - Exit codes:
0success,1user error,2system error - Data is fully bundled — no remote fetch at runtime
- CLI version flag is
-V/--cli-version(not--version, which targets antd version) - Bilingual data stored as paired fields:
description/descriptionZh, uselocalize(en, zh, lang)to pick