#!/usr/bin/env node
import {a,d,e,f,g,b}from'./chunk-BFD3GFRK.js';import'./chunk-5TAVYPOV.js';import n from'chalk';import*as t from'fs';import*as o from'path';import {fileURLToPath}from'url';async function C(c){let s=process.cwd(),e=parseInt(c.port||"3850",10),p=c.open!==false;console.log(n.cyan(`
  Starting Paradigm Docs...
`));try{let{startPlatformServer:i}=await import('./platform-server-G6MJIAJS.js');await i({projectDir:s,port:e,open:p,sections:["overview","docs"]}),console.log(n.green(`  Docs running at ${n.bold(`http://localhost:${e}`)}`)),console.log(n.gray(`  Press Ctrl+C to stop
`)),await new Promise(()=>{});}catch(i){i.code==="EADDRINUSE"?(console.error(n.red(`
  Error: Port ${e} is already in use.`)),console.log(n.gray(`  Try: paradigm docs serve --port ${e+1}
`))):console.error(n.red(`
  Failed to start Paradigm Docs:`),i),process.exit(1);}}var k=fileURLToPath(import.meta.url),v=o.dirname(k);async function F(c){let s=process.cwd();for(;s!=="/"&&!t.existsSync(o.join(s,".paradigm"));)s=o.dirname(s);s==="/"&&(console.error(n.red("  Not in a Paradigm project (no .paradigm/ directory found)")),process.exit(1));let e$1=a(s),p=c.output||e$1.output||".paradigm/docs-site",i=o.resolve(s,p),r=o.join(i,"_data");console.log(n.cyan(`
  Building docs to ${n.white(i)}...
`)),t.mkdirSync(o.join(r,"symbols"),{recursive:true}),t.mkdirSync(o.join(r,"flows"),{recursive:true}),t.mkdirSync(o.join(r,"pages"),{recursive:true});let u=d(s,e$1);t.writeFileSync(o.join(r,"manifest.json"),JSON.stringify(u,null,2),"utf8"),console.log(n.gray(`  manifest.json (${u.totalSymbols} symbols)`));let g$1=0;for(let f$1 of u.groups){let h=[...f$1.items];if(f$1.subgroups)for(let a of f$1.subgroups)h.push(...a.items);for(let a of h)if(["component","signal","aspect","gate"].includes(a.kind)){let d=e(s,a.id);d&&(t.writeFileSync(o.join(r,"symbols",`${a.id}.json`),JSON.stringify(d,null,2),"utf8"),g$1++);}else if(a.kind==="flow"){let d=f(s,a.id);d&&t.writeFileSync(o.join(r,"flows",`${a.id}.json`),JSON.stringify(d,null,2),"utf8");}}let $=g(s);t.writeFileSync(o.join(r,"portal.json"),JSON.stringify($,null,2),"utf8");let y=b(s,e$1.customContent);for(let f of y)t.writeFileSync(o.join(r,"pages",`${f.slug}.json`),JSON.stringify(f,null,2),"utf8");let m=o.join(v,"..","..","platform-ui","dist");t.existsSync(m)||(m=o.join(v,"..","..","..","platform-ui","dist")),t.existsSync(m)&&(x(m,i),console.log(n.gray("  Copied SPA shell"))),console.log(n.gray(`  ${g$1} symbol pages`)),console.log(n.gray(`  ${y.length} custom pages`)),console.log(n.gray("  portal.json")),console.log(n.green(`
  Docs built to ${i}
`));}function x(c,s){t.mkdirSync(s,{recursive:true});for(let e of t.readdirSync(c,{withFileTypes:true})){let p=o.join(c,e.name),i=o.join(s,e.name);e.isDirectory()?e.name!=="_data"&&x(p,i):t.copyFileSync(p,i);}}export{F as docsBuildCommand,C as docsServeCommand};