@vercel/geistdocs 1.3.0-canary.41d37f1 → 1.3.0-canary.88e35b7

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/dist/cli/index.js CHANGED
@@ -1,3 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import{program as T}from"commander";import{access as pe,copyFile as ge,rm as de}from"fs/promises";import{join as G}from"path";import{cancel as ue,intro as fe,isCancel as me,log as he,outro as we,spinner as ye,text as Pe}from"@clack/prompts";import{exec as se}from"child_process";import{readFileSync as ne}from"fs";import{cp as re,readFile as ae,rename as ie,writeFile as oe}from"fs/promises";import{join as x}from"path";import{fileURLToPath as ce}from"url";import{promisify as le}from"util";var f="@vercel/geistdocs",m=(e,t)=>le(se)(e,t),_=["dependencies","devDependencies","optionalDependencies","peerDependencies"],b=()=>JSON.parse(ne(new URL("../../package.json",import.meta.url),"utf8")).version,P=async e=>{let t=x(e,"package.json"),s=await ae(t,"utf8");return JSON.parse(s)},F=async(e,t)=>{let s=x(e,"package.json");await oe(s,`${JSON.stringify(t,null,2)}
3
- `,"utf8")},E=(e,t)=>{for(let s of _){let n=e[s];if(n&&t in n)return n[t]}},V=(e,t)=>!!E(e,t),$=(e,t,s)=>{let n=!1;for(let r of _){let a=e[r];a&&t in a&&(a[t]=s,n=!0)}return n},j=()=>ce(new URL("../../template",import.meta.url)),D=async e=>{await re(j(),e,{recursive:!0});let t=x(e,".gitignore"),s=x(e,"_gitignore");try{await ie(s,t)}catch{}};var ve=async e=>{await D(e)},Te=async e=>{try{return await pe(e),!0}catch{return!1}},ke=async()=>{await Te(".env.example")&&await ge(".env.example",".env.local")},xe=async()=>{await de(G("content","docs"),{recursive:!0,force:!0})},be=async e=>{let t=await P(e),s=b();return $(t,f,s)?(await F(e,t),!0):!1},Fe=async e=>{await m("pnpm install",{cwd:e,env:process.env,stdio:"inherit"})},$e=async e=>{await m("git init",{cwd:e,env:process.env,stdio:"inherit"}),await m("git add .",{cwd:e,env:process.env,stdio:"inherit"}),await m('git commit -m "\u2728 Initial commit"',{cwd:e,env:process.env,stdio:"inherit"})},De=async()=>{let e=await Pe({message:"What is your project named?",placeholder:"my-app",validate(t){if(t.length===0)return"Please enter a project name."}});return me(e)&&(ue("Operation cancelled."),process.exit(0)),e.toString()},B=async e=>{try{fe("Let's start a Geistdocs project!");let t=process.cwd(),s=e.name||await De(),n=ye(),r=G(t,s);n.start("Copying bundled template..."),await ve(s),n.message("Setting up environment variables..."),process.chdir(r),await ke(),n.message("Deleting demo content..."),await xe(),n.message("Rewriting package dependency versions..."),await be(r),n.message("Installing dependencies..."),await Fe(r),e.disableGit||(n.message("Initializing Git repository..."),await $e(r)),n.stop("Project initialized successfully!"),we("Run `pnpm dev` to start the development server.")}catch(t){let s=t instanceof Error?t.message:`Failed to initialize project: ${t}`;he.error(s),process.exit(1)}};import{readFileSync as Se,writeFileSync as Ce}from"fs";import{mkdir as Re,readFile as J,writeFile as Ee}from"fs/promises";import{dirname as je,extname as Ne,relative as K,resolve as C}from"path";import{intro as Je,isCancel as Ue,log as h,multiselect as Ie,outro as S,spinner as Oe}from"@clack/prompts";import{glob as Le}from"glob";import{Node as v,Project as Ae,SyntaxKind as _e}from"ts-morph";var Ve="geistdocs.tsx",Ge="content/docs/**/*.mdx",U=".translation-cache.json",N=8,z=()=>({version:1,entries:{}}),Be=async e=>{let t=await J(e),{createHash:s}=await import("crypto");return s("sha256").update(t).digest("hex")},ze=e=>{let t=C(process.cwd(),e);return Se(t,"utf8")},H=e=>v.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(v.isPropertyAssignment(t)){let s=t.getNameNode();if(v.isIdentifier(s)||v.isStringLiteral(s))return[s.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],He=e=>{try{let t=new Ae({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),s=ze(e),a=t.createSourceFile(e,s,{overwrite:!0}).getVariableDeclarations().find(l=>l.getName()==="translations")?.getInitializer();if(!a)return[];if(v.isObjectLiteralExpression(a))return H(a);let o=a.getFirstDescendantByKind(_e.ObjectLiteralExpression);return o?H(o):[]}catch(t){let s=t instanceof Error?t.message:`${t}`;return h.warn(`Failed to read locales from ${e}: ${s}`),[]}},Me=async()=>{let e=await Ie({message:"Which locales should be translated?",options:[{value:"cn",label:"Chinese (cn)"},{value:"jp",label:"Japanese (jp)"},{value:"es",label:"Spanish (es)"},{value:"fr",label:"French (fr)"},{value:"de",label:"German (de)"}],required:!0});return Ue(e)&&(S("Translation cancelled"),process.exit(0)),e},Ke=async e=>(await Le(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),qe=async()=>{let e=C(process.cwd(),U);try{let t=await J(e,"utf8"),s=JSON.parse(t);return s.version!==1||!s.entries?z():{version:1,entries:s.entries}}catch{return z()}},M=e=>{let t=C(process.cwd(),U),s=JSON.stringify(e,null,2);Ce(t,s,"utf8")},Xe=async e=>{let t=await Promise.all(e.map(async s=>[s,await Be(s)]));return Object.fromEntries(t)},We=(e,t)=>{let s=Ne(e);return`${e.slice(0,-s.length)}.${t}${s}`},q=(e,t)=>`${K(process.cwd(),e)}::${t}`,Ye=(e,t,s,n,r=!1)=>{let a=[],o=0;for(let l of t){let c=s[l];for(let i of e){let g=We(l,i),d=q(l,i),u=n.entries[d];if(!r&&u?.hash===c){o+=1;continue}a.push({locale:i,sourceFile:l,sourceHash:c,targetFile:g})}}return{tasks:a,skippedCount:o}},Ze=async e=>{await Re(je(e),{recursive:!0})},Qe=async(e,t,s)=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:s})});if(!n.ok){let a=await n.text();throw new Error(`API request failed (${n.status}): ${a}`)}let r=await n.json();if(!r.translation)throw new Error("API response did not include a translation");return r.translation},et=async(e,t,s)=>{let n=await J(e.sourceFile,"utf8"),r=await Qe(t,n,e.locale);await Ze(e.targetFile),await Ee(e.targetFile,r,"utf8"),s.entries[q(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},X=async(e,t)=>{Je("Translate MDX content");let s=e??Ge,n=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",r=He(t.config??Ve),a=await Ke(s);a.length===0&&(h.error(`No MDX files found matching pattern: ${s}`),S("Translation cancelled"),process.exit(1)),h.info(`Found ${a.length} MDX file(s) matching pattern`),r.length===0&&(r=await Me());let o=C(process.cwd(),U),l=await qe();await M(l),h.info(`Using cache: ${o}`);let c=await Xe(a),{tasks:i,skippedCount:g}=Ye(r,a,c,l,t.force);if(i.length===0){h.success("All translations are up to date!"),S(`Skipped ${g} file(s) (unchanged)`);return}let d=[];for(let y=0;y<i.length;y+=N)d.push(i.slice(y,y+N));h.info(`Processing ${i.length} translation(s) in ${d.length} batch(es) of up to ${N}`),g>0&&h.info(`Skipped ${g} translation(s) (unchanged)`);let u=Oe();u.start("Translating content...");let k=0;for(let y of d)await Promise.all(y.map(async A=>{await et(A,n,l),k+=1,u.message(`Translated ${k}/${i.length}: ${K(process.cwd(),A.targetFile)}`)})),await M(l);u.stop("Translation complete!"),S(`Created/updated ${i.length} file(s)`)};import{access as tt,copyFile as st,mkdir as Q,rm as L}from"fs/promises";import{dirname as nt,join as w}from"path";import{intro as rt,log as p,outro as R,spinner as ee}from"@clack/prompts";import{glob as at}from"glob";var it=["**/*"],ot=["content/docs/**"],I=".geistdocs-tmp",ct=async(e,t)=>{let s=w(e,t);await L(s,{recursive:!0,force:!0}),await Q(s,{recursive:!0})},O=async e=>await L(e,{recursive:!0,force:!0}),W=async(e,t,s)=>(await at(e,{cwd:s,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),lt=async e=>{try{return await tt(e),!0}catch{return!1}},pt=async(e,t,s)=>{let n=w(t,e),r=w(s,e);return await lt(n)?(await st(n,r),{success:!0}):{success:!1,error:`Source file not found: ${n}`}},gt=async(e,t)=>{let s=w(t,e);return await L(s,{force:!0}),{success:!0}},Y=20,Z=async(e,t,s)=>{let n=[];for(let r=0;r<e.length;r+=s){let a=e.slice(r,r+s),o=await Promise.all(a.map(t));n.push(...o)}return n},dt=async(e,t,s,n,r)=>{let a={success:[],deleted:[],failed:[]},o=[...new Set(e.map(c=>nt(w(n,c))))];r.message(`Creating ${o.length} directories...`),await Promise.all(o.map(c=>Q(c,{recursive:!0}))),r.message(`Updating ${e.length} files...`);let l=await Z(e,async c=>{let i=await pt(c,s,n);return{file:c,...i}},Y);for(let{file:c,success:i,error:g}of l)i?a.success.push(c):a.failed.push({file:c,error:g??"Unknown error"});if(t.length>0){r.message(`Deleting ${t.length} files...`);let c=await Z(t,async i=>{try{return await gt(i,n),{file:i,success:!0}}catch(g){let d=g instanceof Error?g.message:`${g}`;return{file:i,success:!1,error:d}}},Y);for(let i of c)i.success?a.deleted.push(i.file):a.failed.push({file:i.file,error:i.error})}return a},ut=e=>{if(e.success.length>0){p.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)p.info(` \u2713 ${t}`)}if(e.deleted.length>0){p.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)p.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){p.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:s}of e.failed)p.error(` \u2717 ${t}: ${s}`)}},ft=async e=>{let t=await P(e),s=E(t,f),n=b();return s?s===n?{currentVersion:s,nextVersion:n,updated:!1}:($(t,f,n),await F(e,t),{currentVersion:s,nextVersion:n,updated:!0}):{currentVersion:s,nextVersion:n,updated:!1}},mt=async(e,t,s)=>{let n=await P(e);if(!V(n,f))return!1;t&&t.length>0&&p.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),s?.sync&&p.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:r,nextVersion:a,updated:o}=await ft(e);if(!o)return p.success(r?`@vercel/geistdocs is already at ${a}.`:"No package version update was needed."),R("Package-based site is already up to date."),!0;p.info(`Bumping ${f} from ${r} to ${a}`);let l=ee();return l.start("Installing updated package version..."),await m("pnpm install",{cwd:e}),l.stop("Package update complete!"),R("Please review and test the upgraded package version."),!0},ht=async(e,t,s,n,r)=>{let a=w(e,I),o=ee(),l=r?.sync?a:t;o.start("Preparing template snapshot..."),r?.sync&&(await ct(e,I),await D(a)),o.message("Scanning for files...");let c=await W(s,n,l),i=[];if(r?.sync){o.message("Comparing with local files...");let d=await W(s,n,e),u=new Set(c);i=d.filter(k=>!u.has(k))}if(o.stop(`Found ${c.length} files to update`),c.length===0&&i.length===0){p.warn("No files matched the patterns. Nothing to update."),r?.sync&&await O(a),R("Update cancelled.");return}p.info(`Patterns: ${s.length}`),p.info(`Files to update: ${c.length}`),r?.sync&&p.info(`Files to delete: ${i.length}`),o.start("Updating files...");let g=await dt(c,i,l,e,o);r?.sync&&(o.message("Cleaning up..."),await O(a)),o.stop("Update complete!"),ut(g),R("Please review and test the changes carefully.")},te=async(e,t)=>{let s=process.cwd(),n=j(),r=e&&e.length>0?e:it,a=e&&e.length>0?[]:ot;try{if(rt("Let's update your Geistdocs project!"),await mt(s,e,t))return;p.info("Template source: bundled package snapshot"),e&&e.length>0&&p.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&p.info("Sync mode enabled: will delete files removed from template"),await ht(s,n,r,a,t)}catch(o){let l=o instanceof Error?o.message:`${o}`;try{await O(w(s,I))}catch{}p.error(`Failed to update project: ${l}`),process.exit(1)}};T.name("geistdocs").description("CLI for Geistdocs projects").version("1.3.0-canary.41d37f1","-v, --version","Output the current version");T.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").option("--disable-git","Disable git initialization").action(B);T.command("update [files...]").description("Update a Geistdocs project (optionally specify files/patterns to update)").option("--sync","Delete local files that no longer exist in the template").action(te);T.command("translate [pattern]").description("Translate MDX file(s) to one or more locales (default: content/docs/**/*.mdx)").option("--config <path>","Path to config file to load locales from (defaults to geistdocs.tsx)").option("--url <url>","Custom translation API URL (defaults to GEISTDOCS_TRANSLATE_URL or https://geistdocs.com/translate)").option("--force","Force re-translation of all files, ignoring cache").action(X);T.parse(process.argv);
2
+ import{program as x}from"commander";import{access as de,copyFile as pe,mkdir as ge,rm as ue,writeFile as O}from"fs/promises";import{join as v}from"path";import{cancel as fe,intro as me,isCancel as he,log as we,outro as ye,spinner as Pe,text as ve}from"@clack/prompts";import{spawn as ne}from"child_process";import{readFileSync as re}from"fs";import{cp as ae,readFile as ie,rename as oe,writeFile as ce}from"fs/promises";import{join as b}from"path";import{fileURLToPath as le}from"url";var f="@vercel/geistdocs",m=(e,t=[],s={})=>new Promise((n,r)=>{let a=ne(e,t,{stdio:"inherit",...s});a.on("error",r),a.on("close",i=>{if(i===0){n();return}r(new Error(`Command failed with exit code ${i}: ${[e,...t].join(" ")}`))})}),V=["dependencies","devDependencies","optionalDependencies","peerDependencies"],F=()=>JSON.parse(re(new URL("../../package.json",import.meta.url),"utf8")).version,P=async e=>{let t=b(e,"package.json"),s=await ie(t,"utf8");return JSON.parse(s)},$=async(e,t)=>{let s=b(e,"package.json");await ce(s,`${JSON.stringify(t,null,2)}
3
+ `,"utf8")},E=(e,t)=>{for(let s of V){let n=e[s];if(n&&t in n)return n[t]}},z=(e,t)=>!!E(e,t),S=(e,t,s)=>{let n=!1;for(let r of V){let a=e[r];a&&t in a&&(a[t]=s,n=!0)}return n},N=()=>le(new URL("../../template",import.meta.url)),D=async e=>{await ae(N(),e,{recursive:!0});let t=b(e,".gitignore"),s=b(e,"_gitignore");try{await oe(s,t)}catch{}};var Te=async e=>{await D(e)},xe=async e=>{try{return await de(e),!0}catch{return!1}},ke=async()=>{await xe(".env.example")&&await pe(".env.example",".env.local")},be=async()=>{let e=v("content","docs"),t=["---","title: Welcome to Geistdocs","description: Start writing documentation with Geistdocs.","---","","# Welcome to Geistdocs","","- Edit `content/docs/index.mdx`.","- Add more pages in `content/docs`.","- Update `content/docs/meta.json` to control the sidebar.",""].join(`
4
+ `),s=["---","title: Welcome to Geistdocs","description: Start writing documentation with Geistdocs.","---","","# Welcome to Geistdocs","","- Edit `content/docs/index.cn.mdx`.","- Add translated pages in `content/docs`.","- Update `content/docs/meta.json` to control the sidebar.",""].join(`
5
+ `);await ue(e,{recursive:!0,force:!0}),await ge(e,{recursive:!0}),await O(v(e,"meta.json"),`${JSON.stringify({title:"Documentation",description:"Documentation",root:!0,pages:["index"]},null,2)}
6
+ `,"utf8"),await O(v(e,"index.mdx"),t,"utf8"),await O(v(e,"index.cn.mdx"),s,"utf8")},Fe=async e=>{let t=await P(e),s=F();return S(t,f,s)?(await $(e,t),!0):!1},$e=async e=>{await m("pnpm",["install"],{cwd:e,env:process.env,stdio:"inherit"})},Se=async e=>{await m("git",["init"],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["add","."],{cwd:e,env:process.env,stdio:"inherit"}),await m("git",["commit","-m","\u2728 Initial commit"],{cwd:e,env:process.env,stdio:"inherit"})},De=async()=>{let e=await ve({message:"What is your project named?",placeholder:"my-app",validate(t){if(t.length===0)return"Please enter a project name."}});return he(e)&&(fe("Operation cancelled."),process.exit(0)),e.toString()},B=async e=>{try{me("Let's start a Geistdocs project!");let t=process.cwd(),s=e.name||await De(),n=Pe(),r=v(t,s);n.start("Copying bundled template..."),await Te(s),n.message("Setting up environment variables..."),process.chdir(r),await ke(),n.message("Creating starter content..."),await be(),n.message("Rewriting package dependency versions..."),await Fe(r),n.message("Installing dependencies..."),await $e(r),e.disableGit||(n.message("Initializing Git repository..."),await Se(r)),n.stop("Project initialized successfully!"),ye("Run `pnpm dev` to start the development server.")}catch(t){let s=t instanceof Error?t.message:`Failed to initialize project: ${t}`;we.error(s),process.exit(1)}};import{readFileSync as Ce,writeFileSync as je}from"fs";import{mkdir as Re,readFile as J,writeFile as Ee}from"fs/promises";import{dirname as Ne,extname as Oe,relative as K,resolve as j}from"path";import{intro as Ue,isCancel as Je,log as h,multiselect as Ie,outro as C,spinner as Ae}from"@clack/prompts";import{glob as Le}from"glob";import{Node as T,Project as Ge,SyntaxKind as _e}from"ts-morph";var Ve="geistdocs.tsx",ze="content/docs/**/*.mdx",I=".translation-cache.json",U=8,H=()=>({version:1,entries:{}}),Be=async e=>{let t=await J(e),{createHash:s}=await import("crypto");return s("sha256").update(t).digest("hex")},He=e=>{let t=j(process.cwd(),e);return Ce(t,"utf8")},M=e=>T.isObjectLiteralExpression(e)?e.getProperties().flatMap(t=>{if(T.isPropertyAssignment(t)){let s=t.getNameNode();if(T.isIdentifier(s)||T.isStringLiteral(s))return[s.getText().replaceAll(/['"]/g,"")]}return[]}).filter(Boolean):[],Me=e=>{try{let t=new Ge({compilerOptions:{allowJs:!0,jsx:4,module:99,target:10},skipAddingFilesFromTsConfig:!0,useInMemoryFileSystem:!0}),s=He(e),a=t.createSourceFile(e,s,{overwrite:!0}).getVariableDeclarations().find(l=>l.getName()==="translations")?.getInitializer();if(!a)return[];if(T.isObjectLiteralExpression(a))return M(a);let i=a.getFirstDescendantByKind(_e.ObjectLiteralExpression);return i?M(i):[]}catch(t){let s=t instanceof Error?t.message:`${t}`;return h.warn(`Failed to read locales from ${e}: ${s}`),[]}},We=async()=>{let e=await Ie({message:"Which locales should be translated?",options:[{value:"cn",label:"Chinese (cn)"},{value:"jp",label:"Japanese (jp)"},{value:"es",label:"Spanish (es)"},{value:"fr",label:"French (fr)"},{value:"de",label:"German (de)"}],required:!0});return Je(e)&&(C("Translation cancelled"),process.exit(0)),e},Ke=async e=>(await Le(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).sort(),qe=async()=>{let e=j(process.cwd(),I);try{let t=await J(e,"utf8"),s=JSON.parse(t);return s.version!==1||!s.entries?H():{version:1,entries:s.entries}}catch{return H()}},W=e=>{let t=j(process.cwd(),I),s=JSON.stringify(e,null,2);je(t,s,"utf8")},Xe=async e=>{let t=await Promise.all(e.map(async s=>[s,await Be(s)]));return Object.fromEntries(t)},Ye=(e,t)=>{let s=Oe(e);return`${e.slice(0,-s.length)}.${t}${s}`},q=(e,t)=>`${K(process.cwd(),e)}::${t}`,Ze=(e,t,s,n,r=!1)=>{let a=[],i=0;for(let l of t){let c=s[l];for(let o of e){let p=Ye(l,o),g=q(l,o),u=n.entries[g];if(!r&&u?.hash===c){i+=1;continue}a.push({locale:o,sourceFile:l,sourceHash:c,targetFile:p})}}return{tasks:a,skippedCount:i}},Qe=async e=>{await Re(Ne(e),{recursive:!0})},et=async(e,t,s)=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,locale:s})});if(!n.ok){let a=await n.text();throw new Error(`API request failed (${n.status}): ${a}`)}let r=await n.json();if(!r.translation)throw new Error("API response did not include a translation");return r.translation},tt=async(e,t,s)=>{let n=await J(e.sourceFile,"utf8"),r=await et(t,n,e.locale);await Qe(e.targetFile),await Ee(e.targetFile,r,"utf8"),s.entries[q(e.sourceFile,e.locale)]={hash:e.sourceHash,updatedAt:new Date().toISOString()}},X=async(e,t)=>{Ue("Translate MDX content");let s=e??ze,n=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",r=Me(t.config??Ve),a=await Ke(s);a.length===0&&(h.error(`No MDX files found matching pattern: ${s}`),C("Translation cancelled"),process.exit(1)),h.info(`Found ${a.length} MDX file(s) matching pattern`),r.length===0&&(r=await We());let i=j(process.cwd(),I),l=await qe();await W(l),h.info(`Using cache: ${i}`);let c=await Xe(a),{tasks:o,skippedCount:p}=Ze(r,a,c,l,t.force);if(o.length===0){h.success("All translations are up to date!"),C(`Skipped ${p} file(s) (unchanged)`);return}let g=[];for(let y=0;y<o.length;y+=U)g.push(o.slice(y,y+U));h.info(`Processing ${o.length} translation(s) in ${g.length} batch(es) of up to ${U}`),p>0&&h.info(`Skipped ${p} translation(s) (unchanged)`);let u=Ae();u.start("Translating content...");let k=0;for(let y of g)await Promise.all(y.map(async _=>{await tt(_,n,l),k+=1,u.message(`Translated ${k}/${o.length}: ${K(process.cwd(),_.targetFile)}`)})),await W(l);u.stop("Translation complete!"),C(`Created/updated ${o.length} file(s)`)};import{access as st,copyFile as nt,mkdir as ee,rm as G}from"fs/promises";import{dirname as rt,join as w}from"path";import{intro as at,log as d,outro as R,spinner as te}from"@clack/prompts";import{glob as it}from"glob";var ot=["**/*"],ct=["content/docs/**"],A=".geistdocs-tmp",lt=async(e,t)=>{let s=w(e,t);await G(s,{recursive:!0,force:!0}),await ee(s,{recursive:!0})},L=async e=>await G(e,{recursive:!0,force:!0}),Y=async(e,t,s)=>(await it(e,{cwd:s,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),dt=async e=>{try{return await st(e),!0}catch{return!1}},pt=async(e,t,s)=>{let n=w(t,e),r=w(s,e);return await dt(n)?(await nt(n,r),{success:!0}):{success:!1,error:`Source file not found: ${n}`}},gt=async(e,t)=>{let s=w(t,e);return await G(s,{force:!0}),{success:!0}},Z=20,Q=async(e,t,s)=>{let n=[];for(let r=0;r<e.length;r+=s){let a=e.slice(r,r+s),i=await Promise.all(a.map(t));n.push(...i)}return n},ut=async(e,t,s,n,r)=>{let a={success:[],deleted:[],failed:[]},i=[...new Set(e.map(c=>rt(w(n,c))))];r.message(`Creating ${i.length} directories...`),await Promise.all(i.map(c=>ee(c,{recursive:!0}))),r.message(`Updating ${e.length} files...`);let l=await Q(e,async c=>{let o=await pt(c,s,n);return{file:c,...o}},Z);for(let{file:c,success:o,error:p}of l)o?a.success.push(c):a.failed.push({file:c,error:p??"Unknown error"});if(t.length>0){r.message(`Deleting ${t.length} files...`);let c=await Q(t,async o=>{try{return await gt(o,n),{file:o,success:!0}}catch(p){let g=p instanceof Error?p.message:`${p}`;return{file:o,success:!1,error:g}}},Z);for(let o of c)o.success?a.deleted.push(o.file):a.failed.push({file:o.file,error:o.error})}return a},ft=e=>{if(e.success.length>0){d.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)d.info(` \u2713 ${t}`)}if(e.deleted.length>0){d.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)d.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){d.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:s}of e.failed)d.error(` \u2717 ${t}: ${s}`)}},mt=async e=>{let t=await P(e),s=E(t,f),n=F();return s?s===n?{currentVersion:s,nextVersion:n,updated:!1}:(S(t,f,n),await $(e,t),{currentVersion:s,nextVersion:n,updated:!0}):{currentVersion:s,nextVersion:n,updated:!1}},ht=async(e,t,s)=>{let n=await P(e);if(!z(n,f))return!1;t&&t.length>0&&d.warn("Ignoring file patterns for a package-based site. This update will bump the package version instead."),s?.sync&&d.warn("Ignoring --sync for a package-based site. Runtime updates now come from the package version.");let{currentVersion:r,nextVersion:a,updated:i}=await mt(e);if(!i)return d.success(r?`@vercel/geistdocs is already at ${a}.`:"No package version update was needed."),R("Package-based site is already up to date."),!0;d.info(`Bumping ${f} from ${r} to ${a}`);let l=te();return l.start("Installing updated package version..."),await m("pnpm",["install"],{cwd:e}),l.stop("Package update complete!"),R("Please review and test the upgraded package version."),!0},wt=async(e,t,s,n,r)=>{let a=w(e,A),i=te(),l=r?.sync?a:t;i.start("Preparing template snapshot..."),r?.sync&&(await lt(e,A),await D(a)),i.message("Scanning for files...");let c=await Y(s,n,l),o=[];if(r?.sync){i.message("Comparing with local files...");let g=await Y(s,n,e),u=new Set(c);o=g.filter(k=>!u.has(k))}if(i.stop(`Found ${c.length} files to update`),c.length===0&&o.length===0){d.warn("No files matched the patterns. Nothing to update."),r?.sync&&await L(a),R("Update cancelled.");return}d.info(`Patterns: ${s.length}`),d.info(`Files to update: ${c.length}`),r?.sync&&d.info(`Files to delete: ${o.length}`),i.start("Updating files...");let p=await ut(c,o,l,e,i);r?.sync&&(i.message("Cleaning up..."),await L(a)),i.stop("Update complete!"),ft(p),R("Please review and test the changes carefully.")},se=async(e,t)=>{let s=process.cwd(),n=N(),r=e&&e.length>0?e:ot,a=e&&e.length>0?[]:ct;try{if(at("Let's update your Geistdocs project!"),await ht(s,e,t))return;d.info("Template source: bundled package snapshot"),e&&e.length>0&&d.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&d.info("Sync mode enabled: will delete files removed from template"),await wt(s,n,r,a,t)}catch(i){let l=i instanceof Error?i.message:`${i}`;try{await L(w(s,A))}catch{}d.error(`Failed to update project: ${l}`),process.exit(1)}};x.name("geistdocs").description("CLI for Geistdocs projects").version("1.3.0-canary.88e35b7","-v, --version","Output the current version");x.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").option("--disable-git","Disable git initialization").action(B);x.command("update [files...]").description("Update a Geistdocs project (optionally specify files/patterns to update)").option("--sync","Delete local files that no longer exist in the template").action(se);x.command("translate [pattern]").description("Translate MDX file(s) to one or more locales (default: content/docs/**/*.mdx)").option("--config <path>","Path to config file to load locales from (defaults to geistdocs.tsx)").option("--url <url>","Custom translation API URL (defaults to GEISTDOCS_TRANSLATE_URL or https://geistdocs.com/translate)").option("--force","Force re-translation of all files, ignoring cache").action(X);x.parse(process.argv);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vercel/geistdocs",
3
3
  "description": "Runtime and CLI for Geistdocs projects.",
4
- "version": "1.3.0-canary.41d37f1",
4
+ "version": "1.3.0-canary.88e35b7",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/vercel/geistdocs",
@@ -1 +1,29 @@
1
+ # dependencies
2
+ node_modules
3
+
4
+ # generated content
5
+ .source
6
+
7
+ # test and build output
8
+ coverage
9
+ .next
10
+ out
11
+ build
12
+ dist
13
+ *.tsbuildinfo
14
+
15
+ # local environment
16
+ .env*.local
1
17
  .vercel
18
+
19
+ # logs
20
+ npm-debug.log*
21
+ yarn-debug.log*
22
+ yarn-error.log*
23
+ pnpm-debug.log*
24
+
25
+ # system files
26
+ .DS_Store
27
+
28
+ # Turborepo
29
+ .turbo
@@ -14,7 +14,7 @@
14
14
  "@ai-sdk/react": "^2.0.115",
15
15
  "@icons-pack/react-simple-icons": "^13.8.0",
16
16
  "@orama/tokenizers": "^3.1.16",
17
- "@vercel/geistdocs": "1.3.0-canary.41d37f1",
17
+ "@vercel/geistdocs": "1.3.0-canary.88e35b7",
18
18
  "@streamdown/cjk": "^1.0.1",
19
19
  "@streamdown/code": "^1.0.1",
20
20
  "@vercel/agent-readability": "^0.2.1",