@chneau/x 0.0.254 → 0.0.255

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/package.json +1 -1
  2. package/x.js +1 -1
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@chneau/x",
3
- "version": "0.0.254",
3
+ "version": "0.0.255",
4
4
  "bin": "./x.js"
5
5
  }
package/x.js CHANGED
@@ -257,7 +257,7 @@ spec:
257
257
  `),oM=async({serviceAlias:e,registry:t,image:n,service:r,ingress:i})=>{let s=new rt.App({outputFileExtension:".yml"}),o=new rt.Chart(s,r.namespace,{namespace:r.namespace,disableResourceNameHashes:!0});new Ae.Namespace(o,r.namespace);let a=new Ae.Deployment(o,`d-${e}`,{replicas:r.replicas,metadata:{name:n.imageName},terminationGracePeriod:rt.Duration.seconds(0),dockerRegistryAuth:t.username&&t.password?ype(o,t.hostname,t.username,t.password):void 0}),u=`${t.hostname}/${n.repository}/${n.imageName}:${n.tag}`;a.addContainer({name:n.imageName,image:u,portNumber:r.port,envVariables:_pe({...r.env,DEPLOYMENT_DATE:new Date().toISOString()}),resources:{cpu:{request:r.cpuRequest?iM(r.cpuRequest):void 0,limit:r.cpuLimit?iM(r.cpuLimit):void 0},memory:{request:r.memoryRequest?sM(r.memoryRequest):void 0,limit:r.memoryLimit?sM(r.memoryLimit):void 0}},securityContext:{readOnlyRootFilesystem:r.readOnlyRootFilesystem,user:r.runAsUser,group:r.runAsGroup,ensureNonRoot:r.runAsNonRoot,allowPrivilegeEscalation:r.allowPrivilegeEscalation,privileged:r.privileged},startup:Ae.Probe.fromTcpSocket({periodSeconds:rt.Duration.seconds(1),failureThreshold:30})});let c=a.exposeViaService({name:n.imageName}),l=s.synthYaml();if(i==="traefik"){let d=Spe(c,r.endpoints,r.namespace,r.port);l=`${l}
258
258
  ---
259
259
  ${d}`}else bpe(o,c,r.endpoints);return l};var wpe=K.object({hostname:K.string(),username:K.string().nullish(),password:K.string().nullish()}),kpe=K.object({registry:K.string(),dockerfile:K.string().default("Dockerfile"),target:K.string().optional(),buildArgs:K.record(K.string(),K.string()).default({}),context:K.string().default("."),repository:K.string(),imageName:K.string(),tag:K.string().default("latest")}),gn=K.object({image:K.string(),replicas:K.number(),file:K.string(),context:K.string(),namespace:K.string(),port:K.number().min(1).max(65535),env:K.record(K.string(),K.string()),readOnlyRootFilesystem:K.boolean(),runAsUser:K.number().optional(),runAsGroup:K.number().optional(),runAsNonRoot:K.boolean().optional(),allowPrivilegeEscalation:K.boolean().optional(),privileged:K.boolean().optional(),cpuRequest:K.string().optional(),cpuLimit:K.string().optional(),memoryRequest:K.string().optional(),memoryLimit:K.string().optional(),endpoints:K.array(K.string().regex(/^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/)),ingress:K.enum(["nginx","traefik"]).optional()}),Ope=gn.extend({replicas:gn.shape.replicas.default(1),file:gn.shape.file.default("kubeconfig"),port:gn.shape.port.default(3000),env:gn.shape.env.default({}),readOnlyRootFilesystem:gn.shape.readOnlyRootFilesystem.default(!1),endpoints:gn.shape.endpoints.default([]),ingress:gn.shape.ingress.default("nginx")}),Ppe=gn.partial().extend({extends:K.string()}),xpe=Ope.or(Ppe),aM=K.object({registries:K.record(K.string(),wpe).default({}),images:K.record(K.string(),kpe),services:K.record(K.string(),xpe)}),gx=new Map,Ipe=async(e)=>{let t=Yc.join($pe.homedir(),".docker","config.json");try{let n=await Bun.file(t).json(),r=e==="docker.io"?"index.docker.io":e;return Object.keys(n?.auths??{}).some((i)=>i.includes(r))}catch{return!1}},uM=async()=>{let e=Bun.argv.slice(3),t=e.filter((o)=>o.endsWith(".json")),n=e.filter((o)=>!o.endsWith(".json")),r=t.length>0;if(t.length===0)t.push(...(await Bun.$`ls *.json`.text().catch(()=>"")).split(`
260
- `).filter(Boolean),".deploy.json");let i=!1,s=[];for(let o of t){let u=await Bun.file(o).text().catch(()=>null);if(!u)continue;let c=Tx(u),l=JSON.parse(c),d=await aM.parseAsync(l).catch(()=>null);if(!d)continue;let f=structuredClone(d);if(n.length)for(let m in d.services){if(n.includes(m))continue;delete d.services[m]}if(!Object.keys(d.services).length)continue;i=!0;for(let[m,h]of Object.entries(d.services))s.push(Cpe({config:{...d,services:{[m]:h}},allServices:f.services,cwd:Yc.dirname(o)}))}if(!i&&!r)await Ape();if(r&&!i)console.log("\u274C No valid json files found");await Promise.all(s)},Ape=async()=>{console.log("\uD83D\uDD52 Creating .deploy.json template...");let e=aM.parse({$schema:"https://raw.githubusercontent.com/chneau/x/refs/heads/master/deployment-schema.json",registries:{dockerhub:{hostname:"docker.io",username:"username",password:"password"}},images:{"my-image":{registry:"dockerhub",repository:"my-repo",imageName:"my-image"}},services:{"my-service":{image:"my-image",file:"kubeconfig",context:"my-context",namespace:"my-namespace",ingress:"nginx",env:{ENV:"value"},endpoints:["my-endpoint.com"]}}}),t=JSON.stringify(e,null,2),n=Bun.file(".deploy.json");if(await n.exists()){console.log("\u274C .deploy.json already exists");return}await n.write(t),console.log("\u2705 Created .deploy.json")},cM=(e,t,n=[])=>{if(n.includes(e.extends))throw Error(`Circular dependency detected: ${n.join(" -> ")} -> ${e.extends}`);let r=[...n,e.extends],i=t[e.extends];if(!i)throw Error(`Service ${e.extends} not found`);let s="extends"in i?cM(i,t,r):structuredClone(i);for(let[o,a]of Object.entries(e)){if(o==="extends")continue;if(o==="env"){s.env={...s.env,...e.env};continue}if(a!==void 0)s[o]=a}return s},Cpe=async({config:e,cwd:t,allServices:n})=>{for(let[r,i]of Object.entries(e.services)){console.log(`\uD83D\uDD52 Deploying ${r}...`);let s="extends"in i?cM(i,n):i,o=e.images[s.image];if(!o){console.error(`\u274C Image ${s.image} not found`);continue}let a=o.registry?e.registries[o.registry]:null;if(!a){console.info(`\u2753 Registry ${o.registry} not found`);continue}if(a.username&&a.password){let{hostname:l,username:d,password:f}=a;if(!gx.has(l))gx.set(l,(async()=>{if(await Ipe(l)){console.log(`\u2705 Already logged in to ${l}`);return}console.log(`\uD83D\uDD11 Logging in to ${l}...`),await Bun.$`echo ${f} | docker login --username ${d} --password-stdin ${l}`,console.log(`... \u2705 Logged in to ${l}`)})());await gx.get(l);let p=`${a.hostname}/${o.repository}/${o.imageName}:${o.tag}`;console.log(`\uD83D\uDD28 Building ${p}...`);let m=Object.entries(o.buildArgs).map(([w,I])=>`--build-arg=${w}=${I}`),h=o.target?[`--target=${o.target}`]:[],g=Yc.resolve(t,o.context),k=Yc.resolve(t,o.dockerfile);await Bun.$`docker build --pull --push --tag=${p} ${h} --file=${k} ${m} .`.cwd(g),console.log(`... \u2705 Built ${p}`)}console.log(`\uD83D\uDD17 Creating deployment for ${r}...`);let u=await oM({serviceAlias:r,registry:a,image:o,service:s,ingress:s.ingress});console.log(`... \u2705 Created deployment for ${r}`),console.log(`\uD83D\uDE80 Deploying ${r}...`);let c={...Bun.env,KUBECONFIG:Yc.join(t,s.file)};await Bun.$`echo ${u} | kubectl --context=${s.context} apply --filename=-`.env(c),console.log(`... \u2705 Deployed ${r}`)}};var{$:Te}=globalThis.Bun;var it={git:{defaultName:"chneau",defaultEmail:"charles63500@gmail.com"},templates:{web:"https://github.com/chneau/bun-hono-react-template","bun-hono-react-template":"https://github.com/chneau/bun-hono-react-template"},dotfiles:{baseUrl:"https://raw.githubusercontent.com/chneau/dotfiles/HEAD/"},packages:{apt:["git","gcc","make","curl","wget","unzip","zsh","bash","tree"],brew:[{name:"aichat"},{name:"bpytop"},{name:"dive"},{name:"dldash/core/docker-color-output",check:"docker-color-output"},{name:"docker-compose"},{name:"go"},{name:"graphviz",check:"dot"},{name:"helm"},{name:"hyperfine"},{name:"kubecolor"},{name:"kubectx"},{name:"kubernetes-cli",check:"kubectl"},{name:"lazygit"},{name:"node"},{name:"openjdk",check:"javac"},{name:"pipx"},{name:"stern"},{name:"zsh"}],bun:[{name:"@biomejs/biome",check:"biome"},{name:"@github/copilot",check:"copilot"},{name:"@google/gemini-cli",check:"gemini"},{name:"@qwen-code/qwen-code",check:"qwen"},{name:"opencode-ai",check:"opencode"},{name:"concurrently"},{name:"depcheck"},{name:"fkill-cli",check:"fkill"},{name:"http-server"},{name:"live-server"},{name:"nodemon"},{name:"npm-check-updates"},{name:"npm-check"},{name:"oxlint"},{name:"prettier"},{name:"ts-unused-exports"},{name:"tsx"},{name:"typesync"},{name:"ungit"}],custom:[{name:"uv",command:"curl -LsSf https://astral.sh/uv/install.sh | sh"},{name:"brew",env:{CI:"1",HOME:"/tmp"},command:"curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash"},{name:"deno",command:"curl -fsSL https://deno.land/install.sh | sh"},{name:"dotnet",command:"curl -sSL https://dot.net/v1/dotnet-install.sh | bash -s -- --channel 10.0"}],winget:[{name:"Git.Git",check:"git"},{name:"GoLang.Go",check:"go"},{name:"OpenJS.NodeJS",check:"node"},{name:"DenoLand.Deno",check:"deno"},{name:"JesseDuffield.Lazygit",check:"lazygit"},{name:"Microsoft.VisualStudioCode",check:"code"},{name:"Kubernetes.kubectl",check:"kubectl"},{name:"Helm.Helm",check:"helm"},{name:"JanDeDobbeleer.OhMyPosh",check:"oh-my-posh"}]}};var{$:vn}=globalThis.Bun;var dM=K.object({email:K.email(),name:K.string().min(1),updates:K.boolean()}),lM=async(e,t)=>{let n=(await vn`git config --global ${e}`.nothrow().text()).trim();if(n==="")console.log(`\u274C Git ${e} is not set`),console.log(`\uD83D\uDD52 Setting git ${e}`),await vn`git config --global ${e} ${t}`,console.log(`\u2705 Git ${e} set`);else console.log(`\u2705 Git ${e} is already set to "${n}"`)},vh=async(e)=>{await lM("user.name",e.name),await lM("user.email",e.email),await vn`git config --global url."ssh://git@github.com/".insteadOf "https://github.com/"`,await vn`git config --global merge.ff false`,await vn`git config --global pull.ff true`,await vn`git config --global pull.rebase true`,await vn`git config --global core.whitespace "blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol"`,await vn`git config --global fetch.prune true`,console.log("\u2705 Git config checked and updated.")},yh=async()=>{let e=`${Bun.env.HOME||Bun.env.USERPROFILE}/.ssh/id_rsa`;if(await Bun.file(e).exists())console.log("\u2705 SSH key is set");else throw console.log("\u274C SSH key is not set"),console.log(`\u26A1 Please execute this command:
260
+ `).filter(Boolean),".deploy.json");let i=!1,s=[];for(let o of t){let u=await Bun.file(o).text().catch(()=>null);if(!u)continue;let c=Tx(u),l=JSON.parse(c),d=await aM.parseAsync(l).catch(()=>null);if(!d)continue;let f=structuredClone(d);if(n.length)for(let m in d.services){if(n.includes(m))continue;delete d.services[m]}if(!Object.keys(d.services).length)continue;i=!0;for(let[m,h]of Object.entries(d.services))s.push(Cpe({config:{...d,services:{[m]:h}},allServices:f.services,cwd:Yc.dirname(o)}))}if(!i&&!r)await Ape();if(r&&!i)console.log("\u274C No valid json files found");await Promise.all(s)},Ape=async()=>{console.log("\uD83D\uDD52 Creating .deploy.json template...");let e=aM.parse({$schema:"https://raw.githubusercontent.com/chneau/x/refs/heads/master/deployment-schema.json",registries:{dockerhub:{hostname:"docker.io",username:"username",password:"password"}},images:{"my-image":{registry:"dockerhub",repository:"my-repo",imageName:"my-image"}},services:{"my-service":{image:"my-image",file:"kubeconfig",context:"my-context",namespace:"my-namespace",ingress:"nginx",env:{ENV:"value"},endpoints:["my-endpoint.com"]}}}),t=JSON.stringify(e,null,2),n=Bun.file(".deploy.json");if(await n.exists()){console.log("\u274C .deploy.json already exists");return}await n.write(t),console.log("\u2705 Created .deploy.json")},cM=(e,t,n=[])=>{if(n.includes(e.extends))throw Error(`Circular dependency detected: ${n.join(" -> ")} -> ${e.extends}`);let r=[...n,e.extends],i=t[e.extends];if(!i)throw Error(`Service ${e.extends} not found`);let s="extends"in i?cM(i,t,r):structuredClone(i);for(let[o,a]of Object.entries(e)){if(o==="extends")continue;if(o==="env"){s.env={...s.env,...e.env};continue}if(a!==void 0)s[o]=a}return s},Cpe=async({config:e,cwd:t,allServices:n})=>{for(let[r,i]of Object.entries(e.services)){console.log(`\uD83D\uDD52 Deploying ${r}...`);let s="extends"in i?cM(i,n):i,o=e.images[s.image];if(!o){console.error(`\u274C Image ${s.image} not found`);continue}let a=o.registry?e.registries[o.registry]:null;if(!a){console.info(`\u2753 Registry ${o.registry} not found`);continue}if(a.username&&a.password){let{hostname:l,username:d,password:f}=a;if(!gx.has(l))gx.set(l,(async()=>{if(await Ipe(l)){console.log(`\u2705 Already logged in to ${l}`);return}console.log(`\uD83D\uDD11 Logging in to ${l}...`),await Bun.$`echo ${f} | docker login --username ${d} --password-stdin ${l}`,console.log(`... \u2705 Logged in to ${l}`)})());await gx.get(l);let p=`${a.hostname}/${o.repository}/${o.imageName}:${o.tag}`;console.log(`\uD83D\uDD28 Building ${p}...`);let m=Object.entries(o.buildArgs).map(([w,I])=>`--build-arg=${w}=${I}`),h=o.target?[`--target=${o.target}`]:[],g=Yc.resolve(t,o.context),k=Yc.resolve(t,o.dockerfile);await Bun.$`docker build --pull --push --tag=${p} ${h} --file=${k} ${m} .`.cwd(g),console.log(`... \u2705 Built ${p}`)}console.log(`\uD83D\uDD17 Creating deployment for ${r}...`);let u=await oM({serviceAlias:r,registry:a,image:o,service:s,ingress:s.ingress});console.log(`... \u2705 Created deployment for ${r}`),console.log(`\uD83D\uDE80 Deploying ${r}...`);let c={...Bun.env,KUBECONFIG:Yc.join(t,s.file)};await Bun.$`echo ${u} | kubectl --context=${s.context} apply --filename=-`.env(c),console.log(`... \u2705 Deployed ${r}`)}};var{$:Te}=globalThis.Bun;var it={git:{defaultName:"chneau",defaultEmail:"charles63500@gmail.com"},templates:{web:"https://github.com/chneau/bun-orpc-react-template","web-orpc":"https://github.com/chneau/bun-orpc-react-template","web-hono":"https://github.com/chneau/bun-hono-react-template","bun-orpc-react-template":"https://github.com/chneau/bun-orpc-react-template","bun-hono-react-template":"https://github.com/chneau/bun-hono-react-template"},dotfiles:{baseUrl:"https://raw.githubusercontent.com/chneau/dotfiles/HEAD/"},packages:{apt:["git","gcc","make","curl","wget","unzip","zsh","bash","tree"],brew:[{name:"aichat"},{name:"bpytop"},{name:"dive"},{name:"dldash/core/docker-color-output",check:"docker-color-output"},{name:"docker-compose"},{name:"go"},{name:"graphviz",check:"dot"},{name:"helm"},{name:"hyperfine"},{name:"kubecolor"},{name:"kubectx"},{name:"kubernetes-cli",check:"kubectl"},{name:"lazygit"},{name:"node"},{name:"openjdk",check:"javac"},{name:"pipx"},{name:"stern"},{name:"zsh"}],bun:[{name:"@biomejs/biome",check:"biome"},{name:"@github/copilot",check:"copilot"},{name:"@google/gemini-cli",check:"gemini"},{name:"@qwen-code/qwen-code",check:"qwen"},{name:"opencode-ai",check:"opencode"},{name:"concurrently"},{name:"depcheck"},{name:"fkill-cli",check:"fkill"},{name:"http-server"},{name:"live-server"},{name:"nodemon"},{name:"npm-check-updates"},{name:"npm-check"},{name:"oxlint"},{name:"prettier"},{name:"ts-unused-exports"},{name:"tsx"},{name:"typesync"},{name:"ungit"}],custom:[{name:"uv",command:"curl -LsSf https://astral.sh/uv/install.sh | sh"},{name:"brew",env:{CI:"1",HOME:"/tmp"},command:"curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash"},{name:"deno",command:"curl -fsSL https://deno.land/install.sh | sh"},{name:"dotnet",command:"curl -sSL https://dot.net/v1/dotnet-install.sh | bash -s -- --channel 10.0"}],winget:[{name:"Git.Git",check:"git"},{name:"GoLang.Go",check:"go"},{name:"OpenJS.NodeJS",check:"node"},{name:"DenoLand.Deno",check:"deno"},{name:"JesseDuffield.Lazygit",check:"lazygit"},{name:"Microsoft.VisualStudioCode",check:"code"},{name:"Kubernetes.kubectl",check:"kubectl"},{name:"Helm.Helm",check:"helm"},{name:"JanDeDobbeleer.OhMyPosh",check:"oh-my-posh"}]}};var{$:vn}=globalThis.Bun;var dM=K.object({email:K.email(),name:K.string().min(1),updates:K.boolean()}),lM=async(e,t)=>{let n=(await vn`git config --global ${e}`.nothrow().text()).trim();if(n==="")console.log(`\u274C Git ${e} is not set`),console.log(`\uD83D\uDD52 Setting git ${e}`),await vn`git config --global ${e} ${t}`,console.log(`\u2705 Git ${e} set`);else console.log(`\u2705 Git ${e} is already set to "${n}"`)},vh=async(e)=>{await lM("user.name",e.name),await lM("user.email",e.email),await vn`git config --global url."ssh://git@github.com/".insteadOf "https://github.com/"`,await vn`git config --global merge.ff false`,await vn`git config --global pull.ff true`,await vn`git config --global pull.rebase true`,await vn`git config --global core.whitespace "blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol"`,await vn`git config --global fetch.prune true`,console.log("\u2705 Git config checked and updated.")},yh=async()=>{let e=`${Bun.env.HOME||Bun.env.USERPROFILE}/.ssh/id_rsa`;if(await Bun.file(e).exists())console.log("\u2705 SSH key is set");else throw console.log("\u274C SSH key is not set"),console.log(`\u26A1 Please execute this command:
261
261
 
262
262
  ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -P ""`),Error("\u274C SSH key is not set")},_h=async()=>{if(await vn`ssh -T -o "StrictHostKeyChecking no" git@github.com 2>&1`.nothrow().text().then((e)=>e.includes("successfully authenticated")))console.log("\u2705 SSH key is set on GitHub");else if(console.log("\u274C SSH key is not set on GitHub"),console.log("\uD83D\uDD52 Adding SSH key to GitHub"),await Bun.file(`${Bun.env.HOME}/.ssh/id_rsa.pub`).exists()){let e=await Bun.file(`${Bun.env.HOME}/.ssh/id_rsa.pub`).text();console.log(e),console.log("\u26A1 Go to https://github.com/settings/ssh/new and past the text above")}else console.log("\u274C ~/.ssh/id_rsa.pub not found. Please generate SSH key first.")};var{$:Er}=globalThis.Bun;var bh=(e,t,n,r)=>({name:e,type:t,check:()=>nn(r??e),install:n}),Npe=(e)=>bh(e,"apt",()=>Er`sudo apt install -y ${e}`),Dpe=(e,t)=>bh(e,"brew",()=>Er`brew install ${e}`,t),Epe=(e,t)=>bh(e,"bun",()=>Er`bun install --force --global ${e}`,t),Tpe=it.packages.apt.map(Npe),Jpe=it.packages.brew.map((e)=>Dpe(e.name,"check"in e?e.check:void 0)),fM=it.packages.bun.map((e)=>Epe(e.name,"check"in e?e.check:void 0)),Rpe=it.packages.custom.map((e)=>bh(e.name,"custom",()=>{let t=Er`bash -c ${e.command}`;if("env"in e&&e.env)t=t.env({...Bun.env,...e.env});return t},"check"in e?e.check:void 0)),pM=async(e)=>{await Er`sudo apt install -y ${e}`},mM=async(e)=>{await Er`brew install ${e}`},Sh=async(e)=>{await Er`bun install --force --global ${e}`},hM=fM,gM=[...Tpe,...Rpe,...Jpe,...fM];var{$:vx}=globalThis.Bun;var{$:Lpe}=globalThis.Bun;var zpe=(e,t)=>({name:e,type:"winget",check:async()=>await nn(t??e),install:async()=>await Lpe`powershell.exe -Command "winget install --id ${e} -e --source winget --accept-package-agreements --accept-source-agreements"`}),Kpe=it.packages.winget.map((e)=>zpe(e.name,"check"in e?e.check:void 0)),vM=[...Kpe,...hM];var Mpe=async()=>{console.log("\uD83D\uDD52 Updating system (winget upgrade --all)..."),await vx`winget upgrade --all --accept-package-agreements --accept-source-agreements`.nothrow(),console.log("\uD83D\uDD52 Updating Bun..."),await vx`bun upgrade`.nothrow(),await vx`bun update --latest --force --global`.nothrow(),console.log("\u2705 System updated")},Gpe=async()=>{let e=await Promise.all(vM.map(async(t)=>({name:t.name,type:t.type,exists:await t.check(),install:t.install}))).then((t)=>t.filter((n)=>!n.exists));if(!e.length)console.log("\u2705 All packages are installed");else{console.log("\u274C Some packages are not installed"),console.table(e.map((r)=>({name:r.name,type:r.type})));let t=e.filter((r)=>r.type==="winget"),n=e.filter((r)=>r.type==="bun");for(let r of t)console.log(`\uD83D\uDD52 Installing ${r.name} via winget...`),await r.install().then(()=>console.log(`\u2705 Installed ${r.name}`)).catch(()=>console.log(`\u274C Failed to install ${r.name}`));if(n.length>0){let r=n.map((i)=>i.name);console.log(`\uD83D\uDD52 Batch installing bun packages: ${r.join(", ")}...`);try{await Sh(r),console.log(`\u2705 Installed bun packages: ${r.join(", ")}`)}catch{console.log(`\u274C Failed to install some bun packages: ${r.join(", ")}`)}}}},yM=async(e)=>{console.log("\uD83D\uDD0D Running doctor (Windows)..."),console.log("\u2699\uFE0F email =",e.email,", name =",e.name,", updates =",e.updates),await Gpe(),await vh(e);try{await yh(),await _h()}catch(t){console.log(t)}if(e.updates)await Mpe();else console.log("\u26A0\uFE0F Skipping system updates");console.log("\u2139\uFE0F Restart your shell for installed packages to be available.")};if(process.platform!=="win32")Bun.env.PATH=[Bun.env.PATH??"","/home/linuxbrew/.linuxbrew/bin","/home/linuxbrew/.linuxbrew/sbin","$BUN_INSTALL/bin","$HOME/go/bin","$HOME/.arkade/bin","${KREW_ROOT:-$HOME/.krew}/bin","$HOME/.cargo/bin","$HOME/.dotnet","$HOME/.dotnet/tools","$HOME/.go/bin","$HOME/.local/bin","$HOME/bin","/snap/bin","/usr/local/sbin","/usr/sbin","/sbin"].join(":");var qpe=async()=>{if(!await Nx())console.log("\u2705 You are not root");else throw Error("\u274C You are root")},Upe=async()=>{if(await Dx())console.log("\u2705 You can sudo");else throw console.log("\u26A1 Please run this command to configure sudo:"),console.log("sudo sed -i 's/%sudo\\s\\+ALL=(ALL:ALL)\\s\\+ALL/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/g' /etc/sudoers"),Error("\u274C You cannot sudo")},Bpe=async()=>{console.log("\uD83D\uDD52 Updating system..."),await Te`sudo apt update -y`.nothrow(),await Te`sudo apt upgrade -y`.nothrow(),await Te`sudo apt autoremove -y`.nothrow(),await Te`sudo apt autoclean -y`.nothrow();let e=await nn("brew")?"brew":"/home/linuxbrew/.linuxbrew/bin/brew";if(await Bun.file(e).exists())await Te`${e} update`.nothrow(),await Te`${e} upgrade`.nothrow(),await Te`${e} cleanup`.nothrow();await Te`bun upgrade`.nothrow(),await Te`bun update --latest --force --global`.nothrow(),console.log("\u2705 System updated")},Fpe=async()=>{let e=await Promise.all(gM.map(async(s)=>({pkg:s,exists:await s.check()}))).then((s)=>s.filter((o)=>!o.exists).map((o)=>o.pkg));if(e.length===0){console.log("\u2705 All packages are installed");return}console.log("\u274C Some packages are not installed"),console.table(e.map((s)=>({name:s.name,type:s.type})));let t=e.filter((s)=>s.type==="apt"),n=e.filter((s)=>s.type==="brew"),r=e.filter((s)=>s.type==="bun"),i=e.filter((s)=>s.type==="custom");if(t.length>0){let s=t.map((o)=>o.name);console.log(`\uD83D\uDD52 Batch installing apt packages: ${s.join(", ")}...`);try{await pM(s),console.log(`\u2705 Installed apt packages: ${s.join(", ")}`)}catch{console.log(`\u274C Failed to install some apt packages: ${s.join(", ")}`)}}if(n.length>0){let s=n.map((o)=>o.name);console.log(`\uD83D\uDD52 Batch installing brew packages: ${s.join(", ")}...`);try{await mM(s),console.log(`\u2705 Installed brew packages: ${s.join(", ")}`)}catch{console.log(`\u274C Failed to install some brew packages: ${s.join(", ")}`)}}if(r.length>0){let s=r.map((o)=>o.name);console.log(`\uD83D\uDD52 Batch installing bun packages: ${s.join(", ")}...`);try{await Sh(s),console.log(`\u2705 Installed bun packages: ${s.join(", ")}`)}catch{console.log(`\u274C Failed to install some bun packages: ${s.join(", ")}`)}}for(let s of i)console.log(`\uD83D\uDD52 Installing custom package ${s.name}...`),await s.install().then(()=>console.log(`\u2705 Installed ${s.name}`)).catch(()=>console.log(`\u274C Failed to install ${s.name}`))},$h=async(e,t,n)=>{if(await t())console.log(`\u2705 ${e} is correct`);else console.log(`\u274C ${e} is incorrect`),console.log(`\uD83D\uDD52 Fixing ${e}...`),await n(),console.log(`\u2705 ${e} is fixed`)},Zpe=async()=>{let e=it.dotfiles.baseUrl,n=await Promise.all([".bashrc",".zshrc",".aliases",".profile"].map(async(r)=>({name:r,isPresent:await Bun.file(`${Bun.env.HOME}/${r}`).exists()})));if(n.every((r)=>r.isPresent)){console.log("\u2705 Dotfiles are installed");return}console.log("\u274C Dotfiles are not installed"),console.log("\uD83D\uDD52 Installing dotfiles"),await Promise.all(n.filter((r)=>!r.isPresent).map(async(r)=>{console.log(`\uD83D\uDD52 Installing ${r.name}`);let i=await fetch(`${e}${r.name}`).then((s)=>s.text());await Bun.write(`${Bun.env.HOME}/${r.name}`,i),console.log(`\u2705 Installed ${r.name}`)})),console.log("\u2705 Dotfiles are installed")},jpe=()=>$h("Docker",()=>nn("docker"),()=>Te`curl -sSL get.docker.com | sh`),Hpe=()=>$h("User in docker group",async()=>(await Te`groups`.text()).includes("docker"),()=>Te`sudo usermod -aG docker $USER`.nothrow()),Wpe=async()=>{let e=(await Te`which zsh`.text()).trim();await $h("Zsh is set as a valid shell",async()=>(await Bun.file("/etc/shells").text()).includes(e),()=>Te`echo ${e} | sudo tee -a /etc/shells`),await $h("Zsh is set as your shell",async()=>(await Te`cat /etc/passwd | grep "^$USER:"`.text()).includes(e),()=>Te`sudo chsh -s ${e} $USER`)},Ype=async(e)=>{if(console.log("\uD83D\uDD0D Running doctor (Linux)..."),console.log("\u2699\uFE0F email =",e.email,", name =",e.name,", updates =",e.updates),await Promise.all([qpe(),Upe()]),await Promise.all([Zpe(),Fpe().then(()=>Promise.all([vh(e).then(yh).then(_h),Wpe(),jpe().then(Hpe)]))]),e.updates)await Bpe();else console.log("\u26A0\uFE0F Skipping system updates")},_M=async(e)=>{if(e=dM.parse(e),process.platform==="win32")await yM(e);else await Ype(e)};var{$:yx}=globalThis.Bun;var bM=async()=>void await Promise.all([yx`deno fmt --use-tabs --quiet; oxlint --fix-dangerously --quiet; biome check --write --unsafe .`.nothrow(),yx`go fmt ./...`.nothrow(),yx`dotnet csharpier .`.nothrow()]);var{$:Zn}=globalThis.Bun;var M={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",green:"\x1B[32m",yellow:"\x1B[33m",red:"\x1B[31m",cyan:"\x1B[36m",gray:"\x1B[90m",magenta:"\x1B[35m"},$M=(e)=>e.replace(/\x1b\[[0-9;]*m/g,""),st=(e,t)=>{let n=$M(e).length,r=Math.max(0,t-n);return e+" ".repeat(r)},SM=(e)=>{switch(e){case"pending":return`${M.gray}\u23F3 pending${M.reset}`;case"running":return`${M.yellow}\uD83D\uDD04 checking...${M.reset}`;case"success":return`${M.green}\u2705 pass${M.reset}`;case"error":return`${M.red}\u274C fail${M.reset}`;case"skipped":return`${M.gray}\u23ED\uFE0F skipped${M.reset}`}},wM=async(e,t)=>{if((await Zn`which helm`.quiet().nothrow()).exitCode!==0)console.error("\u274C helm command not found in PATH"),process.exit(1);let r=(await Zn`kubectl config current-context`.text().catch(()=>"unknown")).trim();console.log(`${M.bold}\u2638\uFE0F Helm Chart Manager [Context: ${M.cyan}${r}${M.reset}${M.bold}]${M.reset}
263
263
  `);let[i]=await Promise.all([Zn`helm list -A -o json`.text().catch(()=>"[]"),Zn`helm repo update`.quiet().nothrow().catch(()=>null)]),s=[];try{s=JSON.parse(i)}catch{console.error("\u274C Failed to parse helm releases output"),process.exit(1)}if(!s||s.length===0){console.log(`\u2139\uFE0F No Helm releases found in current context (${r}).`);return}if(e&&e.length>0){if(s=s.filter((f)=>e.includes(f.name)||e.includes(`${f.namespace}/${f.name}`)),s.length===0){console.log(`\u2139\uFE0F No matching releases found for filter: ${e.join(", ")}`);return}}let o=[];for(let f of s){let p=f.chart,m=p.match(/^(.*?)-(v?[0-9].*)$/),h=m?.[1]?m[1]:p,g=m?.[2]?m[2]:"";o.push({name:f.name,namespace:f.namespace,currentChart:p,currentVersion:g,targetChart:h,targetVersion:"...",clientDryRun:"pending",serverDryRun:"pending",upgradeStatus:"pending"})}console.log(`${M.yellow}\uD83D\uDD0D Checking charts asynchronously...${M.reset}