@crafter/cli-tree 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +328 -0
- package/dist/archaeology/cache.d.ts +11 -0
- package/dist/archaeology/delegate.d.ts +43 -0
- package/dist/archaeology/index.d.ts +12 -0
- package/dist/archaeology/index.js +61 -0
- package/dist/archaeology/index.js.map +9 -0
- package/dist/archaeology/llm.d.ts +1 -0
- package/dist/archaeology/merge.d.ts +3 -0
- package/dist/archaeology/orchestrator.d.ts +25 -0
- package/dist/archaeology/prompts.d.ts +13 -0
- package/dist/archaeology/types.d.ts +101 -0
- package/dist/archaeology/validate.d.ts +18 -0
- package/dist/chunk-57gtsvhb.js +434 -0
- package/dist/chunk-57gtsvhb.js.map +16 -0
- package/dist/chunk-5aahbfr2.js +293 -0
- package/dist/chunk-5aahbfr2.js.map +10 -0
- package/dist/chunk-pkfpaae1.js +678 -0
- package/dist/chunk-pkfpaae1.js.map +15 -0
- package/dist/chunk-q4se2rwe.js +181 -0
- package/dist/chunk-q4se2rwe.js.map +14 -0
- package/dist/chunk-v5w3w6bd.js +168 -0
- package/dist/chunk-v5w3w6bd.js.map +11 -0
- package/dist/chunk-ykze151b.js +770 -0
- package/dist/chunk-ykze151b.js.map +16 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +433 -0
- package/dist/cli.js.map +10 -0
- package/dist/encoders/ansi.d.ts +2 -0
- package/dist/encoders/html.d.ts +10 -0
- package/dist/encoders/string.d.ts +2 -0
- package/dist/flow/encode.d.ts +5 -0
- package/dist/flow/index.d.ts +8 -0
- package/dist/flow/index.js +25 -0
- package/dist/flow/index.js.map +9 -0
- package/dist/flow/layout.d.ts +30 -0
- package/dist/flow/parse.d.ts +2 -0
- package/dist/flow/render.d.ts +3 -0
- package/dist/flow/types.d.ts +42 -0
- package/dist/flow/validate.d.ts +3 -0
- package/dist/flow/yaml.d.ts +4 -0
- package/dist/grid.d.ts +14 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +9 -0
- package/dist/miner/history.d.ts +6 -0
- package/dist/miner/index.d.ts +18 -0
- package/dist/miner/index.js +38 -0
- package/dist/miner/index.js.map +9 -0
- package/dist/miner/sessions.d.ts +3 -0
- package/dist/miner/stats.d.ts +2 -0
- package/dist/miner/suggest.d.ts +11 -0
- package/dist/miner/transitions.d.ts +6 -0
- package/dist/miner/types.d.ts +46 -0
- package/dist/miner/workflows.d.ts +11 -0
- package/dist/parse.d.ts +3 -0
- package/dist/render.d.ts +3 -0
- package/dist/types.d.ts +39 -0
- package/package.json +85 -0
- package/skill/SKILL.md +263 -0
- package/skill/evals/evals.json +26 -0
- package/skill/install.sh +38 -0
- package/skill/references/archaeology-guide.md +157 -0
- package/skill/references/skill-template.md +120 -0
- package/src/archaeology/cache.ts +107 -0
- package/src/archaeology/delegate.ts +113 -0
- package/src/archaeology/index.ts +48 -0
- package/src/archaeology/llm.ts +10 -0
- package/src/archaeology/merge.ts +155 -0
- package/src/archaeology/orchestrator.ts +185 -0
- package/src/archaeology/prompts.ts +178 -0
- package/src/archaeology/types.ts +139 -0
- package/src/archaeology/validate.ts +157 -0
- package/src/cli.ts +451 -0
- package/src/encoders/ansi.ts +32 -0
- package/src/encoders/html.ts +78 -0
- package/src/encoders/string.ts +20 -0
- package/src/flow/encode.ts +21 -0
- package/src/flow/index.ts +15 -0
- package/src/flow/layout.ts +150 -0
- package/src/flow/parse.ts +100 -0
- package/src/flow/render.ts +186 -0
- package/src/flow/types.ts +45 -0
- package/src/flow/validate.ts +111 -0
- package/src/flow/yaml.ts +235 -0
- package/src/grid.ts +59 -0
- package/src/index.ts +24 -0
- package/src/miner/history.ts +156 -0
- package/src/miner/index.ts +76 -0
- package/src/miner/sessions.ts +39 -0
- package/src/miner/stats.ts +43 -0
- package/src/miner/suggest.ts +101 -0
- package/src/miner/transitions.ts +62 -0
- package/src/miner/types.ts +45 -0
- package/src/miner/workflows.ts +96 -0
- package/src/parse.ts +321 -0
- package/src/render.ts +182 -0
- package/src/types.ts +62 -0
- package/workflows/docker-deploy.yml +42 -0
- package/workflows/docker-parallel.yml +36 -0
- package/workflows/gh-issue-to-pr.yml +48 -0
- package/workflows/git-pr-flow.yml +36 -0
- package/workflows/kubectl-rollout.yml +37 -0
- package/workflows/npm-publish.yml +42 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/flow/yaml.ts", "../src/flow/parse.ts", "../src/flow/validate.ts", "../src/flow/layout.ts", "../src/flow/render.ts", "../src/flow/encode.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"export type YamlValue = string | number | boolean | null | YamlValue[] | { [key: string]: YamlValue };\n\nexport function parseYaml(text: string): YamlValue {\n\tconst lines = text.split(\"\\n\");\n\tconst cleaned: { indent: number; content: string; lineNum: number }[] = [];\n\n\tfor (let i = 0; i < lines.length; i++) {\n\t\tconst raw = lines[i]!;\n\t\tconst commentIdx = findCommentStart(raw);\n\t\tconst withoutComment = commentIdx >= 0 ? raw.slice(0, commentIdx) : raw;\n\t\tconst trimmed = withoutComment.trimEnd();\n\t\tif (!trimmed.trim()) continue;\n\n\t\tconst indent = trimmed.length - trimmed.trimStart().length;\n\t\tcleaned.push({ indent, content: trimmed.trim(), lineNum: i + 1 });\n\t}\n\n\tconst result = parseBlock(cleaned, 0, 0);\n\treturn result.value;\n}\n\nfunction findCommentStart(line: string): number {\n\tlet inString: string | null = null;\n\tfor (let i = 0; i < line.length; i++) {\n\t\tconst ch = line[i];\n\t\tif (inString) {\n\t\t\tif (ch === inString && line[i - 1] !== \"\\\\\") inString = null;\n\t\t} else {\n\t\t\tif (ch === '\"' || ch === \"'\") inString = ch;\n\t\t\telse if (ch === \"#\" && (i === 0 || line[i - 1] === \" \" || line[i - 1] === \"\\t\")) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\treturn -1;\n}\n\ninterface ParseState {\n\tvalue: YamlValue;\n\tnextIdx: number;\n}\n\nfunction parseBlock(\n\tlines: { indent: number; content: string; lineNum: number }[],\n\tstartIdx: number,\n\tbaseIndent: number,\n): ParseState {\n\tif (startIdx >= lines.length) return { value: null, nextIdx: startIdx };\n\n\tconst first = lines[startIdx]!;\n\tif (first.indent < baseIndent) return { value: null, nextIdx: startIdx };\n\n\tif (first.content.startsWith(\"- \") || first.content === \"-\") {\n\t\treturn parseList(lines, startIdx, first.indent);\n\t}\n\n\tif (first.content.includes(\":\")) {\n\t\treturn parseMap(lines, startIdx, first.indent);\n\t}\n\n\treturn { value: parseScalar(first.content), nextIdx: startIdx + 1 };\n}\n\nfunction parseList(\n\tlines: { indent: number; content: string; lineNum: number }[],\n\tstartIdx: number,\n\tlistIndent: number,\n): ParseState {\n\tconst items: YamlValue[] = [];\n\tlet i = startIdx;\n\n\twhile (i < lines.length) {\n\t\tconst line = lines[i]!;\n\t\tif (line.indent < listIndent) break;\n\t\tif (line.indent > listIndent) {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!line.content.startsWith(\"- \") && line.content !== \"-\") break;\n\n\t\tconst itemContent = line.content === \"-\" ? \"\" : line.content.slice(2);\n\n\t\tif (!itemContent) {\n\t\t\tconst childIndent = listIndent + 2;\n\t\t\tconst next = parseBlock(lines, i + 1, childIndent);\n\t\t\titems.push(next.value);\n\t\t\ti = next.nextIdx;\n\t\t} else if (itemContent.includes(\":\") && !isFlowScalar(itemContent)) {\n\t\t\tconst inlineIndent = listIndent + 2;\n\t\t\tconst synthetic = [\n\t\t\t\t{ indent: inlineIndent, content: itemContent, lineNum: line.lineNum },\n\t\t\t\t...lines.slice(i + 1),\n\t\t\t];\n\t\t\tconst mapResult = parseMap(synthetic, 0, inlineIndent);\n\t\t\titems.push(mapResult.value);\n\t\t\ti = i + 1 + (mapResult.nextIdx - 1);\n\t\t} else {\n\t\t\titems.push(parseScalar(itemContent));\n\t\t\ti++;\n\t\t}\n\t}\n\n\treturn { value: items, nextIdx: i };\n}\n\nfunction parseMap(\n\tlines: { indent: number; content: string; lineNum: number }[],\n\tstartIdx: number,\n\tmapIndent: number,\n): ParseState {\n\tconst map: { [key: string]: YamlValue } = {};\n\tlet i = startIdx;\n\n\twhile (i < lines.length) {\n\t\tconst line = lines[i]!;\n\t\tif (line.indent < mapIndent) break;\n\t\tif (line.indent > mapIndent) {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst colonIdx = findUnquotedColon(line.content);\n\t\tif (colonIdx < 0) break;\n\n\t\tconst key = line.content.slice(0, colonIdx).trim().replace(/^[\"']|[\"']$/g, \"\");\n\t\tconst rest = line.content.slice(colonIdx + 1).trim();\n\n\t\tif (!rest) {\n\t\t\tconst next = parseBlock(lines, i + 1, mapIndent + 1);\n\t\t\tmap[key] = next.value;\n\t\t\ti = next.nextIdx;\n\t\t} else if (rest.startsWith(\"[\") && rest.endsWith(\"]\")) {\n\t\t\tmap[key] = parseInlineList(rest);\n\t\t\ti++;\n\t\t} else if (rest.startsWith(\"{\") && rest.endsWith(\"}\")) {\n\t\t\tmap[key] = parseInlineMap(rest);\n\t\t\ti++;\n\t\t} else {\n\t\t\tmap[key] = parseScalar(rest);\n\t\t\ti++;\n\t\t}\n\t}\n\n\treturn { value: map, nextIdx: i };\n}\n\nfunction findUnquotedColon(text: string): number {\n\tlet inString: string | null = null;\n\tlet bracket = 0;\n\tfor (let i = 0; i < text.length; i++) {\n\t\tconst ch = text[i];\n\t\tif (inString) {\n\t\t\tif (ch === inString && text[i - 1] !== \"\\\\\") inString = null;\n\t\t} else {\n\t\t\tif (ch === '\"' || ch === \"'\") inString = ch;\n\t\t\telse if (ch === \"[\" || ch === \"{\") bracket++;\n\t\t\telse if (ch === \"]\" || ch === \"}\") bracket--;\n\t\t\telse if (ch === \":\" && bracket === 0) return i;\n\t\t}\n\t}\n\treturn -1;\n}\n\nfunction parseScalar(text: string): YamlValue {\n\tconst trimmed = text.trim();\n\tif (trimmed === \"\" || trimmed === \"null\" || trimmed === \"~\") return null;\n\tif (trimmed === \"true\") return true;\n\tif (trimmed === \"false\") return false;\n\n\tif ((trimmed.startsWith('\"') && trimmed.endsWith('\"')) || (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))) {\n\t\treturn trimmed.slice(1, -1).replace(/\\\\\"/g, '\"').replace(/\\\\'/g, \"'\");\n\t}\n\n\tconst num = Number(trimmed);\n\tif (!Number.isNaN(num) && /^-?\\d+(\\.\\d+)?$/.test(trimmed)) return num;\n\n\treturn trimmed;\n}\n\nfunction isFlowScalar(text: string): boolean {\n\treturn text.startsWith(\"[\") || text.startsWith(\"{\") || text.startsWith('\"') || text.startsWith(\"'\");\n}\n\nfunction parseInlineList(text: string): YamlValue[] {\n\tconst inner = text.slice(1, -1).trim();\n\tif (!inner) return [];\n\treturn splitTopLevel(inner, \",\").map(item => parseScalar(item.trim()));\n}\n\nfunction parseInlineMap(text: string): { [key: string]: YamlValue } {\n\tconst inner = text.slice(1, -1).trim();\n\tif (!inner) return {};\n\tconst result: { [key: string]: YamlValue } = {};\n\tfor (const pair of splitTopLevel(inner, \",\")) {\n\t\tconst colonIdx = findUnquotedColon(pair);\n\t\tif (colonIdx < 0) continue;\n\t\tconst key = pair.slice(0, colonIdx).trim().replace(/^[\"']|[\"']$/g, \"\");\n\t\tconst val = pair.slice(colonIdx + 1).trim();\n\t\tresult[key] = parseScalar(val);\n\t}\n\treturn result;\n}\n\nfunction splitTopLevel(text: string, sep: string): string[] {\n\tconst parts: string[] = [];\n\tlet depth = 0;\n\tlet inString: string | null = null;\n\tlet current = \"\";\n\n\tfor (let i = 0; i < text.length; i++) {\n\t\tconst ch = text[i]!;\n\t\tif (inString) {\n\t\t\tif (ch === inString && text[i - 1] !== \"\\\\\") inString = null;\n\t\t\tcurrent += ch;\n\t\t} else {\n\t\t\tif (ch === '\"' || ch === \"'\") {\n\t\t\t\tinString = ch;\n\t\t\t\tcurrent += ch;\n\t\t\t} else if (ch === \"[\" || ch === \"{\") {\n\t\t\t\tdepth++;\n\t\t\t\tcurrent += ch;\n\t\t\t} else if (ch === \"]\" || ch === \"}\") {\n\t\t\t\tdepth--;\n\t\t\t\tcurrent += ch;\n\t\t\t} else if (ch === sep && depth === 0) {\n\t\t\t\tparts.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t} else {\n\t\t\t\tcurrent += ch;\n\t\t\t}\n\t\t}\n\t}\n\tif (current) parts.push(current);\n\treturn parts;\n}\n",
|
|
6
|
+
"import { parseYaml, type YamlValue } from \"./yaml\";\nimport type { Workflow, WorkflowNode, WorkflowEdge } from \"./types\";\n\nexport function parseWorkflow(yamlText: string): Workflow {\n\tconst raw = parseYaml(yamlText);\n\tif (!isObject(raw)) {\n\t\tthrow new Error(\"Workflow YAML must be a map at the top level\");\n\t}\n\n\tconst name = asString(raw.name, \"name\");\n\tconst cli = asString(raw.cli, \"cli\");\n\tconst description = raw.description ? asString(raw.description, \"description\") : undefined;\n\tconst version = raw.version ? asString(raw.version, \"version\") : undefined;\n\n\tconst nodes = parseNodes(raw.nodes);\n\tconst edges = parseEdges(raw.edges, nodes);\n\n\tconst workflow: Workflow = { name, cli, nodes, edges };\n\tif (description) workflow.description = description;\n\tif (version) workflow.version = version;\n\treturn workflow;\n}\n\nfunction parseNodes(raw: YamlValue): WorkflowNode[] {\n\tif (!Array.isArray(raw)) {\n\t\tthrow new Error(\"'nodes' must be a list\");\n\t}\n\n\treturn raw.map((item, idx) => {\n\t\tif (!isObject(item)) {\n\t\t\tthrow new Error(`nodes[${idx}] must be a map`);\n\t\t}\n\n\t\tconst id = asString(item.id, `nodes[${idx}].id`);\n\t\tconst cmdRaw = item.command;\n\n\t\tlet command: string[];\n\t\tif (typeof cmdRaw === \"string\") {\n\t\t\tcommand = cmdRaw.split(/\\s+/).filter(Boolean);\n\t\t} else if (Array.isArray(cmdRaw)) {\n\t\t\tcommand = cmdRaw.map(c => String(c));\n\t\t} else {\n\t\t\tthrow new Error(`nodes[${idx}].command must be a string or list`);\n\t\t}\n\n\t\tconst node: WorkflowNode = { id, command };\n\t\tif (typeof item.label === \"string\") node.label = item.label;\n\t\tif (typeof item.description === \"string\") node.description = item.description;\n\t\tif (typeof item.optional === \"boolean\") node.optional = item.optional;\n\t\treturn node;\n\t});\n}\n\nfunction parseEdges(raw: YamlValue, nodes: WorkflowNode[]): WorkflowEdge[] {\n\tif (!raw) return inferSequentialEdges(nodes);\n\tif (!Array.isArray(raw)) {\n\t\tthrow new Error(\"'edges' must be a list\");\n\t}\n\n\treturn raw.map((item, idx) => {\n\t\tif (typeof item === \"string\") {\n\t\t\tconst parts = item.split(\"->\").map(s => s.trim());\n\t\t\tif (parts.length !== 2) {\n\t\t\t\tthrow new Error(`edges[${idx}] string must be \"from -> to\"`);\n\t\t\t}\n\t\t\treturn { from: parts[0]!, to: parts[1]! };\n\t\t}\n\n\t\tif (!isObject(item)) {\n\t\t\tthrow new Error(`edges[${idx}] must be a map or string`);\n\t\t}\n\n\t\tconst edge: WorkflowEdge = {\n\t\t\tfrom: asString(item.from, `edges[${idx}].from`),\n\t\t\tto: asString(item.to, `edges[${idx}].to`),\n\t\t};\n\t\tif (typeof item.condition === \"string\") edge.condition = item.condition;\n\t\tif (typeof item.label === \"string\") edge.label = item.label;\n\t\treturn edge;\n\t});\n}\n\nfunction inferSequentialEdges(nodes: WorkflowNode[]): WorkflowEdge[] {\n\tconst edges: WorkflowEdge[] = [];\n\tfor (let i = 0; i < nodes.length - 1; i++) {\n\t\tedges.push({ from: nodes[i]!.id, to: nodes[i + 1]!.id });\n\t}\n\treturn edges;\n}\n\nfunction isObject(value: YamlValue): value is { [key: string]: YamlValue } {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction asString(value: YamlValue, field: string): string {\n\tif (typeof value !== \"string\") {\n\t\tthrow new Error(`${field} must be a string`);\n\t}\n\treturn value;\n}\n",
|
|
7
|
+
"import type { CLINode } from \"../types\";\nimport type { Workflow, ValidationError, ValidationResult } from \"./types\";\n\nexport function validateWorkflow(workflow: Workflow, tree?: CLINode): ValidationResult {\n\tconst errors: ValidationError[] = [];\n\tconst nodeIds = new Set(workflow.nodes.map(n => n.id));\n\n\tif (nodeIds.size !== workflow.nodes.length) {\n\t\terrors.push({ severity: \"error\", message: \"Duplicate node IDs found\" });\n\t}\n\n\tfor (const node of workflow.nodes) {\n\t\tif (node.command.length === 0) {\n\t\t\terrors.push({ node: node.id, severity: \"error\", message: `Node \"${node.id}\" has empty command` });\n\t\t}\n\t\tif (node.command[0] !== workflow.cli) {\n\t\t\terrors.push({\n\t\t\t\tnode: node.id,\n\t\t\t\tseverity: \"warning\",\n\t\t\t\tmessage: `Node \"${node.id}\" command \"${node.command[0]}\" does not match workflow cli \"${workflow.cli}\"`,\n\t\t\t});\n\t\t}\n\t}\n\n\tfor (const edge of workflow.edges) {\n\t\tif (!nodeIds.has(edge.from)) {\n\t\t\terrors.push({\n\t\t\t\tedge: { from: edge.from, to: edge.to },\n\t\t\t\tseverity: \"error\",\n\t\t\t\tmessage: `Edge references unknown node \"${edge.from}\"`,\n\t\t\t});\n\t\t}\n\t\tif (!nodeIds.has(edge.to)) {\n\t\t\terrors.push({\n\t\t\t\tedge: { from: edge.from, to: edge.to },\n\t\t\t\tseverity: \"error\",\n\t\t\t\tmessage: `Edge references unknown node \"${edge.to}\"`,\n\t\t\t});\n\t\t}\n\t}\n\n\tif (hasCycle(workflow)) {\n\t\terrors.push({ severity: \"error\", message: \"Workflow contains a cycle — DAGs only\" });\n\t}\n\n\tif (tree) {\n\t\tfor (const node of workflow.nodes) {\n\t\t\tconst subcommand = node.command.slice(1).filter(arg => !arg.startsWith(\"-\") && !arg.startsWith(\"$\") && /^[a-z]/i.test(arg));\n\t\t\tif (subcommand.length === 0) {\n\t\t\t\tnode.ref = tree;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst firstMatch = tree.subcommands?.find(s => s.name === subcommand[0] || s.aliases?.includes(subcommand[0]!));\n\t\t\tif (!firstMatch) {\n\t\t\t\terrors.push({\n\t\t\t\t\tnode: node.id,\n\t\t\t\t\tseverity: \"warning\",\n\t\t\t\t\tmessage: `Command \"${node.command.join(\" \")}\" not found in ${workflow.cli} tree`,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tnode.ref = findInTree(tree, subcommand);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tvalid: errors.filter(e => e.severity === \"error\").length === 0,\n\t\terrors,\n\t};\n}\n\nfunction hasCycle(workflow: Workflow): boolean {\n\tconst adj = new Map<string, string[]>();\n\tfor (const node of workflow.nodes) adj.set(node.id, []);\n\tfor (const edge of workflow.edges) {\n\t\tadj.get(edge.from)?.push(edge.to);\n\t}\n\n\tconst WHITE = 0, GRAY = 1, BLACK = 2;\n\tconst color = new Map<string, number>();\n\tfor (const node of workflow.nodes) color.set(node.id, WHITE);\n\n\tfunction visit(u: string): boolean {\n\t\tcolor.set(u, GRAY);\n\t\tfor (const v of adj.get(u) ?? []) {\n\t\t\tconst c = color.get(v);\n\t\t\tif (c === GRAY) return true;\n\t\t\tif (c === WHITE && visit(v)) return true;\n\t\t}\n\t\tcolor.set(u, BLACK);\n\t\treturn false;\n\t}\n\n\tfor (const node of workflow.nodes) {\n\t\tif (color.get(node.id) === WHITE && visit(node.id)) return true;\n\t}\n\treturn false;\n}\n\nfunction findInTree(tree: CLINode, path: string[]): CLINode | undefined {\n\tlet current: CLINode | undefined = tree;\n\tfor (const segment of path) {\n\t\tconst child: CLINode | undefined = current?.subcommands?.find(\n\t\t\t(s) => s.name === segment || s.aliases?.includes(segment),\n\t\t);\n\t\tif (!child) return current;\n\t\tcurrent = child;\n\t}\n\treturn current;\n}\n",
|
|
8
|
+
"import type { Workflow, WorkflowNode, WorkflowEdge } from \"./types\";\n\nexport interface LayoutNode {\n\tid: string;\n\tnode: WorkflowNode;\n\tcol: number;\n\trow: number;\n\twidth: number;\n\theight: number;\n\tx: number;\n\ty: number;\n}\n\nexport interface LayoutEdge {\n\tfrom: string;\n\tto: string;\n\tedge: WorkflowEdge;\n}\n\nexport interface Layout {\n\tnodes: LayoutNode[];\n\tedges: LayoutEdge[];\n\ttotalWidth: number;\n\ttotalHeight: number;\n}\n\nexport interface LayoutOptions {\n\tboxPaddingX?: number;\n\tcolGap?: number;\n\trowGap?: number;\n\tminBoxWidth?: number;\n}\n\nexport function computeLayout(workflow: Workflow, opts: LayoutOptions = {}): Layout {\n\tconst boxPaddingX = opts.boxPaddingX ?? 2;\n\tconst colGap = opts.colGap ?? 4;\n\tconst rowGap = opts.rowGap ?? 2;\n\tconst minBoxWidth = opts.minBoxWidth ?? 8;\n\n\tconst ranks = computeRanks(workflow);\n\tconst byRank = groupByRank(workflow.nodes, ranks);\n\tconst maxRank = Math.max(0, ...Array.from(ranks.values()));\n\n\tconst allWidths = workflow.nodes.map(n => boxWidthFor(n, boxPaddingX, minBoxWidth));\n\tconst uniformWidth = Math.max(...allWidths);\n\n\tconst maxPerRank = Math.max(\n\t\t1,\n\t\t...Array.from(byRank.values()).map(v => v.length),\n\t);\n\tconst totalRowWidth = maxPerRank * uniformWidth + (maxPerRank - 1) * colGap;\n\n\tconst layoutNodes: LayoutNode[] = [];\n\tconst boxHeight = 3;\n\n\tlet currentY = 0;\n\tfor (let r = 0; r <= maxRank; r++) {\n\t\tconst rankNodes = byRank.get(r) ?? [];\n\t\tconst count = rankNodes.length;\n\t\tconst rowWidth = count * uniformWidth + (count - 1) * colGap;\n\t\tconst startX = Math.floor((totalRowWidth - rowWidth) / 2);\n\n\t\tfor (let i = 0; i < rankNodes.length; i++) {\n\t\t\tconst node = rankNodes[i]!;\n\t\t\tconst x = startX + i * (uniformWidth + colGap);\n\t\t\tlayoutNodes.push({\n\t\t\t\tid: node.id,\n\t\t\t\tnode,\n\t\t\t\tcol: i,\n\t\t\t\trow: r,\n\t\t\t\twidth: uniformWidth,\n\t\t\t\theight: boxHeight,\n\t\t\t\tx,\n\t\t\t\ty: currentY,\n\t\t\t});\n\t\t}\n\n\t\tcurrentY += boxHeight + rowGap;\n\t}\n\n\tconst totalWidth = Math.max(\n\t\t0,\n\t\t...layoutNodes.map(n => n.x + n.width),\n\t);\n\tconst totalHeight = Math.max(\n\t\t0,\n\t\t...layoutNodes.map(n => n.y + n.height),\n\t);\n\n\tconst edges: LayoutEdge[] = workflow.edges.map(e => ({\n\t\tfrom: e.from,\n\t\tto: e.to,\n\t\tedge: e,\n\t}));\n\n\treturn { nodes: layoutNodes, edges, totalWidth, totalHeight };\n}\n\nfunction computeRanks(workflow: Workflow): Map<string, number> {\n\tconst ranks = new Map<string, number>();\n\tconst inEdges = new Map<string, string[]>();\n\tfor (const node of workflow.nodes) {\n\t\tranks.set(node.id, 0);\n\t\tinEdges.set(node.id, []);\n\t}\n\tfor (const edge of workflow.edges) {\n\t\tinEdges.get(edge.to)?.push(edge.from);\n\t}\n\n\tconst visiting = new Set<string>();\n\tfunction visit(id: string): number {\n\t\tif (visiting.has(id)) return ranks.get(id) ?? 0;\n\t\tvisiting.add(id);\n\t\tconst parents = inEdges.get(id) ?? [];\n\t\tif (parents.length === 0) {\n\t\t\tranks.set(id, 0);\n\t\t} else {\n\t\t\tconst maxParent = Math.max(...parents.map(p => visit(p)));\n\t\t\tranks.set(id, maxParent + 1);\n\t\t}\n\t\tvisiting.delete(id);\n\t\treturn ranks.get(id)!;\n\t}\n\n\tfor (const node of workflow.nodes) {\n\t\tvisit(node.id);\n\t}\n\n\treturn ranks;\n}\n\nfunction groupByRank(nodes: WorkflowNode[], ranks: Map<string, number>): Map<number, WorkflowNode[]> {\n\tconst byRank = new Map<number, WorkflowNode[]>();\n\tfor (const node of nodes) {\n\t\tconst r = ranks.get(node.id) ?? 0;\n\t\tif (!byRank.has(r)) byRank.set(r, []);\n\t\tbyRank.get(r)!.push(node);\n\t}\n\treturn byRank;\n}\n\nfunction boxWidthFor(node: WorkflowNode, padding: number, minWidth: number): number {\n\tconst label = node.label ?? node.id;\n\tconst contentWidth = label.length;\n\treturn Math.max(minWidth, contentWidth + padding * 2 + 2);\n}\n\nexport function findNode(layout: Layout, id: string): LayoutNode | undefined {\n\treturn layout.nodes.find(n => n.id === id);\n}\n",
|
|
9
|
+
"import { createGrid, writeText, type Grid } from \"../grid\";\nimport { computeLayout, findNode, type Layout, type LayoutNode } from \"./layout\";\nimport type { Workflow, FlowRenderOptions } from \"./types\";\n\nconst BOX = {\n\ttopLeft: \"┌\",\n\ttopRight: \"┐\",\n\tbotLeft: \"└\",\n\tbotRight: \"┘\",\n\thoriz: \"─\",\n\tvert: \"│\",\n\tarrowDown: \"▼\",\n\tarrowRight: \"►\",\n\tjunctionDown: \"┬\",\n\tjunctionUp: \"┴\",\n\tjunctionLeft: \"┤\",\n\tjunctionRight: \"├\",\n\tcross: \"┼\",\n};\n\nconst COLOR = {\n\tboxFrame: \"gray\",\n\tlabel: \"cyan\",\n\toptional: \"yellow\",\n\tarrow: \"gray\",\n\ttitle: \"magenta\",\n\tdescription: \"gray\",\n};\n\nexport function renderFlow(workflow: Workflow, opts: FlowRenderOptions = {}): Grid {\n\tconst useColor = opts.color ?? true;\n\tconst showDescriptions = opts.showDescriptions ?? true;\n\tconst compact = opts.compact ?? false;\n\n\tconst layout = computeLayout(workflow);\n\n\tconst titleLines = buildTitle(workflow, showDescriptions && !compact);\n\tconst titleOffset = titleLines.length;\n\tconst flowHeight = layout.totalHeight;\n\tconst legendLines = compact ? [] : buildLegend(workflow);\n\tconst legendOffset = legendLines.length > 0 ? legendLines.length + 1 : 0;\n\n\tconst totalHeight = titleOffset + flowHeight + legendOffset + 1;\n\tconst totalWidth = Math.max(layout.totalWidth, maxLineLength(titleLines), maxLineLength(legendLines)) + 2;\n\n\tconst grid = createGrid(totalWidth);\n\tfor (let i = 0; i < totalHeight; i++) grid.addRow();\n\n\tlet row = 0;\n\tfor (const line of titleLines) {\n\t\twriteText(grid, 0, row, line.text, useColor ? line.color : null);\n\t\trow++;\n\t}\n\n\tfor (const node of layout.nodes) {\n\t\tdrawBox(grid, node, row + node.y, useColor);\n\t}\n\n\tfor (const edge of layout.edges) {\n\t\tconst from = findNode(layout, edge.from);\n\t\tconst to = findNode(layout, edge.to);\n\t\tif (!from || !to) continue;\n\t\tdrawEdge(grid, from, to, row, useColor);\n\t}\n\n\tif (legendLines.length > 0) {\n\t\tlet legendRow = row + flowHeight + 1;\n\t\tfor (const line of legendLines) {\n\t\t\twriteText(grid, 0, legendRow, line.text, useColor ? line.color : null);\n\t\t\tlegendRow++;\n\t\t}\n\t}\n\n\treturn grid;\n}\n\ninterface TextLine {\n\ttext: string;\n\tcolor: string | null;\n}\n\nfunction buildTitle(workflow: Workflow, showDescription: boolean): TextLine[] {\n\tconst lines: TextLine[] = [];\n\tconst title = `${workflow.cli} · ${workflow.name}`;\n\tlines.push({ text: title, color: COLOR.title });\n\tif (showDescription && workflow.description) {\n\t\tlines.push({ text: workflow.description, color: COLOR.description });\n\t}\n\tlines.push({ text: \"\", color: null });\n\treturn lines;\n}\n\nfunction buildLegend(workflow: Workflow): TextLine[] {\n\tconst hasOptional = workflow.nodes.some(n => n.optional);\n\tif (!hasOptional) return [];\n\treturn [\n\t\t{ text: \" ─── required ┈┈┈ optional\", color: COLOR.description },\n\t];\n}\n\nfunction maxLineLength(lines: TextLine[]): number {\n\treturn lines.reduce((max, l) => Math.max(max, l.text.length), 0);\n}\n\nfunction drawBox(grid: Grid, node: LayoutNode, rowOffset: number, useColor: boolean): void {\n\tconst y = rowOffset;\n\tconst x = node.x;\n\tconst w = node.width;\n\tconst label = node.node.label ?? node.node.id;\n\tconst isOptional = node.node.optional;\n\tconst labelColor = useColor ? (isOptional ? COLOR.optional : COLOR.label) : null;\n\tconst frameColor = useColor ? COLOR.boxFrame : null;\n\n\tconst horizChar = isOptional ? \"┈\" : BOX.horiz;\n\tconst vertChar = isOptional ? \"┊\" : BOX.vert;\n\tconst tlChar = isOptional ? \"┌\" : BOX.topLeft;\n\tconst trChar = isOptional ? \"┐\" : BOX.topRight;\n\tconst blChar = isOptional ? \"└\" : BOX.botLeft;\n\tconst brChar = isOptional ? \"┘\" : BOX.botRight;\n\n\twriteText(grid, x, y, tlChar, frameColor);\n\tfor (let i = 1; i < w - 1; i++) {\n\t\twriteText(grid, x + i, y, horizChar, frameColor);\n\t}\n\twriteText(grid, x + w - 1, y, trChar, frameColor);\n\n\twriteText(grid, x, y + 1, vertChar, frameColor);\n\tconst labelStart = x + Math.floor((w - label.length) / 2);\n\twriteText(grid, labelStart, y + 1, label, labelColor);\n\twriteText(grid, x + w - 1, y + 1, vertChar, frameColor);\n\n\twriteText(grid, x, y + 2, blChar, frameColor);\n\tfor (let i = 1; i < w - 1; i++) {\n\t\twriteText(grid, x + i, y + 2, horizChar, frameColor);\n\t}\n\twriteText(grid, x + w - 1, y + 2, brChar, frameColor);\n}\n\nfunction drawEdge(grid: Grid, from: LayoutNode, to: LayoutNode, rowOffset: number, useColor: boolean): void {\n\tconst color = useColor ? COLOR.arrow : null;\n\n\tconst fromCenterX = from.x + Math.floor(from.width / 2);\n\tconst toCenterX = to.x + Math.floor(to.width / 2);\n\tconst fromBottomY = rowOffset + from.y + from.height - 1;\n\tconst toTopY = rowOffset + to.y;\n\n\tif (to.row > from.row) {\n\t\tif (fromCenterX === toCenterX) {\n\t\t\tfor (let y = fromBottomY + 1; y < toTopY - 1; y++) {\n\t\t\t\twriteText(grid, fromCenterX, y, BOX.vert, color);\n\t\t\t}\n\t\t\twriteText(grid, fromCenterX, toTopY - 1, BOX.arrowDown, color);\n\t\t} else {\n\t\t\tconst midY = fromBottomY + 1;\n\t\t\twriteText(grid, fromCenterX, midY, BOX.vert, color);\n\n\t\t\tconst bendY = midY + 1;\n\t\t\tconst startX = Math.min(fromCenterX, toCenterX);\n\t\t\tconst endX = Math.max(fromCenterX, toCenterX);\n\t\t\tfor (let x = startX + 1; x < endX; x++) {\n\t\t\t\twriteText(grid, x, bendY, BOX.horiz, color);\n\t\t\t}\n\n\t\t\tif (fromCenterX < toCenterX) {\n\t\t\t\twriteText(grid, fromCenterX, bendY, \"└\", color);\n\t\t\t\twriteText(grid, toCenterX, bendY, \"┐\", color);\n\t\t\t} else {\n\t\t\t\twriteText(grid, fromCenterX, bendY, \"┘\", color);\n\t\t\t\twriteText(grid, toCenterX, bendY, \"┌\", color);\n\t\t\t}\n\n\t\t\tfor (let y = bendY + 1; y < toTopY - 1; y++) {\n\t\t\t\twriteText(grid, toCenterX, y, BOX.vert, color);\n\t\t\t}\n\t\t\twriteText(grid, toCenterX, toTopY - 1, BOX.arrowDown, color);\n\t\t}\n\t} else if (to.row === from.row) {\n\t\tconst y = rowOffset + from.y + Math.floor(from.height / 2);\n\t\tconst startX = from.x + from.width;\n\t\tconst endX = to.x;\n\t\tfor (let x = startX; x < endX - 1; x++) {\n\t\t\twriteText(grid, x, y, BOX.horiz, color);\n\t\t}\n\t\twriteText(grid, endX - 1, y, BOX.arrowRight, color);\n\t}\n}\n",
|
|
10
|
+
"import { encodeAnsi } from \"../encoders/ansi\";\nimport { encodeString } from \"../encoders/string\";\nimport { encodeHtml } from \"../encoders/html\";\nimport { renderFlow } from \"./render\";\nimport type { Workflow, FlowRenderOptions } from \"./types\";\n\nexport function flowToAnsi(workflow: Workflow, opts?: FlowRenderOptions): string {\n\treturn encodeAnsi(renderFlow(workflow, opts));\n}\n\nexport function flowToString(workflow: Workflow, opts?: FlowRenderOptions): string {\n\treturn encodeString(renderFlow(workflow, opts));\n}\n\nexport function flowToHtml(workflow: Workflow, opts?: FlowRenderOptions): string {\n\treturn encodeHtml(renderFlow(workflow, opts));\n}\n\nexport function printFlow(workflow: Workflow, opts?: FlowRenderOptions): void {\n\tconsole.log(flowToAnsi(workflow, opts));\n}\n"
|
|
11
|
+
],
|
|
12
|
+
"mappings": ";;;;;;;;;AAEO,SAAS,SAAS,CAAC,MAAyB;AAAA,EAClD,MAAM,QAAQ,KAAK,MAAM;AAAA,CAAI;AAAA,EAC7B,MAAM,UAAkE,CAAC;AAAA,EAEzE,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AAAA;",
|
|
13
|
+
"debugId": "C94663974D261F8E64756E2164756E21",
|
|
14
|
+
"names": []
|
|
15
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var ANSI_COLORS = {
|
|
3
|
+
red: "\x1B[31m",
|
|
4
|
+
green: "\x1B[32m",
|
|
5
|
+
yellow: "\x1B[33m",
|
|
6
|
+
blue: "\x1B[34m",
|
|
7
|
+
magenta: "\x1B[35m",
|
|
8
|
+
cyan: "\x1B[36m",
|
|
9
|
+
white: "\x1B[37m",
|
|
10
|
+
gray: "\x1B[90m"
|
|
11
|
+
};
|
|
12
|
+
var ANSI_RESET = "\x1B[0m";
|
|
13
|
+
|
|
14
|
+
// src/encoders/ansi.ts
|
|
15
|
+
function encodeAnsi(grid) {
|
|
16
|
+
const lines = [];
|
|
17
|
+
for (let y = 0;y < grid.height; y++) {
|
|
18
|
+
let line = "";
|
|
19
|
+
let currentFg = null;
|
|
20
|
+
for (let x = 0;x < grid.width; x++) {
|
|
21
|
+
const cell = grid.get(x, y);
|
|
22
|
+
if (!cell)
|
|
23
|
+
continue;
|
|
24
|
+
if (cell.fg !== currentFg) {
|
|
25
|
+
if (currentFg !== null)
|
|
26
|
+
line += ANSI_RESET;
|
|
27
|
+
if (cell.fg !== null)
|
|
28
|
+
line += ANSI_COLORS[cell.fg] ?? "";
|
|
29
|
+
currentFg = cell.fg;
|
|
30
|
+
}
|
|
31
|
+
line += cell.char;
|
|
32
|
+
}
|
|
33
|
+
if (currentFg !== null)
|
|
34
|
+
line += ANSI_RESET;
|
|
35
|
+
lines.push(line.trimEnd());
|
|
36
|
+
}
|
|
37
|
+
while (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
38
|
+
lines.pop();
|
|
39
|
+
}
|
|
40
|
+
return lines.join(`
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/encoders/string.ts
|
|
45
|
+
function encodeString(grid) {
|
|
46
|
+
const lines = [];
|
|
47
|
+
for (let y = 0;y < grid.height; y++) {
|
|
48
|
+
let line = "";
|
|
49
|
+
for (let x = 0;x < grid.width; x++) {
|
|
50
|
+
const cell = grid.get(x, y);
|
|
51
|
+
line += cell?.char ?? " ";
|
|
52
|
+
}
|
|
53
|
+
lines.push(line.trimEnd());
|
|
54
|
+
}
|
|
55
|
+
while (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
56
|
+
lines.pop();
|
|
57
|
+
}
|
|
58
|
+
return lines.join(`
|
|
59
|
+
`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/encoders/html.ts
|
|
63
|
+
var COLOR_TO_CSS = {
|
|
64
|
+
red: "#ef4444",
|
|
65
|
+
green: "#22c55e",
|
|
66
|
+
yellow: "#eab308",
|
|
67
|
+
blue: "#3b82f6",
|
|
68
|
+
magenta: "#d946ef",
|
|
69
|
+
cyan: "#06b6d4",
|
|
70
|
+
white: "#e8e0d4",
|
|
71
|
+
gray: "#6b7c72"
|
|
72
|
+
};
|
|
73
|
+
function encodeHtml(grid, opts = {}) {
|
|
74
|
+
const wrap = opts.wrap ?? true;
|
|
75
|
+
const lines = [];
|
|
76
|
+
for (let y = 0;y < grid.height; y++) {
|
|
77
|
+
let line = "";
|
|
78
|
+
let currentFg = null;
|
|
79
|
+
for (let x = 0;x < grid.width; x++) {
|
|
80
|
+
const cell = grid.get(x, y);
|
|
81
|
+
if (!cell)
|
|
82
|
+
continue;
|
|
83
|
+
if (cell.fg !== currentFg) {
|
|
84
|
+
if (currentFg !== null)
|
|
85
|
+
line += "</span>";
|
|
86
|
+
if (cell.fg !== null) {
|
|
87
|
+
const css = COLOR_TO_CSS[cell.fg] ?? cell.fg;
|
|
88
|
+
line += `<span style="color:${css}">`;
|
|
89
|
+
}
|
|
90
|
+
currentFg = cell.fg;
|
|
91
|
+
}
|
|
92
|
+
const ch = cell.char;
|
|
93
|
+
if (ch === "<")
|
|
94
|
+
line += "<";
|
|
95
|
+
else if (ch === ">")
|
|
96
|
+
line += ">";
|
|
97
|
+
else if (ch === "&")
|
|
98
|
+
line += "&";
|
|
99
|
+
else
|
|
100
|
+
line += ch;
|
|
101
|
+
}
|
|
102
|
+
if (currentFg !== null)
|
|
103
|
+
line += "</span>";
|
|
104
|
+
lines.push(line);
|
|
105
|
+
}
|
|
106
|
+
const body = lines.join(`
|
|
107
|
+
`);
|
|
108
|
+
if (!wrap)
|
|
109
|
+
return body;
|
|
110
|
+
const bg = opts.background ?? "#0a0a0a";
|
|
111
|
+
const fg = opts.foreground ?? "#e8e0d4";
|
|
112
|
+
const font = opts.fontFamily ?? '"JetBrains Mono", "Fira Code", "SF Mono", Menlo, Monaco, Consolas, monospace';
|
|
113
|
+
const size = opts.fontSize ?? "14px";
|
|
114
|
+
const pad = opts.padding ?? "24px";
|
|
115
|
+
const style = [
|
|
116
|
+
`background: ${bg}`,
|
|
117
|
+
`color: ${fg}`,
|
|
118
|
+
`font-family: ${font}`,
|
|
119
|
+
`font-size: ${size}`,
|
|
120
|
+
`line-height: 1.3`,
|
|
121
|
+
`padding: ${pad}`,
|
|
122
|
+
`margin: 0`,
|
|
123
|
+
`white-space: pre`,
|
|
124
|
+
`overflow-x: auto`,
|
|
125
|
+
`border-radius: 8px`
|
|
126
|
+
].join("; ");
|
|
127
|
+
return `<pre style="${style}">${body}</pre>`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/grid.ts
|
|
131
|
+
function createGrid(width) {
|
|
132
|
+
const cells = [];
|
|
133
|
+
return {
|
|
134
|
+
get width() {
|
|
135
|
+
return width;
|
|
136
|
+
},
|
|
137
|
+
get height() {
|
|
138
|
+
return cells.length;
|
|
139
|
+
},
|
|
140
|
+
cells,
|
|
141
|
+
set(x, y, char, fg) {
|
|
142
|
+
while (y >= cells.length) {
|
|
143
|
+
const row = [];
|
|
144
|
+
for (let i = 0;i < width; i++) {
|
|
145
|
+
row.push({ char: " ", fg: null });
|
|
146
|
+
}
|
|
147
|
+
cells.push(row);
|
|
148
|
+
}
|
|
149
|
+
if (x < 0 || x >= width)
|
|
150
|
+
return;
|
|
151
|
+
const cell = cells[y]?.[x];
|
|
152
|
+
if (!cell)
|
|
153
|
+
return;
|
|
154
|
+
cell.char = char;
|
|
155
|
+
if (fg !== undefined)
|
|
156
|
+
cell.fg = fg ?? null;
|
|
157
|
+
},
|
|
158
|
+
get(x, y) {
|
|
159
|
+
return cells[y]?.[x];
|
|
160
|
+
},
|
|
161
|
+
addRow() {
|
|
162
|
+
const row = [];
|
|
163
|
+
for (let i = 0;i < width; i++) {
|
|
164
|
+
row.push({ char: " ", fg: null });
|
|
165
|
+
}
|
|
166
|
+
cells.push(row);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function writeText(grid, x, y, text, fg) {
|
|
171
|
+
for (let i = 0;i < text.length; i++) {
|
|
172
|
+
if (x + i >= grid.width)
|
|
173
|
+
break;
|
|
174
|
+
grid.set(x + i, y, text[i], fg);
|
|
175
|
+
}
|
|
176
|
+
return x + text.length;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { createGrid, writeText, encodeAnsi, encodeString, encodeHtml };
|
|
180
|
+
|
|
181
|
+
//# debugId=EA07EBA81FE8B86664756E2164756E21
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/types.ts", "../src/encoders/ansi.ts", "../src/encoders/string.ts", "../src/encoders/html.ts", "../src/grid.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"export type AnsiColor =\n\t| \"red\"\n\t| \"green\"\n\t| \"yellow\"\n\t| \"blue\"\n\t| \"magenta\"\n\t| \"cyan\"\n\t| \"white\"\n\t| \"gray\";\n\nexport const ANSI_COLORS: Record<AnsiColor, string> = {\n\tred: \"\\x1b[31m\",\n\tgreen: \"\\x1b[32m\",\n\tyellow: \"\\x1b[33m\",\n\tblue: \"\\x1b[34m\",\n\tmagenta: \"\\x1b[35m\",\n\tcyan: \"\\x1b[36m\",\n\twhite: \"\\x1b[37m\",\n\tgray: \"\\x1b[90m\",\n};\n\nexport const ANSI_RESET = \"\\x1b[0m\";\nexport const ANSI_BOLD = \"\\x1b[1m\";\nexport const ANSI_DIM = \"\\x1b[2m\";\n\nexport interface CLINode {\n\tname: string;\n\tdescription?: string;\n\taliases?: string[];\n\tsubcommands?: CLINode[];\n\tflags?: Flag[];\n\targs?: Arg[];\n}\n\nexport interface Flag {\n\tname: string;\n\tshort?: string;\n\ttype: \"boolean\" | \"string\" | \"number\" | \"enum\";\n\tenum?: string[];\n\trequired?: boolean;\n\tdefault?: unknown;\n\tdescription?: string;\n}\n\nexport interface Arg {\n\tname: string;\n\trequired?: boolean;\n\tvariadic?: boolean;\n\tdescription?: string;\n}\n\nexport interface TreeOptions {\n\tcolor?: boolean;\n\tindent?: number;\n\tshowFlags?: boolean;\n\tshowArgs?: boolean;\n\tshowDescriptions?: boolean;\n\tshowTypes?: boolean;\n\tshowDefaults?: boolean;\n\tmaxDepth?: number;\n\tcompact?: boolean;\n}\n",
|
|
6
|
+
"import type { Grid } from \"../grid\";\nimport { ANSI_COLORS, ANSI_RESET, type AnsiColor } from \"../types\";\n\nexport function encodeAnsi(grid: Grid): string {\n\tconst lines: string[] = [];\n\n\tfor (let y = 0; y < grid.height; y++) {\n\t\tlet line = \"\";\n\t\tlet currentFg: string | null = null;\n\n\t\tfor (let x = 0; x < grid.width; x++) {\n\t\t\tconst cell = grid.get(x, y);\n\t\t\tif (!cell) continue;\n\n\t\t\tif (cell.fg !== currentFg) {\n\t\t\t\tif (currentFg !== null) line += ANSI_RESET;\n\t\t\t\tif (cell.fg !== null) line += ANSI_COLORS[cell.fg as AnsiColor] ?? \"\";\n\t\t\t\tcurrentFg = cell.fg;\n\t\t\t}\n\t\t\tline += cell.char;\n\t\t}\n\n\t\tif (currentFg !== null) line += ANSI_RESET;\n\t\tlines.push(line.trimEnd());\n\t}\n\n\twhile (lines.length > 0 && lines[lines.length - 1] === \"\") {\n\t\tlines.pop();\n\t}\n\n\treturn lines.join(\"\\n\");\n}\n",
|
|
7
|
+
"import type { Grid } from \"../grid\";\n\nexport function encodeString(grid: Grid): string {\n\tconst lines: string[] = [];\n\n\tfor (let y = 0; y < grid.height; y++) {\n\t\tlet line = \"\";\n\t\tfor (let x = 0; x < grid.width; x++) {\n\t\t\tconst cell = grid.get(x, y);\n\t\t\tline += cell?.char ?? \" \";\n\t\t}\n\t\tlines.push(line.trimEnd());\n\t}\n\n\twhile (lines.length > 0 && lines[lines.length - 1] === \"\") {\n\t\tlines.pop();\n\t}\n\n\treturn lines.join(\"\\n\");\n}\n",
|
|
8
|
+
"import type { Grid } from \"../grid\";\n\nconst COLOR_TO_CSS: Record<string, string> = {\n\tred: \"#ef4444\",\n\tgreen: \"#22c55e\",\n\tyellow: \"#eab308\",\n\tblue: \"#3b82f6\",\n\tmagenta: \"#d946ef\",\n\tcyan: \"#06b6d4\",\n\twhite: \"#e8e0d4\",\n\tgray: \"#6b7c72\",\n};\n\nexport interface HtmlEncodeOptions {\n\twrap?: boolean;\n\tbackground?: string;\n\tforeground?: string;\n\tfontFamily?: string;\n\tfontSize?: string;\n\tpadding?: string;\n}\n\nexport function encodeHtml(grid: Grid, opts: HtmlEncodeOptions = {}): string {\n\tconst wrap = opts.wrap ?? true;\n\tconst lines: string[] = [];\n\n\tfor (let y = 0; y < grid.height; y++) {\n\t\tlet line = \"\";\n\t\tlet currentFg: string | null = null;\n\n\t\tfor (let x = 0; x < grid.width; x++) {\n\t\t\tconst cell = grid.get(x, y);\n\t\t\tif (!cell) continue;\n\n\t\t\tif (cell.fg !== currentFg) {\n\t\t\t\tif (currentFg !== null) line += \"</span>\";\n\t\t\t\tif (cell.fg !== null) {\n\t\t\t\t\tconst css = COLOR_TO_CSS[cell.fg] ?? cell.fg;\n\t\t\t\t\tline += `<span style=\"color:${css}\">`;\n\t\t\t\t}\n\t\t\t\tcurrentFg = cell.fg;\n\t\t\t}\n\n\t\t\tconst ch = cell.char;\n\t\t\tif (ch === \"<\") line += \"<\";\n\t\t\telse if (ch === \">\") line += \">\";\n\t\t\telse if (ch === \"&\") line += \"&\";\n\t\t\telse line += ch;\n\t\t}\n\n\t\tif (currentFg !== null) line += \"</span>\";\n\t\tlines.push(line);\n\t}\n\n\tconst body = lines.join(\"\\n\");\n\tif (!wrap) return body;\n\n\tconst bg = opts.background ?? \"#0a0a0a\";\n\tconst fg = opts.foreground ?? \"#e8e0d4\";\n\tconst font = opts.fontFamily ?? '\"JetBrains Mono\", \"Fira Code\", \"SF Mono\", Menlo, Monaco, Consolas, monospace';\n\tconst size = opts.fontSize ?? \"14px\";\n\tconst pad = opts.padding ?? \"24px\";\n\n\tconst style = [\n\t\t`background: ${bg}`,\n\t\t`color: ${fg}`,\n\t\t`font-family: ${font}`,\n\t\t`font-size: ${size}`,\n\t\t`line-height: 1.3`,\n\t\t`padding: ${pad}`,\n\t\t`margin: 0`,\n\t\t`white-space: pre`,\n\t\t`overflow-x: auto`,\n\t\t`border-radius: 8px`,\n\t].join(\"; \");\n\n\treturn `<pre style=\"${style}\">${body}</pre>`;\n}\n",
|
|
9
|
+
"export interface Cell {\n\tchar: string;\n\tfg: string | null;\n}\n\nexport interface Grid {\n\twidth: number;\n\theight: number;\n\tcells: Cell[][];\n\tset(x: number, y: number, char: string, fg?: string | null): void;\n\tget(x: number, y: number): Cell | undefined;\n\taddRow(): void;\n}\n\nexport function createGrid(width: number): Grid {\n\tconst cells: Cell[][] = [];\n\n\treturn {\n\t\tget width() {\n\t\t\treturn width;\n\t\t},\n\t\tget height() {\n\t\t\treturn cells.length;\n\t\t},\n\t\tcells,\n\t\tset(x: number, y: number, char: string, fg?: string | null) {\n\t\t\twhile (y >= cells.length) {\n\t\t\t\tconst row: Cell[] = [];\n\t\t\t\tfor (let i = 0; i < width; i++) {\n\t\t\t\t\trow.push({ char: \" \", fg: null });\n\t\t\t\t}\n\t\t\t\tcells.push(row);\n\t\t\t}\n\t\t\tif (x < 0 || x >= width) return;\n\t\t\tconst cell = cells[y]?.[x];\n\t\t\tif (!cell) return;\n\t\t\tcell.char = char;\n\t\t\tif (fg !== undefined) cell.fg = fg ?? null;\n\t\t},\n\t\tget(x: number, y: number) {\n\t\t\treturn cells[y]?.[x];\n\t\t},\n\t\taddRow() {\n\t\t\tconst row: Cell[] = [];\n\t\t\tfor (let i = 0; i < width; i++) {\n\t\t\t\trow.push({ char: \" \", fg: null });\n\t\t\t}\n\t\t\tcells.push(row);\n\t\t},\n\t};\n}\n\nexport function writeText(grid: Grid, x: number, y: number, text: string, fg?: string | null): number {\n\tfor (let i = 0; i < text.length; i++) {\n\t\tif (x + i >= grid.width) break;\n\t\tgrid.set(x + i, y, text[i]!, fg);\n\t}\n\treturn x + text.length;\n}\n"
|
|
10
|
+
],
|
|
11
|
+
"mappings": ";AAUO,IAAM,cAAyC;AAAA,EACrD,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AACP;AAEO,IAAM,aAAa;;;AClBnB,SAAS,UAAU,CAAC,MAAoB;AAAA,EAC9C,MAAM,QAAkB,CAAC;AAAA,EAEzB,SAAS,IAAI,EAAG,IAAI,KAAK,QAAQ,KAAK;AAAA,IACrC,IAAI,OAAO;AAAA,IACX,IAAI,YAA2B;AAAA,IAE/B,SAAS,IAAI,EAAG,IAAI,KAAK,OAAO,KAAK;AAAA,MACpC,MAAM,OAAO,KAAK,IAAI,GAAG,CAAC;AAAA,MAC1B,IAAI,CAAC;AAAA,QAAM;AAAA,MAEX,IAAI,KAAK,OAAO,WAAW;AAAA,QAC1B,IAAI,cAAc;AAAA,UAAM,QAAQ;AAAA,QAChC,IAAI,KAAK,OAAO;AAAA,UAAM,QAAQ,YAAY,KAAK,OAAoB;AAAA,QACnE,YAAY,KAAK;AAAA,MAClB;AAAA,MACA,QAAQ,KAAK;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
import {
|
|
2
|
+
createGrid,
|
|
3
|
+
encodeAnsi,
|
|
4
|
+
encodeHtml,
|
|
5
|
+
encodeString,
|
|
6
|
+
writeText
|
|
7
|
+
} from "./chunk-q4se2rwe.js";
|
|
8
|
+
|
|
9
|
+
// src/render.ts
|
|
10
|
+
var BOX = {
|
|
11
|
+
pipe: "│",
|
|
12
|
+
tee: "├",
|
|
13
|
+
corner: "└",
|
|
14
|
+
dash: "──",
|
|
15
|
+
space: " "
|
|
16
|
+
};
|
|
17
|
+
function defaults(opts) {
|
|
18
|
+
return {
|
|
19
|
+
color: opts?.color ?? true,
|
|
20
|
+
indent: opts?.indent ?? 3,
|
|
21
|
+
showFlags: opts?.showFlags ?? true,
|
|
22
|
+
showArgs: opts?.showArgs ?? true,
|
|
23
|
+
showDescriptions: opts?.showDescriptions ?? true,
|
|
24
|
+
showTypes: opts?.showTypes ?? true,
|
|
25
|
+
showDefaults: opts?.showDefaults ?? true,
|
|
26
|
+
maxDepth: opts?.maxDepth ?? Infinity,
|
|
27
|
+
compact: opts?.compact ?? false
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function formatFlag(flag, opts) {
|
|
31
|
+
let text = `--${flag.name}`;
|
|
32
|
+
if (flag.short)
|
|
33
|
+
text = `-${flag.short}, ${text}`;
|
|
34
|
+
if (opts.showTypes && flag.type !== "boolean") {
|
|
35
|
+
if (flag.type === "enum" && flag.enum) {
|
|
36
|
+
text += ` <${flag.enum.join("|")}>`;
|
|
37
|
+
} else {
|
|
38
|
+
text += ` <${flag.type}>`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (flag.type === "boolean") {
|
|
42
|
+
text += " [boolean]";
|
|
43
|
+
}
|
|
44
|
+
if (opts.showDefaults && flag.default !== undefined) {
|
|
45
|
+
text += ` (default: ${JSON.stringify(flag.default)})`;
|
|
46
|
+
}
|
|
47
|
+
if (flag.required) {
|
|
48
|
+
text += " *";
|
|
49
|
+
}
|
|
50
|
+
return text;
|
|
51
|
+
}
|
|
52
|
+
function formatArg(arg) {
|
|
53
|
+
const name = arg.variadic ? `${arg.name}...` : arg.name;
|
|
54
|
+
return arg.required ? `<${name}>` : `[${name}]`;
|
|
55
|
+
}
|
|
56
|
+
function drawPrefix(state, col, pipes, isLast) {
|
|
57
|
+
const indent = state.opts.indent;
|
|
58
|
+
for (let i = 0;i < pipes.length; i++) {
|
|
59
|
+
const x2 = i * indent;
|
|
60
|
+
if (pipes[i]) {
|
|
61
|
+
writeText(state.grid, x2, state.row, BOX.pipe, state.opts.color ? "gray" : null);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const x = pipes.length * indent;
|
|
65
|
+
const connector = isLast ? BOX.corner : BOX.tee;
|
|
66
|
+
writeText(state.grid, x, state.row, connector + BOX.dash + " ", state.opts.color ? "gray" : null);
|
|
67
|
+
}
|
|
68
|
+
function renderNode(state, node, depth, pipes, isLast, isRoot) {
|
|
69
|
+
const indent = state.opts.indent;
|
|
70
|
+
if (isRoot) {
|
|
71
|
+
writeText(state.grid, 0, state.row, node.name, state.opts.color ? "cyan" : null);
|
|
72
|
+
if (node.description && state.opts.showDescriptions) {
|
|
73
|
+
const descCol = node.name.length + 1;
|
|
74
|
+
writeText(state.grid, descCol, state.row, `— ${node.description}`, state.opts.color ? "gray" : null);
|
|
75
|
+
}
|
|
76
|
+
state.row++;
|
|
77
|
+
} else {
|
|
78
|
+
drawPrefix(state, pipes.length * indent, pipes, isLast);
|
|
79
|
+
const textStart = pipes.length * indent + 4;
|
|
80
|
+
writeText(state.grid, textStart, state.row, node.name, state.opts.color ? "green" : null);
|
|
81
|
+
if (node.aliases && node.aliases.length > 0) {
|
|
82
|
+
const aliasStart = textStart + node.name.length;
|
|
83
|
+
const aliasText = ` (${node.aliases.join(", ")})`;
|
|
84
|
+
writeText(state.grid, aliasStart, state.row, aliasText, state.opts.color ? "gray" : null);
|
|
85
|
+
}
|
|
86
|
+
if (node.description && state.opts.showDescriptions && !state.opts.compact) {
|
|
87
|
+
const nameLen = node.name.length + (node.aliases ? ` (${node.aliases.join(", ")})`.length : 0);
|
|
88
|
+
const descCol = textStart + nameLen + 1;
|
|
89
|
+
writeText(state.grid, descCol, state.row, `— ${node.description}`, state.opts.color ? "gray" : null);
|
|
90
|
+
}
|
|
91
|
+
state.row++;
|
|
92
|
+
}
|
|
93
|
+
if (depth >= state.opts.maxDepth)
|
|
94
|
+
return;
|
|
95
|
+
const children = [];
|
|
96
|
+
if (state.opts.showArgs && node.args) {
|
|
97
|
+
for (const arg of node.args) {
|
|
98
|
+
children.push({ type: "arg", item: arg });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (state.opts.showFlags && node.flags) {
|
|
102
|
+
for (const flag of node.flags) {
|
|
103
|
+
children.push({ type: "flag", item: flag });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (node.subcommands) {
|
|
107
|
+
for (const cmd of node.subcommands) {
|
|
108
|
+
children.push({ type: "cmd", item: cmd });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (let i = 0;i < children.length; i++) {
|
|
112
|
+
const child = children[i];
|
|
113
|
+
const childIsLast = i === children.length - 1;
|
|
114
|
+
const nextPipes = isRoot ? [] : [...pipes, !isLast];
|
|
115
|
+
if (child.type === "flag") {
|
|
116
|
+
const flag = child.item;
|
|
117
|
+
drawPrefix(state, nextPipes.length * indent, nextPipes, childIsLast);
|
|
118
|
+
const textStart = nextPipes.length * indent + 4;
|
|
119
|
+
const flagText = formatFlag(flag, state.opts);
|
|
120
|
+
writeText(state.grid, textStart, state.row, flagText, state.opts.color ? "yellow" : null);
|
|
121
|
+
if (flag.description && state.opts.showDescriptions && !state.opts.compact) {
|
|
122
|
+
const descCol = textStart + flagText.length + 1;
|
|
123
|
+
writeText(state.grid, descCol, state.row, `— ${flag.description}`, state.opts.color ? "gray" : null);
|
|
124
|
+
}
|
|
125
|
+
state.row++;
|
|
126
|
+
} else if (child.type === "arg") {
|
|
127
|
+
const arg = child.item;
|
|
128
|
+
drawPrefix(state, nextPipes.length * indent, nextPipes, childIsLast);
|
|
129
|
+
const textStart = nextPipes.length * indent + 4;
|
|
130
|
+
const argText = formatArg(arg);
|
|
131
|
+
writeText(state.grid, textStart, state.row, argText, state.opts.color ? "magenta" : null);
|
|
132
|
+
if (arg.description && state.opts.showDescriptions && !state.opts.compact) {
|
|
133
|
+
const descCol = textStart + argText.length + 1;
|
|
134
|
+
writeText(state.grid, descCol, state.row, `— ${arg.description}`, state.opts.color ? "gray" : null);
|
|
135
|
+
}
|
|
136
|
+
state.row++;
|
|
137
|
+
} else {
|
|
138
|
+
const cmd = child.item;
|
|
139
|
+
renderNode(state, cmd, depth + 1, nextPipes, childIsLast, false);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function renderTree(root, opts) {
|
|
144
|
+
const resolved = defaults(opts);
|
|
145
|
+
const width = 120;
|
|
146
|
+
const grid = createGrid(width);
|
|
147
|
+
const state = { grid, row: 0, opts: resolved };
|
|
148
|
+
renderNode(state, root, 0, [], true, true);
|
|
149
|
+
return grid;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/index.ts
|
|
153
|
+
function treeToAnsi(root, opts) {
|
|
154
|
+
return encodeAnsi(renderTree(root, opts));
|
|
155
|
+
}
|
|
156
|
+
function treeToString(root, opts) {
|
|
157
|
+
return encodeString(renderTree(root, opts));
|
|
158
|
+
}
|
|
159
|
+
function treeToHtml(root, opts) {
|
|
160
|
+
return encodeHtml(renderTree(root, opts));
|
|
161
|
+
}
|
|
162
|
+
function printTree(root, opts) {
|
|
163
|
+
console.log(treeToAnsi(root, opts));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { treeToAnsi, treeToString, treeToHtml, printTree };
|
|
167
|
+
|
|
168
|
+
//# debugId=4971A73DDBEA82A564756E2164756E21
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/render.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { createGrid, writeText } from \"./grid\";\nimport type { Grid } from \"./grid\";\nimport type { CLINode, Flag, Arg, TreeOptions } from \"./types\";\n\nconst BOX = {\n\tpipe: \"│\",\n\ttee: \"├\",\n\tcorner: \"└\",\n\tdash: \"──\",\n\tspace: \" \",\n} as const;\n\ninterface RenderState {\n\tgrid: Grid;\n\trow: number;\n\topts: Required<TreeOptions>;\n}\n\nfunction defaults(opts?: TreeOptions): Required<TreeOptions> {\n\treturn {\n\t\tcolor: opts?.color ?? true,\n\t\tindent: opts?.indent ?? 3,\n\t\tshowFlags: opts?.showFlags ?? true,\n\t\tshowArgs: opts?.showArgs ?? true,\n\t\tshowDescriptions: opts?.showDescriptions ?? true,\n\t\tshowTypes: opts?.showTypes ?? true,\n\t\tshowDefaults: opts?.showDefaults ?? true,\n\t\tmaxDepth: opts?.maxDepth ?? Infinity,\n\t\tcompact: opts?.compact ?? false,\n\t};\n}\n\nfunction formatFlag(flag: Flag, opts: Required<TreeOptions>): string {\n\tlet text = `--${flag.name}`;\n\tif (flag.short) text = `-${flag.short}, ${text}`;\n\n\tif (opts.showTypes && flag.type !== \"boolean\") {\n\t\tif (flag.type === \"enum\" && flag.enum) {\n\t\t\ttext += ` <${flag.enum.join(\"|\")}>`;\n\t\t} else {\n\t\t\ttext += ` <${flag.type}>`;\n\t\t}\n\t}\n\n\tif (flag.type === \"boolean\") {\n\t\ttext += \" [boolean]\";\n\t}\n\n\tif (opts.showDefaults && flag.default !== undefined) {\n\t\ttext += ` (default: ${JSON.stringify(flag.default)})`;\n\t}\n\n\tif (flag.required) {\n\t\ttext += \" *\";\n\t}\n\n\treturn text;\n}\n\nfunction formatArg(arg: Arg): string {\n\tconst name = arg.variadic ? `${arg.name}...` : arg.name;\n\treturn arg.required ? `<${name}>` : `[${name}]`;\n}\n\nfunction drawPrefix(state: RenderState, col: number, pipes: boolean[], isLast: boolean) {\n\tconst indent = state.opts.indent;\n\tfor (let i = 0; i < pipes.length; i++) {\n\t\tconst x = i * indent;\n\t\tif (pipes[i]) {\n\t\t\twriteText(state.grid, x, state.row, BOX.pipe, state.opts.color ? \"gray\" : null);\n\t\t}\n\t}\n\n\tconst x = pipes.length * indent;\n\tconst connector = isLast ? BOX.corner : BOX.tee;\n\twriteText(state.grid, x, state.row, connector + BOX.dash + \" \", state.opts.color ? \"gray\" : null);\n}\n\nfunction renderNode(\n\tstate: RenderState,\n\tnode: CLINode,\n\tdepth: number,\n\tpipes: boolean[],\n\tisLast: boolean,\n\tisRoot: boolean,\n) {\n\tconst indent = state.opts.indent;\n\n\tif (isRoot) {\n\t\twriteText(state.grid, 0, state.row, node.name, state.opts.color ? \"cyan\" : null);\n\t\tif (node.description && state.opts.showDescriptions) {\n\t\t\tconst descCol = node.name.length + 1;\n\t\t\twriteText(state.grid, descCol, state.row, `— ${node.description}`, state.opts.color ? \"gray\" : null);\n\t\t}\n\t\tstate.row++;\n\t} else {\n\t\tdrawPrefix(state, pipes.length * indent, pipes, isLast);\n\t\tconst textStart = pipes.length * indent + 4;\n\t\twriteText(state.grid, textStart, state.row, node.name, state.opts.color ? \"green\" : null);\n\n\t\tif (node.aliases && node.aliases.length > 0) {\n\t\t\tconst aliasStart = textStart + node.name.length;\n\t\t\tconst aliasText = ` (${node.aliases.join(\", \")})`;\n\t\t\twriteText(state.grid, aliasStart, state.row, aliasText, state.opts.color ? \"gray\" : null);\n\t\t}\n\n\t\tif (node.description && state.opts.showDescriptions && !state.opts.compact) {\n\t\t\tconst nameLen = node.name.length + (node.aliases ? ` (${node.aliases.join(\", \")})`.length : 0);\n\t\t\tconst descCol = textStart + nameLen + 1;\n\t\t\twriteText(state.grid, descCol, state.row, `— ${node.description}`, state.opts.color ? \"gray\" : null);\n\t\t}\n\t\tstate.row++;\n\t}\n\n\tif (depth >= state.opts.maxDepth) return;\n\n\tconst children: { type: \"flag\" | \"arg\" | \"cmd\"; item: Flag | Arg | CLINode }[] = [];\n\n\tif (state.opts.showArgs && node.args) {\n\t\tfor (const arg of node.args) {\n\t\t\tchildren.push({ type: \"arg\", item: arg });\n\t\t}\n\t}\n\n\tif (state.opts.showFlags && node.flags) {\n\t\tfor (const flag of node.flags) {\n\t\t\tchildren.push({ type: \"flag\", item: flag });\n\t\t}\n\t}\n\n\tif (node.subcommands) {\n\t\tfor (const cmd of node.subcommands) {\n\t\t\tchildren.push({ type: \"cmd\", item: cmd });\n\t\t}\n\t}\n\n\tfor (let i = 0; i < children.length; i++) {\n\t\tconst child = children[i]!;\n\t\tconst childIsLast = i === children.length - 1;\n\t\tconst nextPipes = isRoot ? [] : [...pipes, !isLast];\n\n\t\tif (child.type === \"flag\") {\n\t\t\tconst flag = child.item as Flag;\n\t\t\tdrawPrefix(state, (nextPipes.length) * indent, nextPipes, childIsLast);\n\t\t\tconst textStart = nextPipes.length * indent + 4;\n\t\t\tconst flagText = formatFlag(flag, state.opts);\n\t\t\twriteText(state.grid, textStart, state.row, flagText, state.opts.color ? \"yellow\" : null);\n\n\t\t\tif (flag.description && state.opts.showDescriptions && !state.opts.compact) {\n\t\t\t\tconst descCol = textStart + flagText.length + 1;\n\t\t\t\twriteText(state.grid, descCol, state.row, `— ${flag.description}`, state.opts.color ? \"gray\" : null);\n\t\t\t}\n\t\t\tstate.row++;\n\t\t} else if (child.type === \"arg\") {\n\t\t\tconst arg = child.item as Arg;\n\t\t\tdrawPrefix(state, (nextPipes.length) * indent, nextPipes, childIsLast);\n\t\t\tconst textStart = nextPipes.length * indent + 4;\n\t\t\tconst argText = formatArg(arg);\n\t\t\twriteText(state.grid, textStart, state.row, argText, state.opts.color ? \"magenta\" : null);\n\n\t\t\tif (arg.description && state.opts.showDescriptions && !state.opts.compact) {\n\t\t\t\tconst descCol = textStart + argText.length + 1;\n\t\t\t\twriteText(state.grid, descCol, state.row, `— ${arg.description}`, state.opts.color ? \"gray\" : null);\n\t\t\t}\n\t\t\tstate.row++;\n\t\t} else {\n\t\t\tconst cmd = child.item as CLINode;\n\t\t\trenderNode(state, cmd, depth + 1, nextPipes, childIsLast, false);\n\t\t}\n\t}\n}\n\nexport function renderTree(root: CLINode, opts?: TreeOptions): Grid {\n\tconst resolved = defaults(opts);\n\tconst width = 120;\n\tconst grid = createGrid(width);\n\tconst state: RenderState = { grid, row: 0, opts: resolved };\n\n\trenderNode(state, root, 0, [], true, true);\n\n\treturn grid;\n}\n",
|
|
6
|
+
"import { renderTree } from \"./render\";\nimport { encodeAnsi } from \"./encoders/ansi\";\nimport { encodeString } from \"./encoders/string\";\nimport { encodeHtml } from \"./encoders/html\";\nimport type { CLINode, Flag, Arg, TreeOptions, AnsiColor } from \"./types\";\n\nexport type { CLINode, Flag, Arg, TreeOptions, AnsiColor };\nexport { parseHelp, parseHelpRecursive } from \"./parse\";\n\nexport function treeToAnsi(root: CLINode, opts?: TreeOptions): string {\n\treturn encodeAnsi(renderTree(root, opts));\n}\n\nexport function treeToString(root: CLINode, opts?: TreeOptions): string {\n\treturn encodeString(renderTree(root, opts));\n}\n\nexport function treeToHtml(root: CLINode, opts?: TreeOptions): string {\n\treturn encodeHtml(renderTree(root, opts));\n}\n\nexport function printTree(root: CLINode, opts?: TreeOptions): void {\n\tconsole.log(treeToAnsi(root, opts));\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";;;;;;;;;AAIA,IAAM,MAAM;AAAA,EACX,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AACR;AAQA,SAAS,QAAQ,CAAC,MAA2C;AAAA,EAC5D,OAAO;AAAA,IACN,OAAO,MAAM,SAAS;AAAA,IACtB,QAAQ,MAAM,UAAU;AAAA,IACxB,WAAW,MAAM,aAAa;AAAA,IAC9B,UAAU,MAAM,YAAY;AAAA,IAC5B,kBAAkB,MAAM,oBAAoB;AAAA,IAC5C,WAAW,MAAM,aAAa;AAAA,IAC9B,cAAc,MAAM,gBAAgB;AAAA,IAC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