UNPKG

codecanon

Version:

CLI tool that downloads documentation from 3rd party libraries, converts them to Markdown, and optimizes for LLMs

36 lines (35 loc) 1.73 kB
import { Command } from "commander"; import { addPackage } from "../lib/package.js"; export const addCommand = new Command("add") .description("Fetch, process, and index documentation for a specified package") .argument("<package>", "Package name (e.g., 'react', 'express', 'lodash')") .option("--version <version>", "Specific version to fetch (defaults to latest)") .option("--source <source>", "Documentation source", "npm") .option("--force", "Re-fetch even if package documentation already exists locally", false) .option("--no-chunk", "Skip semantic chunking and store as single document", false) .action(async (packageName, options) => { try { console.log(`📦 Adding documentation for package: ${packageName}`); if (options.version) { console.log(`📌 Version: ${options.version}`); } console.log(`🔍 Source: ${options.source}`); const result = await addPackage({ name: packageName, version: options.version, source: options.source, force: options.force, enableChunking: options.chunk, cwd: process.cwd(), }); console.log("✅ Package documentation added successfully!"); console.log(`📄 Documents processed: ${result.documentsCount}`); console.log(`🔍 Chunks created: ${result.chunksCount}`); console.log(`💾 Stored in: .canon/cache/${packageName}`); console.log("\nContext updated! Your AI assistant now has access to this documentation."); } catch (error) { console.error("❌ Failed to add package:", error instanceof Error ? error.message : error); process.exit(1); } });