@vercel/geistdocs 1.1.2 → 1.2.1

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{program as E}from"commander";import{copyFile as ee,rm as te}from"fs/promises";import{join as O}from"path";import{cancel as se,intro as ne,isCancel as re,log as oe,outro as ae,spinner as ie,text as ce}from"@clack/prompts";import{spawn as Q}from"child_process";var R="https://github.com/vercel/geistdocs";var T={stdio:"ignore"};var C="geistdocs-update",m=(e,t)=>new Promise((r,s)=>{let[o,...a]=e.split(" "),n=Q(o,a,{stdio:["ignore","pipe","pipe"],shell:t?.shell??!0,cwd:t?.cwd}),g="",l="";n.stdout?.on("data",c=>{g+=c.toString()}),n.stderr?.on("data",c=>{l+=c.toString()});let i=()=>{n.kill("SIGTERM"),setTimeout(()=>{n.killed||n.kill("SIGKILL")},1e3)};process.on("SIGINT",i),process.on("SIGTERM",i),n.on("close",c=>{process.removeListener("SIGINT",i),process.removeListener("SIGTERM",i),c===0?r({stdout:g,stderr:l}):s(new Error(`Command failed with code ${c}: ${l}`))}),n.on("error",c=>{process.removeListener("SIGINT",i),process.removeListener("SIGTERM",i),s(c)})});var le="https://github.com/vercel/geistdocs.git",pe=async e=>{await m(`git clone --depth 1 --filter=blob:none --sparse ${le} ${e}`,T),await m("git sparse-checkout set apps/template",{...T,cwd:e}),await m("mv apps/template/* apps/template/.[!.]* . 2>/dev/null || true",{...T,cwd:e,shell:"/bin/bash"}),await m("rm -rf apps .git",{...T,cwd:e})},ge=async()=>{await ee(".env.example",".env.local")},de=async()=>{await te(O("content","docs"),{recursive:!0,force:!0})},fe=async()=>{await m("pnpm install",T)},me=async()=>{await m("git init",T),await m("git add .",T),await m('git commit -m "\u2728 Initial commit"',T)},ue=async()=>{let e=await ce({message:"What is your project named?",placeholder:"my-app",validate(t){if(t.length===0)return"Please enter a project name."}});return re(e)&&(se("Operation cancelled."),process.exit(0)),e.toString()},A=async e=>{try{ne("Let's start a Geistdocs project!");let t=process.cwd(),r=e.name||await ue(),s=ie(),o=O(t,r);s.start("Cloning template..."),await pe(r),s.message("Moving into project..."),process.chdir(o),s.message("Setting up environment variables..."),await ge(),s.message("Deleting demo content..."),await de(),s.message("Installing dependencies..."),await fe(),e.disableGit||(s.message("Initializing Git repository..."),await me()),s.stop("Project initialized successfully!"),ae("Run `pnpm dev` to start the development server.")}catch(t){let r=t instanceof Error?t.message:`Failed to initialize project: ${t}`;oe.error(r),process.exit(1)}};import{createHash as he}from"crypto";import{existsSync as G}from"fs";import{readFile as L,writeFile as M}from"fs/promises";import{dirname as we,parse as k,resolve as v}from"path";import{intro as ye,isCancel as Te,log as w,outro as b,spinner as $e,text as xe}from"@clack/prompts";import{glob as Pe}from"glob";import{Project as Se,SyntaxKind as I}from"ts-morph";var j=10,be="content/docs/**/*.mdx",U=".translation-cache.json",ve=/\.[a-z]{2}\.mdx$/,Ee=async e=>(await Pe(e,{cwd:process.cwd(),absolute:!0,nodir:!0})).filter(r=>r.endsWith(".mdx")).filter(r=>!ve.test(r)),Fe=e=>{let t=v(process.cwd(),e),o=new Se({skipAddingFilesFromTsConfig:!0}).addSourceFileAtPath(t).getVariableDeclaration("translations");if(!o)throw new Error("Could not find translations export in config file");let a=o.getInitializer();if(!a||a.getKind()!==I.ObjectLiteralExpression)throw new Error("translations must be an object literal");let n=a.asKind(I.ObjectLiteralExpression);if(!n)throw new Error("Could not parse translations object");let g=n.getProperties().filter(c=>c.getKind()===I.PropertyAssignment).map(c=>c.asKind(I.PropertyAssignment)?.getName()).filter(c=>c!==void 0);if(g.length===0)throw new Error("No locales found in translations object");let[l,...i]=g;return i},Ce=e=>he("sha256").update(e).digest("hex"),Ie=async()=>{let e=v(process.cwd(),U);if(!G(e))return{};try{let t=await L(e,"utf-8");return JSON.parse(t)}catch{return w.warn("Failed to load translation cache, starting fresh"),{}}},z=async e=>{let t=v(process.cwd(),U);await M(t,JSON.stringify(e,null,2),"utf-8")},Re=(e,t,r,s)=>{let o=e[t];if(!o)return!0;let a=o[r];return a?a.hash!==s:!0},je=async(e,t,r)=>{let s=await L(e,"utf-8"),o=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:s,locale:t})}),a=await o.text();if(!o.ok){let n=`Translation failed with status ${o.status}`;try{let g=JSON.parse(a);n=g.error||g.message||n}catch{n=a||n}throw new Error(n)}try{return JSON.parse(a).translation}catch{throw new Error(`Failed to parse response: ${a.slice(0,200)}`)}},Le=async(e,t,r,s,o)=>{let a=we(e),{name:n,ext:g}=k(e),l=v(a,`${n}.${t}${g}`);await M(l,r,"utf-8"),s[e]||(s[e]={}),s[e][t]={hash:o,translatedAt:new Date().toISOString()},await z(s)},_=async(e,t)=>{ye("Translate MDX content");let r=e??be,s=[],o=t.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",a=t.config??"geistdocs.tsx";if(a)try{s=Fe(a),w.info(`Loaded ${s.length} locale(s) from config: ${s.join(", ")}`)}catch(p){w.error(`Failed to load config: ${p instanceof Error?p.message:String(p)}`),b("Translation cancelled"),process.exit(1)}let n=await Ee(r);if(n.length===0&&(w.error(`No MDX files found matching pattern: ${r}`),b("Translation cancelled"),process.exit(1)),w.info(`Found ${n.length} MDX file(s) matching pattern`),s.length===0){let p=await xe({message:"Enter target locales (comma-separated):",placeholder:"cn,fr,es",validate:d=>{if(!d)return"At least one locale is required"}});Te(p)&&(b("Translation cancelled"),process.exit(0)),s=p.split(",").map(d=>d.trim())}let g=v(process.cwd(),U),l=await Ie();G(g)||await z(l),w.info(`Using cache: ${g}`);let i=new Map;for(let p of n){let d=await L(p,"utf-8");i.set(p,Ce(d))}let c=[],h=0;for(let p of s)for(let d of n){let S=i.get(d);if(!S)throw new Error(`Hash not found for file: ${d}`);t.force||Re(l,d,p,S)?c.push({filePath:d,locale:p,hash:S}):h+=1}if(c.length===0){w.success("All translations are up to date!"),b(`Skipped ${h} file(s) (unchanged)`);return}let y=[];for(let p=0;p<c.length;p+=j)y.push(c.slice(p,p+j));w.info(`Processing ${c.length} translation(s) in ${y.length} batch(es) of up to ${j}`),h>0&&w.info(`Skipped ${h} translation(s) (unchanged)`);let P=$e();try{let p=[];P.start("Starting translation...");let d=0;for(let $=0;$<y.length;$++){let F=y[$];P.message(`Processing batch ${$+1}/${y.length} (${F.length} translations) - ${d}/${c.length} complete`),await Promise.all(F.map(async u=>{let{name:W,ext:Y}=k(u.filePath),Z=await je(u.filePath,u.locale,o);await Le(u.filePath,u.locale,Z,l,u.hash),p.push({name:W,locale:u.locale,ext:Y}),d+=1})),$<y.length-1&&(P.message(`Batch ${$+1}/${y.length} complete. Pausing...`),await new Promise(u=>setTimeout(u,1e3)))}P.stop("Translation complete!");for(let{name:$,locale:F,ext:u}of p)w.success(`Saved: ${$}.${F}${u}`);let S=[`Translated ${p.length} file(s)`];h>0&&S.push(`Skipped ${h} unchanged`),b(S.join(" \u2022 "))}catch(p){let d=p instanceof Error?p.message:String(p);P.stop(`Translation failed: ${d}`),b("Exiting"),process.exit(1)}};import{access as Ue,copyFile as De,mkdir as X,rm as N}from"fs/promises";import{dirname as Ne,join as x}from"path";import{intro as Oe,log as f,outro as H,spinner as Ae}from"@clack/prompts";import{glob as Ge}from"glob";var V="apps/template",Me=["**/*"],ke=["content/docs/**"],ze=async(e,t)=>{let r=x(e,t);await N(r,{recursive:!0,force:!0}),await X(r,{recursive:!0})},_e=async(e,t)=>{await m(`git clone --depth 1 --filter=blob:none --sparse ${R} ${t}`,{cwd:e}),await m("git sparse-checkout set apps/template",{cwd:x(e,t)})},D=async e=>await N(e,{recursive:!0,force:!0}),K=async(e,t,r)=>(await Ge(e,{cwd:r,nodir:!0,dot:!0,ignore:[".git/**",...t]})).sort(),He=async e=>{try{return await Ue(e),!0}catch{return!1}},Ke=async(e,t,r)=>{let s=x(t,V,e),o=x(r,e);return await He(s)?(await De(s,o),{success:!0}):{success:!1,error:`Source file not found: ${s}`}},Be=async(e,t)=>{let r=x(t,e);return await N(r,{force:!0}),{success:!0}},B=20,J=async(e,t,r)=>{let s=[];for(let o=0;o<e.length;o+=r){let a=e.slice(o,o+r),n=await Promise.all(a.map(t));s.push(...n)}return s},Je=async(e,t,r,s,o)=>{let a={success:[],deleted:[],failed:[]},n=[...new Set(e.map(l=>Ne(x(s,l))))];o.message(`Creating ${n.length} directories...`),await Promise.all(n.map(l=>X(l,{recursive:!0}))),o.message(`Updating ${e.length} files...`);let g=await J(e,async l=>{let i=await Ke(l,r,s);return{file:l,...i}},B);for(let{file:l,success:i,error:c}of g)i?a.success.push(l):a.failed.push({file:l,error:c??"Unknown error"});if(t.length>0){o.message(`Deleting ${t.length} files...`);let l=await J(t,async i=>{try{return await Be(i,s),{file:i,success:!0}}catch(c){let h=c instanceof Error?c.message:`${c}`;return{file:i,success:!1,error:h}}},B);for(let i of l)i.success?a.deleted.push(i.file):a.failed.push({file:i.file,error:i.error})}return a},Xe=e=>{if(e.success.length>0){f.success(`Successfully updated ${e.success.length} files:`);for(let t of e.success)f.info(` \u2713 ${t}`)}if(e.deleted.length>0){f.success(`Deleted ${e.deleted.length} files:`);for(let t of e.deleted)f.info(` \u{1F5D1} ${t}`)}if(e.failed.length>0){f.warn(`Failed to update ${e.failed.length} files:`);for(let{file:t,error:r}of e.failed)f.error(` \u2717 ${t}: ${r}`)}},q=async(e,t)=>{let r=process.cwd(),s=x(r,C),o=e&&e.length>0?e:Me,a=e&&e.length>0?[]:ke;try{Oe("Let's update your Geistdocs project!"),f.info(`Repository: ${R}`),e&&e.length>0&&f.info(`Updating specific files: ${e.join(", ")}`),t?.sync&&f.info("Sync mode enabled: will delete files removed from template");let n=Ae();n.start("Creating temporary directory..."),await ze(r,C),n.message("Cloning repository..."),await _e(r,C),n.message("Scanning for files...");let g=x(s,V),l=await K(o,a,g),i=[];if(t?.sync){n.message("Comparing with local files...");let h=await K(o,a,r),y=new Set(l);i=h.filter(P=>!y.has(P))}if(n.stop(`Found ${l.length} files to update`),l.length===0&&i.length===0){f.warn("No files matched the patterns. Nothing to update."),await D(s),H("Update cancelled.");return}f.info(`Patterns: ${o.length}`),f.info(`Files to update: ${l.length}`),t?.sync&&f.info(`Files to delete: ${i.length}`),n.start("Updating files...");let c=await Je(l,i,s,r,n);n.message("Cleaning up..."),await D(s),n.stop("Update complete!"),Xe(c),H("Please review and test the changes carefully.")}catch(n){let g=n instanceof Error?n.message:`${n}`;try{await D(s)}catch{}f.error(`Failed to update project: ${g}`),process.exit(1)}};E.name("geistdocs").description("CLI for Geistdocs projects").version("1.1.1","-v, --version","Output the current version");E.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").option("--disable-git","Disable git initialization").action(A);E.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(q);E.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(_);E.parse(process.argv);
2
+ import{program as P}from"commander";import{copyFile as V,rm as q}from"fs/promises";import{join as R}from"path";import{cancel as W,intro as Y,isCancel as Z,log as Q,outro as tt,spinner as et,text as st}from"@clack/prompts";import{spawn as X}from"child_process";var v="https://github.com/vercel/geistdocs";var h={stdio:"ignore"};var x="geistdocs-update",f=(t,e)=>new Promise((s,r)=>{let[a,...i]=t.split(" "),n=X(a,i,{stdio:["ignore","pipe","pipe"],shell:e?.shell??!0,cwd:e?.cwd}),l="",c="";n.stdout?.on("data",p=>{l+=p.toString()}),n.stderr?.on("data",p=>{c+=p.toString()});let o=()=>{n.kill("SIGTERM"),setTimeout(()=>{n.killed||n.kill("SIGKILL")},1e3)};process.on("SIGINT",o),process.on("SIGTERM",o),n.on("close",p=>{process.removeListener("SIGINT",o),process.removeListener("SIGTERM",o),p===0?s({stdout:l,stderr:c}):r(new Error(`Command failed with code ${p}: ${c}`))}),n.on("error",p=>{process.removeListener("SIGINT",o),process.removeListener("SIGTERM",o),r(p)})});var nt="https://github.com/vercel/geistdocs.git",rt=async t=>{await f(`git clone --depth 1 --filter=blob:none --sparse ${nt} ${t}`,h),await f("git sparse-checkout set apps/template",{...h,cwd:t}),await f("mv apps/template/* apps/template/.[!.]* . 2>/dev/null || true",{...h,cwd:t,shell:"/bin/bash"}),await f("rm -rf apps .git",{...h,cwd:t})},ot=async()=>{await V(".env.example",".env.local")},at=async()=>{await q(R("content","docs"),{recursive:!0,force:!0})},it=async()=>{await f("pnpm install",h)},ct=async()=>{await f("git init",h),await f("git add .",h),await f('git commit -m "\u2728 Initial commit"',h)},lt=async()=>{let t=await st({message:"What is your project named?",placeholder:"my-app",validate(e){if(e.length===0)return"Please enter a project name."}});return Z(t)&&(W("Operation cancelled."),process.exit(0)),t.toString()},j=async t=>{try{Y("Let's start a Geistdocs project!");let e=process.cwd(),s=t.name||await lt(),r=et(),a=R(e,s);r.start("Cloning template..."),await rt(s),r.message("Moving into project..."),process.chdir(a),r.message("Setting up environment variables..."),await ot(),r.message("Deleting demo content..."),await at(),r.message("Installing dependencies..."),await it(),t.disableGit||(r.message("Initializing Git repository..."),await ct()),r.stop("Project initialized successfully!"),tt("Run `pnpm dev` to start the development server.")}catch(e){let s=e instanceof Error?e.message:`Failed to initialize project: ${e}`;Q.error(s),process.exit(1)}};import{createHash as pt}from"crypto";import{existsSync as L}from"fs";import{readFile as F,writeFile as U}from"fs/promises";import{dirname as gt,parse as D,resolve as $}from"path";import{intro as dt,isCancel as ft,log as m,outro as T,spinner as mt,text as ut}from"@clack/prompts";import{glob as ht}from"glob";import{Project as wt,SyntaxKind as S}from"ts-morph";var b=10,yt="content/docs/**/*.mdx",C=".translation-cache.json",Tt=/\.[a-z]{2}\.mdx$/,$t=async t=>(await ht(t,{cwd:process.cwd(),absolute:!0,nodir:!0})).filter(s=>s.endsWith(".mdx")).filter(s=>!Tt.test(s)),Pt=t=>{let e=$(process.cwd(),t),a=new wt({skipAddingFilesFromTsConfig:!0}).addSourceFileAtPath(e).getVariableDeclaration("translations");if(!a)throw new Error("Could not find translations export in config file");let i=a.getInitializer();if(!i||i.getKind()!==S.ObjectLiteralExpression)throw new Error("translations must be an object literal");let n=i.asKind(S.ObjectLiteralExpression);if(!n)throw new Error("Could not parse translations object");let l=n.getProperties().filter(p=>p.getKind()===S.PropertyAssignment).map(p=>p.asKind(S.PropertyAssignment)?.getName()).filter(p=>p!==void 0);if(l.length===0)throw new Error("No locales found in translations object");let[c,...o]=l;return o},xt=t=>pt("sha256").update(t).digest("hex"),St=async()=>{let t=$(process.cwd(),C);if(!L(t))return{};try{let e=await F(t,"utf-8");return JSON.parse(e)}catch{return m.warn("Failed to load translation cache, starting fresh"),{}}},N=async t=>{let e=$(process.cwd(),C);await U(e,JSON.stringify(t,null,2),"utf-8")},vt=(t,e,s,r)=>{let a=t[e];if(!a)return!0;let i=a[s];return i?i.hash!==r:!0},bt=async(t,e,s)=>{let r=await F(t,"utf-8"),a=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r,locale:e})}),i=await a.text();if(!a.ok){let n=`Translation failed with status ${a.status}`;try{let l=JSON.parse(i);n=l.error||l.message||n}catch{n=i||n}throw new Error(n)}try{return JSON.parse(i).translation}catch{throw new Error(`Failed to parse response: ${i.slice(0,200)}`)}},Ft=async(t,e,s,r,a)=>{let i=gt(t),{name:n,ext:l}=D(t),c=$(i,`${n}.${e}${l}`);await U(c,s,"utf-8"),r[t]||(r[t]={}),r[t][e]={hash:a,translatedAt:new Date().toISOString()},await N(r)},Ct=t=>{try{let e=Pt(t);return m.info(`Loaded ${e.length} locale(s) from config: ${e.join(", ")}`),e}catch(e){m.error(`Failed to load config: ${e instanceof Error?e.message:String(e)}`),T("Translation cancelled"),process.exit(1)}},Et=async()=>{let t=await ut({message:"Enter target locales (comma-separated):",placeholder:"cn,fr,es",validate:e=>{if(!e)return"At least one locale is required"}});return ft(t)&&(T("Translation cancelled"),process.exit(0)),t.split(",").map(e=>e.trim())},It=async t=>{let e=new Map;for(let s of t){let r=await F(s,"utf-8");e.set(s,xt(r))}return e},Rt=(t,e,s,r,a)=>{let i=[],n=0;for(let l of t)for(let c of e){let o=s.get(c);if(!o)throw new Error(`Hash not found for file: ${c}`);a||vt(r,c,l,o)?i.push({filePath:c,locale:l,hash:o}):n+=1}return{tasks:i,skippedCount:n}},jt=async(t,e,s,r)=>{let a=mt(),i=[];a.start("Starting translation...");let n=0;for(let l=0;l<t.length;l++){let c=t[l];a.message(`Processing batch ${l+1}/${t.length} (${c.length} translations) - ${n}/${e} complete`),await Promise.all(c.map(async o=>{let{name:p,ext:u}=D(o.filePath),g=await bt(o.filePath,o.locale,s);await Ft(o.filePath,o.locale,g,r,o.hash),i.push({name:p,locale:o.locale,ext:u}),n+=1})),l<t.length-1&&(a.message(`Batch ${l+1}/${t.length} complete. Pausing...`),await new Promise(o=>setTimeout(o,1e3)))}return a.stop("Translation complete!"),i},O=async(t,e)=>{dt("Translate MDX content");let s=t??yt,r=e.url||process.env.GEISTDOCS_TRANSLATE_URL||"https://geistdocs.com/translate",a=Ct(e.config??"geistdocs.tsx"),i=await $t(s);i.length===0&&(m.error(`No MDX files found matching pattern: ${s}`),T("Translation cancelled"),process.exit(1)),m.info(`Found ${i.length} MDX file(s) matching pattern`),a.length===0&&(a=await Et());let n=$(process.cwd(),C),l=await St();L(n)||await N(l),m.info(`Using cache: ${n}`);let c=await It(i),{tasks:o,skippedCount:p}=Rt(a,i,c,l,e.force);if(o.length===0){m.success("All translations are up to date!"),T(`Skipped ${p} file(s) (unchanged)`);return}let u=[];for(let g=0;g<o.length;g+=b)u.push(o.slice(g,g+b));m.info(`Processing ${o.length} translation(s) in ${u.length} batch(es) of up to ${b}`),p>0&&m.info(`Skipped ${p} translation(s) (unchanged)`);try{let g=await jt(u,o.length,r,l);for(let{name:B,locale:K,ext:J}of g)m.success(`Saved: ${B}.${K}${J}`);let y=[`Translated ${g.length} file(s)`];p>0&&y.push(`Skipped ${p} unchanged`),T(y.join(" \u2022 "))}catch(g){let y=g instanceof Error?g.message:String(g);m.error(`Translation failed: ${y}`),T("Exiting"),process.exit(1)}};import{access as Lt,copyFile as Ut,mkdir as z,rm as I}from"fs/promises";import{dirname as Dt,join as w}from"path";import{intro as Nt,log as d,outro as A,spinner as Ot}from"@clack/prompts";import{glob as At}from"glob";var _="apps/template",kt=["**/*"],Gt=["content/docs/**"],Mt=async(t,e)=>{let s=w(t,e);await I(s,{recursive:!0,force:!0}),await z(s,{recursive:!0})},zt=async(t,e)=>{await f(`git clone --depth 1 --filter=blob:none --sparse ${v} ${e}`,{cwd:t}),await f("git sparse-checkout set apps/template",{cwd:w(t,e)})},E=async t=>await I(t,{recursive:!0,force:!0}),k=async(t,e,s)=>(await At(t,{cwd:s,nodir:!0,dot:!0,ignore:[".git/**",...e]})).sort(),_t=async t=>{try{return await Lt(t),!0}catch{return!1}},Ht=async(t,e,s)=>{let r=w(e,_,t),a=w(s,t);return await _t(r)?(await Ut(r,a),{success:!0}):{success:!1,error:`Source file not found: ${r}`}},Bt=async(t,e)=>{let s=w(e,t);return await I(s,{force:!0}),{success:!0}},G=20,M=async(t,e,s)=>{let r=[];for(let a=0;a<t.length;a+=s){let i=t.slice(a,a+s),n=await Promise.all(i.map(e));r.push(...n)}return r},Kt=async(t,e,s,r,a)=>{let i={success:[],deleted:[],failed:[]},n=[...new Set(t.map(c=>Dt(w(r,c))))];a.message(`Creating ${n.length} directories...`),await Promise.all(n.map(c=>z(c,{recursive:!0}))),a.message(`Updating ${t.length} files...`);let l=await M(t,async c=>{let o=await Ht(c,s,r);return{file:c,...o}},G);for(let{file:c,success:o,error:p}of l)o?i.success.push(c):i.failed.push({file:c,error:p??"Unknown error"});if(e.length>0){a.message(`Deleting ${e.length} files...`);let c=await M(e,async o=>{try{return await Bt(o,r),{file:o,success:!0}}catch(p){let u=p instanceof Error?p.message:`${p}`;return{file:o,success:!1,error:u}}},G);for(let o of c)o.success?i.deleted.push(o.file):i.failed.push({file:o.file,error:o.error})}return i},Jt=t=>{if(t.success.length>0){d.success(`Successfully updated ${t.success.length} files:`);for(let e of t.success)d.info(` \u2713 ${e}`)}if(t.deleted.length>0){d.success(`Deleted ${t.deleted.length} files:`);for(let e of t.deleted)d.info(` \u{1F5D1} ${e}`)}if(t.failed.length>0){d.warn(`Failed to update ${t.failed.length} files:`);for(let{file:e,error:s}of t.failed)d.error(` \u2717 ${e}: ${s}`)}},H=async(t,e)=>{let s=process.cwd(),r=w(s,x),a=t&&t.length>0?t:kt,i=t&&t.length>0?[]:Gt;try{Nt("Let's update your Geistdocs project!"),d.info(`Repository: ${v}`),t&&t.length>0&&d.info(`Updating specific files: ${t.join(", ")}`),e?.sync&&d.info("Sync mode enabled: will delete files removed from template");let n=Ot();n.start("Creating temporary directory..."),await Mt(s,x),n.message("Cloning repository..."),await zt(s,x),n.message("Scanning for files...");let l=w(r,_),c=await k(a,i,l),o=[];if(e?.sync){n.message("Comparing with local files...");let u=await k(a,i,s),g=new Set(c);o=u.filter(y=>!g.has(y))}if(n.stop(`Found ${c.length} files to update`),c.length===0&&o.length===0){d.warn("No files matched the patterns. Nothing to update."),await E(r),A("Update cancelled.");return}d.info(`Patterns: ${a.length}`),d.info(`Files to update: ${c.length}`),e?.sync&&d.info(`Files to delete: ${o.length}`),n.start("Updating files...");let p=await Kt(c,o,r,s,n);n.message("Cleaning up..."),await E(r),n.stop("Update complete!"),Jt(p),A("Please review and test the changes carefully.")}catch(n){let l=n instanceof Error?n.message:`${n}`;try{await E(r)}catch{}d.error(`Failed to update project: ${l}`),process.exit(1)}};P.name("geistdocs").description("CLI for Geistdocs projects").version("1.1.1","-v, --version","Output the current version");P.command("init").description("Initialize a new Geistdocs project").option("--name <name>","Name of the project").option("--disable-git","Disable git initialization").action(j);P.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(H);P.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(O);P.parse(process.argv);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vercel/geistdocs",
3
3
  "description": "CLI for Geistdocs projects, including initialization and updating.",
4
- "version": "1.1.2",
4
+ "version": "1.2.1",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "geistdocs": "dist/index.js"