@chakra-ui/cli
Version:
Generate theme typings for autocomplete
40 lines (37 loc) • 1.39 kB
JavaScript
;
import * as p from '@clack/prompts';
import { Command } from 'commander';
import createDebug from 'debug';
import { searchDocs } from '../utils/fetch.js';
import { formatCliError } from '../utils/format-error.js';
const debug = createDebug("chakra:docs");
const DocsCommand = new Command("docs").description("Search the Chakra UI documentation").argument("<query>", "Search query").action(async (query) => {
debug("searching docs for", query);
try {
const results = await searchDocs(query);
if (results.length === 0) {
p.log.warn(
`No results found for "${query}". Try component names like "button", "modal", or topics like "styling", "theming".`
);
p.outro("Done!");
return;
}
const { default: Table } = await import('cli-table');
const table = new Table({
head: ["name", "category", "url"],
colWidths: [25, 15, 50],
style: { compact: true }
});
const truncate = (s, max) => s.length <= max ? s : `${s.slice(0, max - 1)}\u2026`;
for (const item of results) {
table.push([item.label, item.category, truncate(item.url, 52)]);
}
p.log.info(`Found ${results.length} result(s) for "${query}"`);
p.log.info(table.toString());
p.outro("\u{1F389} Done!");
} catch (error) {
p.log.error(formatCliError(error));
process.exit(1);
}
});
export { DocsCommand };