{"version":3,"file":"generate-documentation.cjs","names":["cli","generateDocumentation","InternalCLI"],"sources":["../../../src/bin/commands/generate-documentation.ts"],"sourcesContent":["import type { ParsedArgs } from '@cli-forge/parser';\n\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, isAbsolute, join, relative } from 'node:path';\nimport { join as joinPathFragments, normalize } from 'node:path/posix';\nimport { pathToFileURL } from 'node:url';\n\nimport cli, { ArgumentsOf, CLI } from '../..';\nimport { Documentation, generateDocumentation } from '../../lib/documentation';\nimport { InternalCLI } from '../../lib/internal-cli';\nimport { ensureDirSync } from '../utils/fs';\n\ntype mdfactory = typeof import('markdown-factory');\n\ntype GenerateDocsArgs = ArgumentsOf<typeof withGenerateDocumentationArgs>;\n\nexport function withGenerateDocumentationArgs<T extends ParsedArgs>(\n  cmd: CLI<T>\n) {\n  return cmd\n    .positional('cli', {\n      type: 'string',\n      description: 'Path to the cli that docs should be generated for.',\n      required: true,\n    })\n    .option('output', {\n      alias: ['o'],\n      type: 'string',\n      description: 'Where should the documentation be output?',\n      default: 'docs',\n    })\n    .option('format', {\n      type: 'string',\n      description: 'What format should the documentation be output in?',\n      default: 'md',\n      choices: ['json', 'md'],\n    })\n    .option('export', {\n      type: 'string',\n      description:\n        'The name of the export that contains the CLI instance. By default, docs will be generated for the default export.',\n    })\n    .option('tsconfig', {\n      type: 'string',\n      description:\n        'Specifies the `tsconfig` used when loading typescript based CLIs.',\n    })\n    .option('llms', {\n      type: 'boolean',\n      description:\n        'Generate an llms.txt file describing the CLI for AI agents.',\n      default: true,\n    });\n}\n\nexport const generateDocumentationCommand = cli('generate-documentation', {\n  description: 'Generate documentation for the given CLI',\n  examples: [\n    'cli-forge generate-documentation ./bin/my-cli',\n    'cli-forge generate-documentation ./bin/my-cli --format json',\n    'cli-forge generate-documentation ./bin/my-cli --export mycli',\n  ],\n  builder: (b) => withGenerateDocumentationArgs(b),\n  handler: async (args) => {\n    const cliModule = await loadCLIModule(args);\n    const cli = readCLIFromModule(cliModule, args);\n\n    const documentation = generateDocumentation(cli);\n    if (args.format === 'md') {\n      await generateMarkdownDocumentation(documentation, args);\n\n      if (args.llms) {\n        generateLlmsTxt(documentation, args);\n      }\n    } else if (args.format === 'json') {\n      const outfile = args.output.endsWith('json')\n        ? args.output\n        : join(args.output, cli.name + '.json');\n      const outdir = dirname(outfile);\n      ensureDirSync(outdir);\n      writeFileSync(outfile, JSON.stringify(documentation, null, 2));\n    }\n  },\n});\n\nasync function generateMarkdownDocumentation(\n  docs: Documentation,\n  args: GenerateDocsArgs\n) {\n  const md = await importMarkdownFactory();\n  await generateMarkdownForSingleCommand(docs, args.output, args.output, md);\n}\n\nfunction generateLlmsTxt(docs: Documentation, args: GenerateDocsArgs) {\n  const content = generateLlmsTxtContent(docs);\n  const outfile = join(args.output, 'llms.txt');\n  ensureDirSync(args.output);\n  writeFileSync(outfile, content);\n}\n\nfunction generateLlmsTxtContent(\n  docs: Documentation,\n  depth = 0,\n  commandPath: string[] = []\n): string {\n  const lines: string[] = [];\n  const indent = '  '.repeat(depth);\n  const currentPath = [...commandPath, docs.name];\n  const fullCommand = currentPath.join(' ');\n\n  // Command header\n  if (depth === 0) {\n    lines.push(`# ${docs.name}`);\n    lines.push('');\n    if (docs.description) {\n      lines.push(docs.description);\n      lines.push('');\n    }\n    lines.push(\n      'This document describes the CLI commands and options for AI agent consumption.'\n    );\n    lines.push('');\n  } else {\n    lines.push(`${indent}## ${fullCommand}`);\n    if (docs.description) {\n      lines.push(`${indent}${docs.description}`);\n    }\n    lines.push('');\n  }\n\n  // Usage\n  lines.push(`${indent}Usage: ${docs.usage}`);\n  lines.push('');\n\n  // Positional arguments\n  if (docs.positionals.length > 0) {\n    lines.push(`${indent}Positional Arguments:`);\n    for (const pos of docs.positionals) {\n      const typeStr = formatOptionType(pos);\n      const reqStr = pos.required ? ' (required)' : ' (optional)';\n      lines.push(`${indent}  <${pos.key}> - ${typeStr}${reqStr}`);\n      if (pos.description) {\n        lines.push(`${indent}    ${pos.description}`);\n      }\n      if (pos.default !== undefined) {\n        lines.push(`${indent}    Default: ${JSON.stringify(pos.default)}`);\n      }\n    }\n    lines.push('');\n  }\n\n  // Options\n  const optionEntries = Object.entries(docs.options);\n  if (optionEntries.length > 0) {\n    lines.push(`${indent}Options:`);\n    for (const [, opt] of optionEntries) {\n      const typeStr = formatOptionType(opt);\n      const aliasStr = opt.alias?.length\n        ? ` (aliases: ${opt.alias\n            .map((a) => (a.length === 1 ? `-${a}` : `--${a}`))\n            .join(', ')})`\n        : '';\n      const reqStr =\n        opt.required && opt.default === undefined ? ' [required]' : '';\n      const deprecatedStr = opt.deprecated ? ' [deprecated]' : '';\n      lines.push(\n        `${indent}  --${opt.key}${aliasStr} <${typeStr}>${reqStr}${deprecatedStr}`\n      );\n      if (opt.description) {\n        lines.push(`${indent}    ${opt.description}`);\n      }\n      if (opt.default !== undefined) {\n        lines.push(`${indent}    Default: ${JSON.stringify(opt.default)}`);\n      }\n      if ('choices' in opt && opt.choices) {\n        const choicesList =\n          typeof opt.choices === 'function' ? opt.choices() : opt.choices;\n        lines.push(`${indent}    Valid values: ${choicesList.join(', ')}`);\n      }\n      if ('resolvedEnvKey' in opt && opt.resolvedEnvKey) {\n        lines.push(`${indent}    Env var: ${opt.resolvedEnvKey}`);\n      }\n    }\n    lines.push('');\n  }\n\n  // Grouped options\n  for (const group of docs.groupedOptions) {\n    if (group.keys.length > 0) {\n      lines.push(`${indent}${group.label}:`);\n      for (const opt of group.keys) {\n        const typeStr = formatOptionType(opt);\n        const aliasStr = opt.alias?.length\n          ? ` (aliases: ${opt.alias\n              .map((a) => (a.length === 1 ? `-${a}` : `--${a}`))\n              .join(', ')})`\n          : '';\n        const reqStr =\n          opt.required && opt.default === undefined ? ' [required]' : '';\n        lines.push(`${indent}  --${opt.key}${aliasStr} <${typeStr}>${reqStr}`);\n        if (opt.description) {\n          lines.push(`${indent}    ${opt.description}`);\n        }\n        if (opt.default !== undefined) {\n          lines.push(`${indent}    Default: ${JSON.stringify(opt.default)}`);\n        }\n        if ('resolvedEnvKey' in opt && opt.resolvedEnvKey) {\n          lines.push(`${indent}    Env var: ${opt.resolvedEnvKey}`);\n        }\n      }\n      lines.push('');\n    }\n  }\n\n  // Configuration sources\n  if (docs.configurationSources && docs.configurationSources.length > 0) {\n    lines.push(`${indent}Configuration:`);\n    for (const section of docs.configurationSources) {\n      lines.push(`${indent}  ${section.heading}`);\n      lines.push(`${indent}    ${section.body}`);\n    }\n    lines.push('');\n  }\n\n  // Examples\n  if (docs.examples.length > 0) {\n    lines.push(`${indent}Examples:`);\n    for (const example of docs.examples) {\n      lines.push(`${indent}  $ ${example}`);\n    }\n    lines.push('');\n  }\n\n  // Subcommands\n  if (docs.subcommands.length > 0) {\n    lines.push(`${indent}Subcommands:`);\n    for (const sub of docs.subcommands) {\n      lines.push(\n        `${indent}  ${sub.name}${\n          sub.description ? ` - ${sub.description}` : ''\n        }`\n      );\n    }\n    lines.push('');\n\n    // Recursively document subcommands\n    for (const sub of docs.subcommands) {\n      lines.push(generateLlmsTxtContent(sub, depth + 1, currentPath));\n    }\n  }\n\n  // Epilogue\n  if (docs.epilogue && depth === 0) {\n    lines.push(`Note: ${docs.epilogue}`);\n    lines.push('');\n  }\n\n  return lines.join('\\n');\n}\n\nfunction formatOptionType(opt: Documentation['options'][string]): string {\n  if ('items' in opt && opt.type === 'array') {\n    return `${opt.items}[]`;\n  }\n  return opt.type;\n}\n\nasync function generateMarkdownForSingleCommand(\n  docs: Documentation,\n  out: string,\n  docsRoot: string,\n  md: mdfactory\n) {\n  const subcommands = docs.subcommands;\n  const outdir = subcommands.length ? out : dirname(out);\n  const outname = subcommands.length ? 'index' : docs.name;\n\n  ensureDirSync(outdir);\n\n  writeFileSync(\n    join(outdir, outname + '.md'),\n    md.h1(\n      docs.name,\n      ...[\n        [md.bold('Usage:'), md.code(docs.usage)].join(' '),\n        docs.description,\n        getPositionalArgsFragment(docs.positionals, md),\n        getFlagArgsFragment(docs.options, 'Flags', md),\n        ...docs.groupedOptions.map((group) =>\n          getFlagArgsFragment(\n            Object.fromEntries(group.keys.map((key) => [key.key, key])),\n            group.label,\n            md\n          )\n        ),\n        getConfigurationSourcesLink(\n          docs.configurationSources,\n          outdir,\n          docsRoot,\n          md\n        ),\n        getSubcommandsFragment(docs.subcommands, outdir, docsRoot, md),\n        getExamplesFragment(docs.examples, md),\n        getEpilogueFragment(docs.epilogue, md),\n      ].filter(isTruthy)\n    )\n  );\n  writeConfigurationSourcesFile(docs.configurationSources, outdir, md);\n  for (const subcommand of docs.subcommands) {\n    await generateMarkdownForSingleCommand(\n      subcommand,\n      join(outdir, subcommand.name),\n      docsRoot,\n      md\n    );\n  }\n}\n\nfunction formatOption(option: Documentation['options'][string], md: mdfactory) {\n  return md.h3(\n    option.deprecated ? md.strikethrough(option.key) : option.key,\n    ...[\n      option.deprecated ? md.bold(md.italics('Deprecated')) : undefined,\n      md.bold('Type:') +\n        ' ' +\n        ('items' in option && option.type === 'array'\n          ? `${option.items}[]`\n          : option.type),\n      option.description,\n      option.default !== undefined\n        ? renderDefaultValueSection(option.default, md)\n        : undefined,\n      // No need to show required if it's required and has a default, as its not actually required to pass.\n      option.required && !option.default ? md.bold('Required') : undefined,\n      'choices' in option && option.choices\n        ? md.bold('Valid values:') +\n          ' ' +\n          (() => {\n            const choicesAsString = (\n              typeof option.choices === 'function'\n                ? option.choices()\n                : option.choices\n            ).map((t: any) => md.code(t.toString()));\n            return choicesAsString.join(', ');\n          })()\n        : undefined,\n      'resolvedEnvKey' in option && option.resolvedEnvKey\n        ? md.bold('Environment variable:') + ' ' + md.code(option.resolvedEnvKey as string)\n        : undefined,\n      option.alias?.length\n        ? md.h4('Aliases', md.ul(...option.alias))\n        : undefined,\n    ].filter(isTruthy)\n  );\n}\n\nfunction getPositionalArgsFragment(\n  positionals: Documentation['positionals'],\n  md: mdfactory\n) {\n  if (positionals?.length === 0) {\n    return undefined;\n  }\n  return md.h2(\n    'Positional Arguments',\n    ...positionals.map((positional) => formatOption(positional, md))\n  );\n}\n\nfunction getFlagArgsFragment(\n  options: Documentation['options'],\n  label: string,\n  md: mdfactory\n) {\n  if (Object.keys(options).length === 0) {\n    return undefined;\n  }\n  return md.h2(\n    label,\n    ...Object.values(options).map((option) => formatOption(option, md))\n  );\n}\n\nfunction getConfigurationSourcesLink(\n  sources: Documentation['configurationSources'],\n  outdir: string,\n  docsRoot: string,\n  md: mdfactory\n) {\n  if (!sources || sources.length === 0) {\n    return undefined;\n  }\n  const linkPath =\n    './' +\n    joinPathFragments(\n      normalize(relative(docsRoot, outdir)),\n      'configuration.md'\n    );\n  return md.h2('Configuration', md.link(linkPath, 'Configuration'));\n}\n\nfunction writeConfigurationSourcesFile(\n  sources: Documentation['configurationSources'],\n  outdir: string,\n  md: mdfactory\n) {\n  if (!sources || sources.length === 0) {\n    return;\n  }\n  ensureDirSync(outdir);\n  writeFileSync(\n    join(outdir, 'configuration.md'),\n    md.h1(\n      'Configuration',\n      ...sources.map((section) => md.h2(section.heading, section.body))\n    )\n  );\n}\n\nfunction getSubcommandsFragment(\n  subcommands: Documentation['subcommands'],\n  outdir: string,\n  docsRoot: string,\n  md: mdfactory\n) {\n  if (subcommands.length === 0) {\n    return undefined;\n  }\n  return md.h2(\n    'Subcommands',\n    ...subcommands.map((subcommand) =>\n      md.link(\n        './' +\n          joinPathFragments(\n            normalize(relative(docsRoot, outdir)),\n            subcommand.name + '.md'\n          ),\n        subcommand.name\n      )\n    )\n  );\n}\n\nfunction isTruthy<T>(value: T | undefined | null): value is T {\n  return !!value;\n}\n\nasync function importMarkdownFactory(): Promise<mdfactory> {\n  try {\n    return await import('markdown-factory');\n  } catch {\n    throw new Error(\n      'Could not find markdown-factory. Please install it to generate markdown documentation.'\n    );\n  }\n}\n\nfunction isCLI(obj: unknown): obj is InternalCLI {\n  return InternalCLI.isInternalCLI(obj);\n}\n\nfunction getExamplesFragment(\n  examples: string[],\n  md: typeof import('markdown-factory')\n): string | undefined {\n  if (examples.length === 0) {\n    return undefined;\n  }\n  return md.h2(\n    'Examples',\n    ...examples.map((example) => md.codeBlock(example, 'shell'))\n  );\n}\n\n/**\n * Reads the CLI instance from the provided module. For some reason,\n * when importing a module that uses `export default` in typescript\n * the default export is nested under a `default` property on the module...\n * We for code that looks like `export default 5`, on import we get back\n * `{ default: {default: 5}}`. To work around this, and make things work\n * we try to read the CLI instance from the module in a few different ways.\n *\n * @param cliModule The imported module\n * @param exportSpecifier The name of the export to read the CLI from. Defaults to `default`.\n * @returns A CLI instance.\n */\nfunction readCLIFromModule(\n  cliModule: any,\n  args: GenerateDocsArgs\n): InternalCLI {\n  let cli = cliModule;\n  if (args.export) {\n    cli = cliModule[args.export] ?? cliModule['default']?.[args.export];\n  } else {\n    cli =\n      cliModule['default']?.['default'] ?? cliModule['default'] ?? cliModule;\n  }\n  if (!isCLI(cli)) {\n    throw new Error(\n      `${args.cli}${args.export ? '#' + args.export : ''} is not a CLI.`\n    );\n  }\n  return cli;\n}\n\n/**\n * Detects whether a file should be loaded as ESM or CJS.\n * Checks file extension first (.mjs/.mts = ESM, .cjs/.cts = CJS),\n * then falls back to the nearest package.json's \"type\" field.\n */\nfunction detectModuleType(filePath: string): 'esm' | 'cjs' {\n  const ext = filePath.split('.').pop()?.toLowerCase();\n\n  // Explicit extensions take precedence\n  if (ext === 'mjs' || ext === 'mts') {\n    return 'esm';\n  }\n  if (ext === 'cjs' || ext === 'cts') {\n    return 'cjs';\n  }\n\n  // Find nearest package.json and check \"type\" field\n  const absolutePath = isAbsolute(filePath)\n    ? filePath\n    : join(process.cwd(), filePath);\n  let dir = dirname(absolutePath);\n  const root = dirname(dir);\n\n  while (dir !== root) {\n    const pkgPath = join(dir, 'package.json');\n    if (existsSync(pkgPath)) {\n      try {\n        const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n        return pkg.type === 'module' ? 'esm' : 'cjs';\n      } catch {\n        // Ignore parse errors, continue searching\n      }\n    }\n    dir = dirname(dir);\n  }\n\n  // Default to CJS (Node.js default)\n  return 'cjs';\n}\n\nasync function loadCLIModule(\n  args: ArgumentsOf<typeof withGenerateDocumentationArgs>\n) {\n  if (isAbsolute(args.cli)) {\n    args.cli = relative(process.cwd(), args.cli);\n  }\n\n  const cliPath = [\n    args.cli,\n    `${args.cli}.ts`,\n    `${args.cli}.js`,\n    `${args.cli}.cjs`,\n    `${args.cli}.mjs`,\n    join(args.cli, 'index.ts'),\n    join(args.cli, 'index.js'),\n    join(args.cli, 'index.cjs'),\n    join(args.cli, 'index.mjs'),\n  ].find((f) => {\n    const p = isAbsolute(f) ? f : join(process.cwd(), f);\n    console.log('Checking for CLI at', p);\n    return existsSync(p);\n  });\n\n  if (!cliPath) {\n    throw new Error(`Could not find CLI module at ${args.cli}\n\n      Ensure that the path is correct and that the CLI module exists.`);\n  }\n\n  const moduleType = detectModuleType(cliPath);\n\n  try {\n    if (moduleType === 'esm') {\n      const tsx = (await import('tsx/esm/api')) as typeof import('tsx/esm/api');\n      return tsx.tsImport(cliPath, {\n        ...(args.tsconfig ? { tsconfig: args.tsconfig } : {}),\n        parentURL: pathToFileURL(\n          join(process.cwd(), 'fake-file-for-import.ts')\n        ).toString(),\n      });\n    } else {\n      const tsx = (await import('tsx/cjs/api')) as typeof import('tsx/cjs/api');\n      return tsx.require(\n        cliPath,\n        join(process.cwd(), 'fake-file-for-require.ts')\n      );\n    }\n  } catch {\n    try {\n      // Resolve relative paths to absolute file:// URLs so ESM import()\n      // resolves from cwd, not from this file's location in node_modules.\n      const importSpecifier = isAbsolute(cliPath)\n        ? pathToFileURL(cliPath).href\n        : pathToFileURL(join(process.cwd(), cliPath)).href;\n      return await import(importSpecifier);\n    } catch (e) {\n      if (cliPath.endsWith('.ts')) {\n        console.warn(\n          '[cli-forge]: Generating docs for a typescript CLI requires installing `tsx` as a dev dependency, targeting the build artifacts instead, or otherwise registering a typescript loader with node.'\n        );\n      }\n      throw e;\n    }\n  }\n}\n\nfunction getEpilogueFragment(\n  epilogue: string | undefined,\n  md: typeof import('markdown-factory')\n) {\n  if (!epilogue) {\n    return undefined;\n  }\n  return md.blockQuote(epilogue);\n}\n\nfunction renderDefaultValueSection(defaultValue: unknown, md: mdfactory) {\n  const json = JSON.stringify(defaultValue, null, 2);\n  if (json.split('\\n').length > 1) {\n    return md.lines(md.bold('Default:'), md.codeBlock(json, 'json'));\n  } else {\n    return md.bold('Default:') + ' ' + md.code(json);\n  }\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAgB,8BACd,KACA;AACA,QAAO,IACJ,WAAW,OAAO;EACjB,MAAM;EACN,aAAa;EACb,UAAU;EACX,CAAC,CACD,OAAO,UAAU;EAChB,OAAO,CAAC,IAAI;EACZ,MAAM;EACN,aAAa;EACb,SAAS;EACV,CAAC,CACD,OAAO,UAAU;EAChB,MAAM;EACN,aAAa;EACb,SAAS;EACT,SAAS,CAAC,QAAQ,KAAK;EACxB,CAAC,CACD,OAAO,UAAU;EAChB,MAAM;EACN,aACE;EACH,CAAC,CACD,OAAO,YAAY;EAClB,MAAM;EACN,aACE;EACH,CAAC,CACD,OAAO,QAAQ;EACd,MAAM;EACN,aACE;EACF,SAAS;EACV,CAAC;;AAGN,MAAa,+BAA+BA,uBAAAA,IAAI,0BAA0B;CACxE,aAAa;CACb,UAAU;EACR;EACA;EACA;EACD;CACD,UAAU,MAAM,8BAA8B,EAAE;CAChD,SAAS,OAAO,SAAS;EAEvB,MAAM,MAAM,kBADM,MAAM,cAAc,KAAK,EACF,KAAK;EAE9C,MAAM,gBAAgBC,0BAAAA,sBAAsB,IAAI;AAChD,MAAI,KAAK,WAAW,MAAM;AACxB,SAAM,8BAA8B,eAAe,KAAK;AAExD,OAAI,KAAK,KACP,iBAAgB,eAAe,KAAK;aAE7B,KAAK,WAAW,QAAQ;GACjC,MAAM,UAAU,KAAK,OAAO,SAAS,OAAO,GACxC,KAAK,UAAA,GAAA,UAAA,MACA,KAAK,QAAQ,IAAI,OAAO,QAAQ;AAEzC,wBAAA,eAAA,GAAA,U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