From aab5f20876bb055cba3df42db19029224a5b4fee Mon Sep 17 00:00:00 2001 From: lonewolfyx Date: Wed, 19 Aug 2026 23:24:21 +0800 Subject: [PATCH] feat(doc): add doc command - Add component and default arguments support - Integrate config resolution and version handling - Implement component loading with metadata - Add error logging for missing components - Support multiple output formats (json, text, markdown) - Add proper exception handling for component resolution --- src/commands/doc.ts | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/commands/doc.ts b/src/commands/doc.ts index 56ad100..4a61d3f 100644 --- a/src/commands/doc.ts +++ b/src/commands/doc.ts @@ -1,13 +1,46 @@ import { defineCommand } from 'citty' +import { componentArgs } from '@/args/component.ts' +import { defaultArgs } from '@/args/default.ts' +import { resolveConfig } from '@/config.ts' +import capitalize from '@/utils/capitalize.ts' +import { logErrorComponent } from '@/utils/error.ts' +import { loadComponent, loadVersionMetaData } from '@/utils/loader.ts' +import { output } from '@/utils/output.ts' +import { resolveVersion } from '@/utils/version.ts' export default defineCommand({ meta: { name: 'doc', description: 'Output the full API documentation for a component in markdown', }, - run({ args }) { - // TODO antd doc - // 组件完整 Markdown 文档 - console.log('Parsed args:', args) + args: { + ...defaultArgs, + ...componentArgs, + }, + async run({ args }) { + const config = resolveConfig(args) + const component = capitalize(args.component) + try { + const version = await resolveVersion(config) + const metaData = await loadVersionMetaData(version) + const components = loadComponent(component, metaData) + + if (!components.doc) { + logErrorComponent(args) + return '' + } + + output({ + json: { + name: component, + doc: components.doc, + }, + text: components.doc, + markdown: components.doc, + }, args.format) + } + catch (error) { + logErrorComponent(args) + } }, })