Skip to content

Commit 232ed5c

Browse files
authored
feat(list): add JSON output formatting for component list (#43)
- Import ComponentDemoRecord type alongside ComponentRecord - Create outputJson function to transform component data for JSON format - Map components to exclude titleZh and code fields in JSON output - Update json property in output call to use transformed data
1 parent 984d996 commit 232ed5c

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/commands/list.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ComponentRecord } from '#/components.ts'
1+
import type { ComponentDemoRecord, ComponentRecord } from '#/components.ts'
22
import { defineCommand } from 'citty'
33
import { Table } from 'console-table-printer'
44
import { defaultArgs } from '@/args/default.ts'
@@ -40,6 +40,17 @@ function outputTable(components: ComponentRecord[]): string {
4040
return p.render()
4141
}
4242

43+
export function outputJson(components: ComponentRecord[]): Omit<ComponentDemoRecord, 'titleZh' | 'code'>[] {
44+
return components.map((component) => {
45+
return {
46+
name: component.name,
47+
title: component.nameZh,
48+
description: component.description,
49+
descriptionZh: component.descriptionZh,
50+
}
51+
})
52+
}
53+
4354
export default defineCommand({
4455
meta: {
4556
name: 'list',
@@ -55,7 +66,7 @@ export default defineCommand({
5566

5667
output({
5768
text: outputTable(components),
58-
json: components,
69+
json: outputJson(components),
5970
markdown: outputMarkdown(components),
6071
}, args.format)
6172
},

0 commit comments

Comments
 (0)