infra-kit 0.1.72 → 0.1.75
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.js +33 -16
- package/dist/cli.js.map +4 -4
- package/dist/mcp.js +29 -19
- package/dist/mcp.js.map +4 -4
- package/package.json +5 -5
- package/src/commands/doctor/doctor.ts +105 -0
- package/src/commands/doctor/index.ts +1 -0
- package/src/commands/env-clear/env-clear.ts +91 -0
- package/src/commands/env-clear/index.ts +1 -0
- package/src/commands/env-init/env-init.ts +83 -0
- package/src/commands/env-init/index.ts +1 -0
- package/src/commands/env-list/env-list.ts +50 -0
- package/src/commands/env-list/index.ts +1 -0
- package/src/commands/env-load/env-load.ts +120 -0
- package/src/commands/env-load/index.ts +1 -0
- package/src/commands/env-status/env-status.ts +103 -0
- package/src/commands/env-status/index.ts +1 -0
- package/src/entry/cli.ts +49 -7
- package/src/entry/mcp.ts +0 -5
- package/src/integrations/doppler/doppler-cli-auth.ts +25 -0
- package/src/integrations/doppler/doppler-project.ts +23 -0
- package/src/integrations/doppler/index.ts +2 -0
- package/src/lib/constants.ts +39 -0
- package/src/lib/logger/index.ts +1 -0
- package/src/mcp/tools/index.ts +8 -0
- package/src/integrations/acli/acli-auth/acli-auth.ts +0 -25
- package/src/integrations/acli/acli-auth/index.ts +0 -1
- package/src/integrations/acli/index.ts +0 -1
- package/src/lib/load-env/index.ts +0 -1
- package/src/lib/load-env/load-env.ts +0 -27
package/dist/cli.js
CHANGED
|
@@ -1,21 +1,38 @@
|
|
|
1
|
-
import{Command as
|
|
2
|
-
|
|
1
|
+
import{Command as Yt}from"commander";import{z as O}from"zod";import{$ as hr}from"zx";import dr from"node:process";import ur from"pino";import fr from"pino-pretty";var gr=()=>{let e=dr.argv.includes("--debug")?"debug":"info",t=["time","pid","hostname"];return e==="debug"&&t.push("level"),ur({level:e},fr({destination:2,ignore:t.join(","),colorize:!0}))},r=gr();var Z=async(e,t,o,n)=>{try{return await hr`${t}`,{name:e,status:"pass",message:o}}catch{return{name:e,status:"fail",message:n}}},ee=async()=>{let e=await Promise.all([Z("gh installed",["gh","--version"],"GitHub CLI is installed","GitHub CLI is not installed. Install from: https://cli.github.com/"),Z("gh authenticated",["gh","auth","status"],"GitHub CLI is authenticated","GitHub CLI is not authenticated. Run: gh auth login"),Z("doppler installed",["doppler","--version"],"Doppler CLI is installed","Doppler CLI is not installed. Install from: https://docs.doppler.com/docs/install-cli"),Z("doppler authenticated",["doppler","me"],"Doppler CLI is authenticated","Doppler CLI is not authenticated. Run: doppler login")]);r.info(`Doctor check results:
|
|
2
|
+
`);for(let o of e){let n=o.status==="pass"?"[PASS]":"[FAIL]";r.info(` ${n} ${o.name}: ${o.message}`)}let t={checks:e.map(o=>({name:o.name,status:o.status,message:o.message})),allPassed:e.every(o=>o.status==="pass")};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:t}},vr={name:"doctor",description:"Check installation and authentication status of gh and doppler CLIs",inputSchema:{},outputSchema:{checks:O.array(O.object({name:O.string().describe("Name of the check"),status:O.enum(["pass","fail"]).describe("Check result"),message:O.string().describe("Details about the check result")})).describe("List of all check results"),allPassed:O.boolean().describe("Whether all checks passed")},handler:ee};import te from"node:fs";import He from"node:path";import Rr from"node:process";import{z as Ee}from"zod";import ze from"node:fs";import yr from"node:path";import wr from"node:process";var w=["dev","arthur","renana","roman","eliran","oriana"],$e={"hulyo-monorepo":"hulyo","travelist-monorepo":"travelist"},br="./node_modules/.cache/infra-kit",J="env-load.env",Ke="env-clear.sh",Se="INFRA_KIT_SESSION",L="INFRA_KIT_ENV_CONFIG",j="INFRA_KIT_ENV_PROJECT",V="INFRA_KIT_ENV_LOADED_AT",re=e=>ze.existsSync(e)?ze.readFileSync(e,"utf-8").split(`
|
|
3
|
+
`).filter(o=>o.includes("=")&&!o.startsWith("set ")).map(o=>o.split("=")[0]):[],F=()=>{let e=wr.env[Se];if(!e)throw new Error("INFRA_KIT_SESSION is not set. Run `source ~/.zshrc` or `infra-kit env-init` first.");return yr.join(br,e)},W="-worktrees";var oe=async()=>{let e=F(),t=He.join(e,J);if(!te.existsSync(t))return r.error("No loaded environment found. Run `env-load` first."),{content:[{type:"text",text:"No loaded environment found. Run `env-load` first."}]};let o=re(t),n=[...o.map(l=>`unset ${l}`),`unset ${L}`,`unset ${j}`,`unset ${V}`],s=He.resolve(e,Ke);te.mkdirSync(e,{recursive:!0}),te.writeFileSync(s,`${n.join(`
|
|
4
|
+
`)}
|
|
5
|
+
`),Rr.stdout.write(`${s}
|
|
6
|
+
`),te.unlinkSync(t),r.info(`Cleared ${o.length} environment variables`);let a={variableCount:o.length,unsetStatements:n};return{content:[{type:"text",text:JSON.stringify(a,null,2)}],structuredContent:a}},kr={name:"env-clear",description:'Clear previously loaded environment variables. Usage: env-clear (after running eval "$(infra-kit env-init)" in shell)',inputSchema:{},outputSchema:{variableCount:Ee.number().describe("Number of variables cleared"),unsetStatements:Ee.array(Ee.string()).describe("Unset statements generated")},handler:oe};import U from"node:fs";import xr from"node:os";import se from"node:path";import Cr from"node:process";var Xe="# infra-kit shell functions",Te=async()=>{let e=se.join(xr.homedir(),".zshrc"),t=$r();if(!U.existsSync(t)){r.error(`Could not find infra-kit binary at ${t}`);return}let o=Tr(t);if(U.existsSync(e)){let n=U.readFileSync(e,"utf-8"),s=Er(n);U.writeFileSync(e,s)}U.appendFileSync(e,`
|
|
7
|
+
${o}
|
|
8
|
+
`),r.info(`Added infra-kit shell functions to ${e}`),r.info("Run `source ~/.zshrc` or open a new terminal to activate.")},$r=()=>se.resolve(se.join(se.dirname(Cr.argv[1]),"cli.js")),Sr=e=>e.startsWith("#")||e.startsWith("env-load")||e.startsWith("env-clear")||e.startsWith("if ")||e.startsWith(" export INFRA_KIT_SESSION")||e.startsWith("fi"),Er=e=>{let t=e.indexOf(Xe);if(t===-1)return e;let o=e.slice(0,t).replace(/\n+$/,""),n=e.slice(t).split(`
|
|
9
|
+
`),s=0;for(;s<n.length&&Sr(n[s]);)s++;let a=n.slice(s).join(`
|
|
10
|
+
`);return o+(a?`
|
|
11
|
+
${a}`:"")},Tr=e=>{let t=`node ${e}`;return[Xe,'if [[ -z "${INFRA_KIT_SESSION}" ]]; then'," export INFRA_KIT_SESSION=$(head -c 4 /dev/urandom | xxd -p)","fi",`env-load() { local f; f=$(${t} env-load "$@") && source "$f"; }`,`env-clear() { local f; f=$(${t} env-clear) && source "$f"; }`].join(`
|
|
12
|
+
`)};import{z as Ae}from"zod";import Ye from"node:process";import{$ as Qe}from"zx";var _=async()=>{try{await Qe`doppler --version`}catch(e){r.error({error:e},"Error: Doppler CLI is not installed."),r.error("Please install it from: https://docs.doppler.com/docs/install-cli"),Ye.exit(1)}try{await Qe`doppler me`}catch(e){r.error({error:e},"Error: Doppler CLI is not authenticated."),r.error("Please authenticate by running: doppler login"),Ye.exit(1)}};import Pr from"node:path";import{$ as Ze}from"zx";var S=async e=>{let o=(await Ze`git worktree list`).stdout.split(`
|
|
13
|
+
`).filter(Boolean),n={release:Ar,feature:Ir};return o.map(n[e]).filter(s=>s!==null)},Ar=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("release/v")?null:`release/${t[0]?.split("/").pop()||""}`},Ir=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("feature/")?null:`feature/${t[0]?.split("/").pop()||""}`},R=async()=>(await Ze`git rev-parse --show-toplevel`).stdout.trim();var D=async()=>{let e=await R(),t=Pr.basename(e),o=$e[t];if(!o)throw new Error(`Could not determine Doppler project for directory "${t}". Expected one of: ${Object.keys($e).join(", ")}`);return o};var ne=async()=>{await _();let e=await D();r.info(`Doppler Project: ${e}
|
|
14
|
+
`),r.info("Available Configs:");for(let o of w)r.info(` - ${o}`);let t={project:e,configs:w};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:t}},Nr={name:"env-list",description:"List available Doppler configs for the detected project",inputSchema:{},outputSchema:{project:Ae.string().describe("Detected Doppler project name"),configs:Ae.array(Ae.string()).describe("Available environment configs")},handler:ne};import Dr from"@inquirer/select";import er from"node:fs";import Or from"node:path";import Jr from"node:process";import{z as ie}from"zod";import{$ as Ie}from"zx";var _r=()=>{let e="",t=[],o=!1;return{start(n){e=n,t=[],o=!1},setInteractive(){o=!0},addOption(n,s){t.push({flag:n,value:s})},print(){if(!o||t.length===0)return;let n=t.map(s=>typeof s.value=="boolean"?s.value?s.flag:"":Array.isArray(s.value)?`${s.flag} "${s.value.join(", ")}"`:`${s.flag} ${s.value}`).filter(Boolean).join(" ");r.info(""),r.info("# Equivalent command:"),r.info(`pnpm exec infra-kit ${e} ${n}`)},reset(){e="",t=[],o=!1}}},i=_r();var ae=async e=>{await _();let{config:t,quiet:o}=e;i.start("env-load");let n="";t?n=t:(i.setInteractive(),n=await Dr({message:"Select environment config",choices:w.map(f=>({name:f,value:f}))})),i.addOption("--config",n);let s=await D();Ie.quiet=!0;let a=await Ie`doppler secrets download --no-file --format env --project ${s} --config ${n}`;Ie.quiet=!1;let l=a.stdout.trim(),c=new Date().toISOString(),m=["set -a",l,`${L}=${n}`,`${j}=${s}`,`${V}=${c}`,"set +a"],p=F(),u=Or.resolve(p,J);er.mkdirSync(p,{recursive:!0}),er.writeFileSync(u,`${m.join(`
|
|
15
|
+
`)}
|
|
16
|
+
`),Jr.stdout.write(`${u}
|
|
17
|
+
`);let d=l.split(`
|
|
18
|
+
`).filter(f=>f.includes("=")).length;o||r.info(`Loaded ${d} variables from ${s}/${n}`);let h={variableCount:d,project:s,config:n};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}},Lr={name:"env-load",description:'Load environment variables from Doppler for a given config. Usage: env-load -c dev (after running eval "$(infra-kit env-init)" in shell)',inputSchema:{config:ie.string().describe("Environment config name to load (e.g. dev, arthur, renana)")},outputSchema:{variableCount:ie.number().describe("Number of variables loaded"),project:ie.string().describe("Doppler project name"),config:ie.string().describe("Doppler config name")},handler:ae};import jr from"node:path";import G from"node:process";import{z as E}from"zod";var ce=async()=>{await _();let e=await D();r.info(`Doppler Environment Status:
|
|
19
|
+
`),r.info(" Authenticated: yes"),r.info(` Detected Project: ${e}`),r.info(` Available Configs: ${w.join(", ")}`);let t=F(),o=G.env[Se],n=jr.join(t,J),s=0,a=0,l=G.env[L]??null,c=G.env[j]??null,m=G.env[V]??null;if(l){let u=re(n);u.length>0&&(a=u.length,s=u.filter(d=>d in G.env).length),r.info(` Session: ${s} of ${a} vars loaded (project: ${c}, config: ${l}, loaded at: ${m})`),r.info(` Session ID: ${o}`)}else r.info(" Session: no env loaded");let p={authenticated:!0,project:e,configs:w,sessionId:o,sessionLoadedCount:s,sessionTotalCount:a,sessionConfig:l,sessionProject:c,sessionLoadedAt:m};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}},Vr={name:"env-status",description:"Show Doppler authentication status and detected project info",inputSchema:{},outputSchema:{authenticated:E.boolean().describe("Whether the user is authenticated"),project:E.string().describe("Detected Doppler project name"),configs:E.array(E.string()).describe("Available environment configs"),sessionId:E.string().describe("Current terminal session ID"),sessionLoadedCount:E.number().describe("Number of cached vars active in the current session"),sessionTotalCount:E.number().describe("Total number of cached var names"),sessionConfig:E.string().nullable().describe("Doppler config name of the loaded session"),sessionProject:E.string().nullable().describe("Doppler project name of the loaded session"),sessionLoadedAt:E.string().nullable().describe("ISO 8601 timestamp of when the env was loaded")},handler:ce};import Wr from"@inquirer/checkbox";import Mr from"@inquirer/confirm";import Br from"node:process";import{z as M}from"zod";import{$}from"zx";import{$ as Ts}from"zx";import rr from"node:process";import{$ as C}from"zx";var Pe=e=>e.replace("release/","").slice(1).split(".").map(Number),Ne=e=>[...e].sort((t,o)=>{let[n,s,a]=Pe(t),[l,c,m]=Pe(o);return n!==l?(n??0)-(l??0):s!==c?(s??0)-(c??0):(a??0)-(m??0)});var y=async()=>{try{let e=await C`gh pr list --search "Release in:title" --base dev --json number,title,headRefName,state,baseRefName`,t=JSON.parse(e.stdout);t.length===0&&(r.error("\u274C No release PRs found. Check the project folder for the script. Exiting..."),rr.exit(1));let o=t.map(n=>n.headRefName);return Ne(o)}catch(e){r.error({error:e},"\u274C Error fetching release PRs"),rr.exit(1)}},le=async e=>{let{version:t,jiraVersionUrl:o}=e,n=`release/v${t}`;try{C.quiet=!0,await C`git switch dev`,await C`git pull origin dev`,await C`git checkout -b ${n}`,await C`git push -u origin ${n}`,await C`git commit --allow-empty-message --allow-empty --message ''`,await C`git push origin ${n}`;let a=(await C`gh pr create --title "Release v${t}" --body "${o} \n" --base dev --head ${n}`).stdout.trim();return await C`git switch dev`,C.quiet=!1,{branchName:n,prUrl:a}}catch(s){throw r.error({error:s,branchName:n},`Error creating release branch ${n}`),s}};var pe=async e=>{let{all:t,confirmedCommand:o}=e;i.start("merge-dev");let n=await y();if(n.length===0)return r.info("\u2139\uFE0F No open release branches found"),i.print(),{content:[{type:"text",text:JSON.stringify({successfulMerges:0,failedMerges:0,failedBranches:[],totalBranches:0},null,2)}],structuredContent:{successfulMerges:0,failedMerges:0,failedBranches:[],totalBranches:0}};let s=[];t?s=n:(i.setInteractive(),s=await Wr({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(p=>({name:p.replace("release/v",""),value:p}))}));let a=s.length===n.length;a?i.addOption("--all",!0):i.addOption("--branches",s);let l=o?!0:await Mr({message:`Are you sure you want to merge dev into these branches: ${s.join(", ")}?`});o||i.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),Br.exit(0)),a&&i.addOption("--yes",!0),$.quiet=!0,await $`git fetch origin`,await $`git switch dev`,await $`git pull origin dev`;let c=[];for(let p of s)await qr(p)||c.push(p);if($.quiet=!1,c.length>0){r.info(`
|
|
20
|
+
\u26A0\uFE0F ${c.length} branch(es) failed to merge automatically.
|
|
3
21
|
`),r.info(`\u{1F4CB} Manual merge script for failed branches:
|
|
4
|
-
`),r.info("```bash");for(let
|
|
5
|
-
`);throw new Error(l)}let c=Number.parseInt(s,10);if(Number.isNaN(c))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${s}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:o,projectId:c,email:i}},le=async()=>{try{return await I()}catch(e){return r.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var G=async e=>{let{version:o,confirmedCommand:s}=e;n.start("release-deliver");let i=await h(),t="";o?t=`release/v${o}`:(n.setInteractive(),t=await Ye({message:"\u{1F33F} Select release branch",choices:i.map(a=>({name:a.replace("release/v",""),value:a}))}));let c=t.replace("release/v","");n.addOption("--version",c),i.includes(t)||(r.error(`\u274C Release branch ${t} not found in open PRs. Exiting...`),me.exit(1));let l=s?!0:await Xe({message:`Are you sure you want to deliver version ${t} to production?`});s||n.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),me.exit(0)),n.addOption("--yes",!0);try{T.quiet=!0,await T`gh pr merge ${t} --squash --admin --delete-branch`,await T`gh pr create --base main --head dev --title "Release v${t.replace("release/v","")} (RC)" --body ""`,await T`gh pr merge dev --squash --admin`,T.quiet=!1,await T`gh workflow run deploy-all.yml --ref main -f environment=prod`,T.quiet=!0,await T`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`,T.quiet=!1;let a=await le();if(a)try{let m=t.replace("release/","");await ce({versionName:m},a)}catch(m){r.error({error:m},"Failed to deliver Jira release (non-blocking)")}else r.info("\u{1F514} Jira is not configured, skipping Jira release delivery");r.info(`Successfully delivered ${t} to production!`),n.print();let p={releaseBranch:t,version:t.replace("release/v",""),success:!0};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}}catch(a){r.error({error:a},"\u274C Error merging release branch into dev"),me.exit(1)}},Qe={name:"gh-release-deliver",description:"Deliver a release branch to production",inputSchema:{version:F.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:F.string().describe("The release branch that was delivered"),version:F.string().describe("The version that was delivered"),success:F.boolean().describe("Whether the delivery was successful")},handler:G};import Ce from"@inquirer/select";import pe from"node:process";import{z as A}from"zod";import{$ as de}from"zx";var E=["dev","arthur","renana","roman","eliran","oriana"],D="-worktrees";var z=async e=>{let{version:o,env:s,skipTerraform:i}=e;n.start("release-deploy-all");let t=["dev"],c=await h();t.push(...c);let l="";o?l=o==="dev"?"dev":`release/v${o}`:(n.setInteractive(),l=await Ce({message:"\u{1F33F} Select release branch",choices:t.map(u=>({name:u.replace("release/v",""),value:u}))}));let a=l==="dev"?"dev":l.replace("release/v","");n.addOption("--version",a),t.includes(l)||(r.error(`\u274C Release branch ${l} not found in open PRs. Exiting...`),pe.exit(1));let p="";s?p=s:(n.setInteractive(),p=await Ce({message:"\u{1F9EA} Select environment",choices:E.map(u=>({name:u,value:u}))})),n.addOption("--env",p),E.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),pe.exit(1));let m=i??!1;m&&n.addOption("--skip-terraform",!0);try{de.quiet=!0,await de`gh workflow run deploy-all.yml --ref ${l} -f environment=${p} ${m?["-f","skip_terraform_deploy=true"]:[]}`,de.quiet=!1,r.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${l} and environment: ${p}`),n.print();let d={releaseBranch:l,version:l.replace("release/v",""),environment:p,skipTerraformDeploy:m,success:!0};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(u){r.error({error:u},"\u274C Error launching workflow"),pe.exit(1)}},Ze={name:"gh-release-deploy-all",description:"Deploy a release branch to a specified environment",inputSchema:{version:A.string().describe('Version to deploy (e.g., "1.2.5")'),env:A.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),skipTerraform:A.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:A.string().describe("The release branch that was deployed"),version:A.string().describe("The version that was deployed"),environment:A.string().describe("The environment deployed to"),skipTerraformDeploy:A.boolean().describe("Whether terraform deployment was skipped"),success:A.boolean().describe("Whether the deployment was successful")},handler:z};import tr from"@inquirer/checkbox";import Te from"@inquirer/select";import or from"node:fs/promises";import{resolve as sr}from"node:path";import N from"node:process";import ir from"yaml";import{z as k}from"zod";import{$ as ue}from"zx";import{$ as Se}from"zx";var C=async e=>{let s=(await Se`git worktree list`).stdout.split(`
|
|
6
|
-
`).filter(Boolean),i={release:er,feature:rr};return s.map(i[e]).filter(t=>t!==null)},er=e=>{let o=e.split(" ").filter(Boolean);return o.length<3||!o[0]?.includes("release/v")?null:`release/${o[0]?.split("/").pop()||""}`},rr=e=>{let o=e.split(" ").filter(Boolean);return o.length<3||!o[0]?.includes("feature/")?null:`feature/${o[0]?.split("/").pop()||""}`},w=async()=>(await Se`git rev-parse --show-toplevel`).stdout.trim();var H=async e=>{let{version:o,env:s,services:i,skipTerraform:t}=e;n.start("release-deploy-selected");let c=["dev"],l=await h();c.push(...l);let a="";o?a=o==="dev"?"dev":`release/v${o}`:(n.setInteractive(),a=await Te({message:"\u{1F33F} Select release branch",choices:c.map(g=>({name:g.replace("release/v",""),value:g}))}));let p=a==="dev"?"dev":a.replace("release/v","");n.addOption("--version",p),c.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),N.exit(1));let m="";s?m=s:(n.setInteractive(),m=await Te({message:"\u{1F9EA} Select environment",choices:E.map(g=>({name:g,value:g}))})),n.addOption("--env",m),E.includes(m)||(r.error(`\u274C Invalid environment: ${m}. Exiting...`),N.exit(1));let u=await nr();u.length===0&&(r.error("\u274C No services found in workflow file. Exiting..."),N.exit(1));let d=[];i&&i.length>0?d=i:(n.setInteractive(),d=await tr({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:u.map(g=>({name:g,value:g}))})),n.addOption("--services",d),d.length===0&&(r.error("\u274C No services selected. Exiting..."),N.exit(1));let v=d.filter(g=>!u.includes(g));v.length>0&&(r.error(`\u274C Invalid services: ${v.join(", ")}. Available services: ${u.join(", ")}`),N.exit(1));let f=t??!1;f&&n.addOption("--skip-terraform",!0);try{ue.quiet=!0;let g=d.flatMap(je=>["-f",`${je}=true`]);await ue`gh workflow run deploy-selected-services.yml --ref ${a} -f environment=${m} ${g} ${f?["-f","skip_terraform_deploy=true"]:[]}`,ue.quiet=!1,r.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${a}, environment: ${m}, services: ${d.join(", ")}`),n.print();let Re={releaseBranch:a,version:a.replace("release/v",""),environment:m,services:d,skipTerraformDeploy:f,success:!0};return{content:[{type:"text",text:JSON.stringify(Re,null,2)}],structuredContent:Re}}catch(g){r.error({error:g},"\u274C Error launching workflow"),N.exit(1)}},nr=async()=>{let e=await w(),o=sr(e,".github/workflows/deploy-selected-services.yml"),s=await or.readFile(o,"utf-8"),t=ir.parse(s).on.workflow_dispatch.inputs,c=[];for(let[l,a]of Object.entries(t))a.type==="boolean"&&l!=="skip_terraform_deploy"&&c.push(l);return c},ar={name:"gh-release-deploy-selected",description:"Deploy selected services from a release branch to a specified environment",inputSchema:{version:k.string().describe('Version to deploy (e.g., "1.2.5")'),env:k.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),services:k.array(k.string()).describe('List of services to deploy (e.g., ["client-be", "client-fe"])'),skipTerraform:k.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:k.string().describe("The release branch that was deployed"),version:k.string().describe("The version that was deployed"),environment:k.string().describe("The environment deployed to"),services:k.array(k.string()).describe("The services that were deployed"),skipTerraformDeploy:k.boolean().describe("Whether terraform deployment was skipped"),success:k.boolean().describe("Whether the deployment was successful")},handler:H};import fe from"@inquirer/select";import cr from"node:fs/promises";import{resolve as lr}from"node:path";import K from"node:process";import mr from"yaml";import{z as S}from"zod";import{$ as ge}from"zx";var X=async e=>{let{version:o,env:s,service:i,skipTerraform:t}=e;n.start("release-deploy-service");let c=["dev"],l=await h();c.push(...l);let a="";o?a=o==="dev"?"dev":`release/v${o}`:(n.setInteractive(),a=await fe({message:"\u{1F33F} Select release branch",choices:c.map(f=>({name:f.replace("release/v",""),value:f}))}));let p=a==="dev"?"dev":a.replace("release/v","");n.addOption("--version",p),c.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),K.exit(1));let m="";s?m=s:(n.setInteractive(),m=await fe({message:"\u{1F9EA} Select environment",choices:E.map(f=>({name:f,value:f}))})),n.addOption("--env",m),E.includes(m)||(r.error(`\u274C Invalid environment: ${m}. Exiting...`),K.exit(1));let u=await pr(),d="";i?d=i:(n.setInteractive(),d=await fe({message:"\u{1F680} Select service to deploy",choices:u.map(f=>({name:f,value:f}))})),n.addOption("--service",d),u.includes(d)||(r.error(`\u274C Invalid service: ${d}. Available services: ${u.join(", ")}`),K.exit(1));let v=t??!1;v&&n.addOption("--skip-terraform",!0);try{ge.quiet=!0,await ge`gh workflow run deploy-single-service.yml --ref ${a} -f environment=${m} -f service=${d} ${v?["-f","skip_terraform_deploy=true"]:[]}`,ge.quiet=!1,r.info(`Successfully launched deploy-single-service workflow_dispatch for release branch: ${a}, environment: ${m}, service: ${d}`),n.print();let g={releaseBranch:a,version:a.replace("release/v",""),environment:m,service:d,skipTerraformDeploy:v,success:!0};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(f){r.error({error:f},"\u274C Error launching workflow"),K.exit(1)}},pr=async()=>{let e=await w(),o=lr(e,".github/workflows/deploy-single-service.yml"),s=await cr.readFile(o,"utf-8");return mr.parse(s).on.workflow_dispatch.inputs.service.options},dr={name:"gh-release-deploy-service",description:"Deploy a specific service in a release branch to a specified environment",inputSchema:{version:S.string().describe('Version to deploy (e.g., "1.2.5")'),env:S.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),service:S.string().describe('Service to deploy (e.g., "client-be", "client-fe")'),skipTerraform:S.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:S.string().describe("The release branch that was deployed"),version:S.string().describe("The version that was deployed"),environment:S.string().describe("The environment deployed to"),service:S.string().describe("The service that was deployed"),skipTerraformDeploy:S.boolean().describe("Whether terraform deployment was skipped"),success:S.boolean().describe("Whether the deployment was successful")},handler:X};import{z as he}from"zod";var Y=async()=>{let o=(await h()).map(i=>i.replace("release/",""));r.info(`All release branches:
|
|
22
|
+
`),r.info("```bash");for(let p of c)r.info(`# Phase #1: Merge dev into ${p}`),r.info(`git switch ${p} && git pull origin ${p} && git merge origin/dev`),r.info("# Phase #2:Resolve conflicts if any, then:"),r.info(`git push origin ${p} && git switch dev`);r.info(`\u2705 ${s.length-c.length}/${s.length} merges completed successfully.`)}else r.info("\u2705 All merges completed successfully!");i.print();let m={successfulMerges:s.length-c.length,failedMerges:c.length,failedBranches:c,totalBranches:s.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},qr=async e=>{try{return await $`git switch ${e}`,await $`git pull origin ${e}`,await $`git merge origin/dev --no-edit`,await $`git push origin ${e}`,await $`git switch dev`,r.info(`Successfully merged dev into ${e}`),!0}catch(t){return r.error({error:t,branch:e},`Error merging dev into ${e}`),await $`git reset --merge HEAD~1`,!1}},Ur={name:"gh-merge-dev",description:"Merge dev branch into selected release branches",inputSchema:{all:M.boolean().describe("Merge dev into all release branches without prompting")},outputSchema:{successfulMerges:M.number().describe("Number of successful merges"),failedMerges:M.number().describe("Number of failed merges"),failedBranches:M.array(M.string()).describe("List of branches that failed to merge"),totalBranches:M.number().describe("Total number of branches processed")},handler:pe};import Hr from"@inquirer/confirm";import Xr from"@inquirer/select";import Je from"node:process";import{z as me}from"zod";import{$ as A}from"zx";import z from"node:process";var _e=async(e,t)=>{try{let{baseUrl:o,token:n,email:s,projectId:a}=t,l={name:e.name,projectId:e.projectId||a,description:e.description||"",released:e.released||!1,archived:e.archived||!1},c=`${o}/rest/api/3/version`,m=btoa(`${s}:${n}`),p=await fetch(c,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${m}`},body:JSON.stringify(l)});if(!p.ok){let d=await p.text();throw r.error({status:p.status,statusText:p.statusText,error:d},"Failed to create Jira version"),new Error(`HTTP ${p.status}: ${p.statusText}`)}return{success:!0,version:await p.json()}}catch(o){throw r.error({error:o},"Error creating Jira version"),o}},Gr=async e=>{try{let{baseUrl:t,token:o,email:n,projectId:s}=e,a=`${t}/rest/api/3/project/${s}/versions`,l=btoa(`${n}:${o}`),c=await fetch(a,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${l}`}});if(!c.ok){let p=await c.text();throw r.error({status:c.status,statusText:c.statusText,error:p},"Failed to get Jira project versions"),new Error(`HTTP ${c.status}: ${c.statusText}`)}return await c.json()}catch(t){throw r.error({error:t},"Error getting Jira project versions"),t}},zr=async(e,t)=>{try{return(await Gr(t)).find(s=>s.name===e)||null}catch(o){throw r.error({error:o,versionName:e},"Error finding Jira version by name"),o}},Kr=async(e,t)=>{try{let{baseUrl:o,token:n,email:s}=t,a={released:e.released??!0,archived:e.archived??!1};e.releaseDate?a.releaseDate=e.releaseDate:e.released!==!1&&(a.releaseDate=new Date().toISOString().split("T")[0]),e.description!==void 0&&(a.description=e.description);let l=`${o}/rest/api/3/version/${e.versionId}`,c=btoa(`${s}:${n}`),m=await fetch(l,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${c}`},body:JSON.stringify(a)});if(!m.ok){let u=await m.text();throw r.error({status:m.status,statusText:m.statusText,error:u},"Failed to update Jira version"),new Error(`HTTP ${m.status}: ${m.statusText}`)}return{success:!0,version:await m.json()}}catch(o){throw r.error({error:o},"Error updating Jira version"),o}},De=async(e,t)=>{try{let{versionName:o}=e,n=await zr(o,t);if(!n)throw r.error({versionName:o},"Jira version not found"),new Error(`Version "${o}" not found in Jira project`);return await Kr({versionId:n.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},t)}catch(o){throw r.error({error:o},"Error delivering Jira release"),o}},B=async()=>{let e=z.env.JIRA_BASE_URL,t=z.env.JIRA_TOKEN||z.env.JIRA_API_TOKEN,o=z.env.JIRA_PROJECT_ID,n=z.env.JIRA_EMAIL,s=[];if(e||s.push("JIRA_BASE_URL (e.g., https://your-domain.atlassian.net)"),t||s.push("JIRA_TOKEN or JIRA_API_TOKEN (your Jira API token)"),o||s.push("JIRA_PROJECT_ID (numeric project ID)"),n||s.push("JIRA_EMAIL (your Jira email address)"),s.length>0){let l=["Jira configuration is required but incomplete.","Please configure the following environment variables:",...s.map(c=>` - ${c}`),"","You can set these in your .env file or as environment variables."].join(`
|
|
23
|
+
`);throw new Error(l)}let a=Number.parseInt(o,10);if(Number.isNaN(a))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${o}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:t,projectId:a,email:n}},Oe=async()=>{try{return await B()}catch(e){return r.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var de=async e=>{let{version:t,confirmedCommand:o}=e;i.start("release-deliver");let n=await y(),s="";t?s=`release/v${t}`:(i.setInteractive(),s=await Xr({message:"\u{1F33F} Select release branch",choices:n.map(c=>({name:c.replace("release/v",""),value:c}))}));let a=s.replace("release/v","");i.addOption("--version",a),n.includes(s)||(r.error(`\u274C Release branch ${s} not found in open PRs. Exiting...`),Je.exit(1));let l=o?!0:await Hr({message:`Are you sure you want to deliver version ${s} to production?`});o||i.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),Je.exit(0)),i.addOption("--yes",!0);try{A.quiet=!0,await A`gh pr merge ${s} --squash --admin --delete-branch`,await A`gh pr create --base main --head dev --title "Release v${s.replace("release/v","")} (RC)" --body ""`,await A`gh pr merge dev --squash --admin`,A.quiet=!1,await A`gh workflow run deploy-all.yml --ref main -f environment=prod`,A.quiet=!0,await A`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`,A.quiet=!1;let c=await Oe();if(c)try{let p=s.replace("release/","");await De({versionName:p},c)}catch(p){r.error({error:p},"Failed to deliver Jira release (non-blocking)")}else r.info("\u{1F514} Jira is not configured, skipping Jira release delivery");r.info(`Successfully delivered ${s} to production!`),i.print();let m={releaseBranch:s,version:s.replace("release/v",""),success:!0};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(c){r.error({error:c},"\u274C Error merging release branch into dev"),Je.exit(1)}},Yr={name:"gh-release-deliver",description:"Deliver a release branch to production",inputSchema:{version:me.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:me.string().describe("The release branch that was delivered"),version:me.string().describe("The version that was delivered"),success:me.boolean().describe("Whether the delivery was successful")},handler:de};import tr from"@inquirer/select";import Le from"node:process";import{z as P}from"zod";import{$ as je}from"zx";var ue=async e=>{let{version:t,env:o,skipTerraform:n}=e;i.start("release-deploy-all");let s=["dev"],a=await y();s.push(...a);let l="";t?l=t==="dev"?"dev":`release/v${t}`:(i.setInteractive(),l=await tr({message:"\u{1F33F} Select release branch",choices:s.map(u=>({name:u.replace("release/v",""),value:u}))}));let c=l==="dev"?"dev":l.replace("release/v","");i.addOption("--version",c),s.includes(l)||(r.error(`\u274C Release branch ${l} not found in open PRs. Exiting...`),Le.exit(1));let m="";o?m=o:(i.setInteractive(),m=await tr({message:"\u{1F9EA} Select environment",choices:w.map(u=>({name:u,value:u}))})),i.addOption("--env",m),w.includes(m)||(r.error(`\u274C Invalid environment: ${m}. Exiting...`),Le.exit(1));let p=n??!1;p&&i.addOption("--skip-terraform",!0);try{je.quiet=!0,await je`gh workflow run deploy-all.yml --ref ${l} -f environment=${m} ${p?["-f","skip_terraform_deploy=true"]:[]}`,je.quiet=!1,r.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${l} and environment: ${m}`),i.print();let d={releaseBranch:l,version:l.replace("release/v",""),environment:m,skipTerraformDeploy:p,success:!0};return{content:[{type:"text",text:JSON.stringify(d,null,2)}],structuredContent:d}}catch(u){r.error({error:u},"\u274C Error launching workflow"),Le.exit(1)}},Qr={name:"gh-release-deploy-all",description:"Deploy a release branch to a specified environment",inputSchema:{version:P.string().describe('Version to deploy (e.g., "1.2.5")'),env:P.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),skipTerraform:P.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:P.string().describe("The release branch that was deployed"),version:P.string().describe("The version that was deployed"),environment:P.string().describe("The environment deployed to"),skipTerraformDeploy:P.boolean().describe("Whether terraform deployment was skipped"),success:P.boolean().describe("Whether the deployment was successful")},handler:ue};import Zr from"@inquirer/checkbox";import or from"@inquirer/select";import et from"node:fs/promises";import{resolve as rt}from"node:path";import q from"node:process";import tt from"yaml";import{z as x}from"zod";import{$ as Ve}from"zx";var fe=async e=>{let{version:t,env:o,services:n,skipTerraform:s}=e;i.start("release-deploy-selected");let a=["dev"],l=await y();a.push(...l);let c="";t?c=t==="dev"?"dev":`release/v${t}`:(i.setInteractive(),c=await or({message:"\u{1F33F} Select release branch",choices:a.map(g=>({name:g.replace("release/v",""),value:g}))}));let m=c==="dev"?"dev":c.replace("release/v","");i.addOption("--version",m),a.includes(c)||(r.error(`\u274C Release branch ${c} not found in open PRs. Exiting...`),q.exit(1));let p="";o?p=o:(i.setInteractive(),p=await or({message:"\u{1F9EA} Select environment",choices:w.map(g=>({name:g,value:g}))})),i.addOption("--env",p),w.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),q.exit(1));let u=await ot();u.length===0&&(r.error("\u274C No services found in workflow file. Exiting..."),q.exit(1));let d=[];n&&n.length>0?d=n:(i.setInteractive(),d=await Zr({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:u.map(g=>({name:g,value:g}))})),i.addOption("--services",d),d.length===0&&(r.error("\u274C No services selected. Exiting..."),q.exit(1));let h=d.filter(g=>!u.includes(g));h.length>0&&(r.error(`\u274C Invalid services: ${h.join(", ")}. Available services: ${u.join(", ")}`),q.exit(1));let f=s??!1;f&&i.addOption("--skip-terraform",!0);try{Ve.quiet=!0;let g=d.flatMap(mr=>["-f",`${mr}=true`]);await Ve`gh workflow run deploy-selected-services.yml --ref ${c} -f environment=${p} ${g} ${f?["-f","skip_terraform_deploy=true"]:[]}`,Ve.quiet=!1,r.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${c}, environment: ${p}, services: ${d.join(", ")}`),i.print();let Ge={releaseBranch:c,version:c.replace("release/v",""),environment:p,services:d,skipTerraformDeploy:f,success:!0};return{content:[{type:"text",text:JSON.stringify(Ge,null,2)}],structuredContent:Ge}}catch(g){r.error({error:g},"\u274C Error launching workflow"),q.exit(1)}},ot=async()=>{let e=await R(),t=rt(e,".github/workflows/deploy-selected-services.yml"),o=await et.readFile(t,"utf-8"),s=tt.parse(o).on.workflow_dispatch.inputs,a=[];for(let[l,c]of Object.entries(s))c.type==="boolean"&&l!=="skip_terraform_deploy"&&a.push(l);return a},st={name:"gh-release-deploy-selected",description:"Deploy selected services from a release branch to a specified environment",inputSchema:{version:x.string().describe('Version to deploy (e.g., "1.2.5")'),env:x.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),services:x.array(x.string()).describe('List of services to deploy (e.g., ["client-be", "client-fe"])'),skipTerraform:x.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:x.string().describe("The release branch that was deployed"),version:x.string().describe("The version that was deployed"),environment:x.string().describe("The environment deployed to"),services:x.array(x.string()).describe("The services that were deployed"),skipTerraformDeploy:x.boolean().describe("Whether terraform deployment was skipped"),success:x.boolean().describe("Whether the deployment was successful")},handler:fe};import Fe from"@inquirer/select";import nt from"node:fs/promises";import{resolve as it}from"node:path";import ge from"node:process";import at from"yaml";import{z as T}from"zod";import{$ as We}from"zx";var he=async e=>{let{version:t,env:o,service:n,skipTerraform:s}=e;i.start("release-deploy-service");let a=["dev"],l=await y();a.push(...l);let c="";t?c=t==="dev"?"dev":`release/v${t}`:(i.setInteractive(),c=await Fe({message:"\u{1F33F} Select release branch",choices:a.map(f=>({name:f.replace("release/v",""),value:f}))}));let m=c==="dev"?"dev":c.replace("release/v","");i.addOption("--version",m),a.includes(c)||(r.error(`\u274C Release branch ${c} not found in open PRs. Exiting...`),ge.exit(1));let p="";o?p=o:(i.setInteractive(),p=await Fe({message:"\u{1F9EA} Select environment",choices:w.map(f=>({name:f,value:f}))})),i.addOption("--env",p),w.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),ge.exit(1));let u=await ct(),d="";n?d=n:(i.setInteractive(),d=await Fe({message:"\u{1F680} Select service to deploy",choices:u.map(f=>({name:f,value:f}))})),i.addOption("--service",d),u.includes(d)||(r.error(`\u274C Invalid service: ${d}. Available services: ${u.join(", ")}`),ge.exit(1));let h=s??!1;h&&i.addOption("--skip-terraform",!0);try{We.quiet=!0,await We`gh workflow run deploy-single-service.yml --ref ${c} -f environment=${p} -f service=${d} ${h?["-f","skip_terraform_deploy=true"]:[]}`,We.quiet=!1,r.info(`Successfully launched deploy-single-service workflow_dispatch for release branch: ${c}, environment: ${p}, service: ${d}`),i.print();let g={releaseBranch:c,version:c.replace("release/v",""),environment:p,service:d,skipTerraformDeploy:h,success:!0};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(f){r.error({error:f},"\u274C Error launching workflow"),ge.exit(1)}},ct=async()=>{let e=await R(),t=it(e,".github/workflows/deploy-single-service.yml"),o=await nt.readFile(t,"utf-8");return at.parse(o).on.workflow_dispatch.inputs.service.options},lt={name:"gh-release-deploy-service",description:"Deploy a specific service in a release branch to a specified environment",inputSchema:{version:T.string().describe('Version to deploy (e.g., "1.2.5")'),env:T.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),service:T.string().describe('Service to deploy (e.g., "client-be", "client-fe")'),skipTerraform:T.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:T.string().describe("The release branch that was deployed"),version:T.string().describe("The version that was deployed"),environment:T.string().describe("The environment deployed to"),service:T.string().describe("The service that was deployed"),skipTerraformDeploy:T.boolean().describe("Whether terraform deployment was skipped"),success:T.boolean().describe("Whether the deployment was successful")},handler:he};import{z as Me}from"zod";var ve=async()=>{let t=(await y()).map(n=>n.replace("release/",""));r.info(`All release branches:
|
|
7
24
|
`),r.info(`
|
|
8
|
-
${
|
|
9
|
-
`)}`);let
|
|
10
|
-
`)}catch(g){let
|
|
11
|
-
`)}let u=
|
|
25
|
+
${t.join(`
|
|
26
|
+
`)}`);let o={releases:t,count:t.length};return{content:[{type:"text",text:JSON.stringify(o,null,2)}],structuredContent:o}},pt={name:"gh-release-list",description:"List all open release branches",inputSchema:{},outputSchema:{releases:Me.array(Me.string()).describe("List of all release branches"),count:Me.number().describe("Number of release branches")},handler:ve};import sr from"@inquirer/confirm";import nr from"node:process";import{z as N}from"zod";import{$ as Be,question as ir}from"zx";import{$ as K}from"zx";var H=async()=>{K.quiet=!0,await K`git fetch origin`,await K`git switch dev`,await K`git pull origin dev`,K.quiet=!1},X=async(e,t,o)=>{let n=`v${e}`,s=await _e({name:n,projectId:t.projectId,description:o||"",released:!1,archived:!1},t),a=`${t.baseUrl}/projects/${s.version.projectId}/versions/${s.version.id}/tab/release-report-all-issues`,l=await le({version:e,jiraVersionUrl:a});return{version:e,branchName:l.branchName,prUrl:l.prUrl,jiraVersionUrl:a}};var ye=async e=>{let{version:t,description:o,confirmedCommand:n,checkout:s}=e;i.start("release-create");let a=t,l=o,c=s,m=await B();a||(i.setInteractive(),a=await ir("Enter version (e.g. 1.2.5): ")),(!a||a.trim()==="")&&(r.error("No version provided. Exiting..."),nr.exit(1));let p=a.trim();i.addOption("--version",p),l===void 0&&(i.setInteractive(),l=await ir("Enter description (optional, press Enter to skip): "),l.trim()===""&&(l="")),l&&i.addOption("--description",l);let u=n?!0:await sr({message:`Are you sure you want to create release branch for version ${p}?`});n||i.setInteractive(),u||(r.info("Operation cancelled. Exiting..."),nr.exit(0)),i.addOption("--yes",!0),await H();let d=await X(p,m,l);r.info(`\u2705 Successfully created release: v${p}`),r.info(`\u{1F517} GitHub PR: ${d.prUrl}`),r.info(`\u{1F517} Jira Version: ${d.jiraVersionUrl}`),c===void 0&&(i.setInteractive(),c=await sr({message:`Do you want to checkout to the created branch ${d.branchName}?`,default:!0})),c||i.addOption("--no-checkout",!0),c&&(Be.quiet=!0,await Be`git switch ${d.branchName}`,Be.quiet=!1,r.info(`\u{1F504} Switched to branch ${d.branchName}`)),i.print();let h={version:p,branchName:d.branchName,prUrl:d.prUrl,jiraVersionUrl:d.jiraVersionUrl,isCheckedOut:c};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}},mt={name:"release-create",description:"Create a single release branch for specified version with Jira version creation",inputSchema:{version:N.string().describe('Version to create (e.g., "1.2.5")'),description:N.string().optional().describe("Optional description for the Jira version"),checkout:N.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:N.string().describe("Version number"),branchName:N.string().describe("Release branch name"),prUrl:N.string().describe("GitHub PR URL"),jiraVersionUrl:N.string().describe("Jira version URL"),isCheckedOut:N.boolean().describe("Whether the branch was checked out")},handler:ye};import dt from"@inquirer/confirm";import ar from"node:process";import{z as b}from"zod";import{question as ut}from"zx";var we=async e=>{let{versions:t,description:o,confirmedCommand:n}=e;i.start("release-create-batch");let s=t,a=await B();s||(i.setInteractive(),s=await ut("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let l=s.split(",").map(f=>f.trim());i.addOption("--versions",l.join(", ")),l.length===0&&(r.error("No versions provided. Exiting..."),ar.exit(1)),l.length===1&&r.warn('\u{1F4A1} You are creating only one release. Consider using "create-release" command for single releases.');let c=n?!0:await dt({message:`Are you sure you want to create release branches for these versions: ${l.join(", ")}?`});n||i.setInteractive(),c||(r.info("Operation cancelled. Exiting..."),ar.exit(0)),i.addOption("--yes",!0),o&&i.addOption("--description",o),await H();let m=[],p=[];for(let f of l)try{let g=await X(f,a,o);m.push(g),r.info(`\u2705 Successfully created release: v${f}`),r.info(`\u{1F517} GitHub PR: ${g.prUrl}`),r.info(`\u{1F517} Jira Version: ${g.jiraVersionUrl}
|
|
27
|
+
`)}catch(g){let I=g instanceof Error?g.message:String(g);p.push({version:f,error:I}),r.error(`\u274C Failed to create release: v${f}`),r.error(` Error: ${I}
|
|
28
|
+
`)}let u=m.length,d=p.length;u===l.length?r.info(`\u2705 All ${l.length} release branches were created successfully.`):u>0?(r.warn(`\u26A0\uFE0F ${u} of ${l.length} release branches were created successfully.`),r.warn(`\u274C ${d} release(s) failed.`)):r.error(`\u274C All ${l.length} release branches failed to create.`),i.print();let h={createdBranches:m.map(f=>f.branchName),successCount:u,failureCount:d,releases:m,failedReleases:p};return{content:[{type:"text",text:JSON.stringify(h,null,2)}],structuredContent:h}},ft={name:"release-create-batch",description:"Create multiple release branches for specified versions with Jira version creation (batch operation)",inputSchema:{versions:b.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6")'),description:b.string().optional().describe("Optional description for the Jira versions")},outputSchema:{createdBranches:b.array(b.string()).describe("List of created release branches"),successCount:b.number().describe("Number of releases created successfully"),failureCount:b.number().describe("Number of releases that failed"),releases:b.array(b.object({version:b.string().describe("Version number"),branchName:b.string().describe("Release branch name"),prUrl:b.string().describe("GitHub PR URL"),jiraVersionUrl:b.string().describe("Jira version URL")})).describe("Detailed information for each created release with URLs"),failedReleases:b.array(b.object({version:b.string().describe("Version number that failed"),error:b.string().describe("Error message")})).describe("List of releases that failed with error messages")},handler:we};import gt from"@inquirer/checkbox";import cr from"@inquirer/confirm";import{copyFileSync as ht,existsSync as vt}from"node:fs";import yt from"node:process";import{z as Y}from"zod";import{$ as qe}from"zx";var wt="feature",bt="release",Rt="release/v",be=async e=>{let{confirmedCommand:t,all:o,cursor:n}=e;i.start("worktrees-add");try{let s=await S("release"),a=await R(),l=`${a}${W}`;await lr(`${l}/${bt}`),await lr(`${l}/${wt}`);let c=await y();if(c.length===0)return r.info("\u2139\uFE0F No open release branches found"),i.print(),{content:[{type:"text",text:JSON.stringify({createdWorktrees:[],count:0},null,2)}],structuredContent:{createdWorktrees:[],count:0}};let m=[];o?m=c:(i.setInteractive(),m=await gt({required:!0,message:"\u{1F33F} Select release branches",choices:c.map(I=>({name:I.replace("release/v",""),value:I}))}));let p=m.length===c.length;p?i.addOption("--all",!0):i.addOption("--branches",m);let u=t?!0:await cr({message:"Are you sure you want to proceed with these worktree changes?"});t||i.setInteractive(),u||(r.info("Operation cancelled. Exiting..."),yt.exit(0)),p&&i.addOption("--yes",!0);let d=n?!0:await cr({message:"Open created worktrees in Cursor?"});d||i.setInteractive(),d&&i.addOption("--cursor",!0);let{branchesToCreate:h}=kt({selectedReleaseBranches:m,currentWorktrees:s}),f=await xt(h,l,a);if(Ct(f),d)for(let I of f)await qe`cursor ${l}/${I}`;i.print();let g={createdWorktrees:f,count:f.length};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(s){throw r.error({error:s},"\u274C Error managing worktrees"),s}},lr=async e=>{await qe`mkdir -p ${e}`},kt=e=>{let{selectedReleaseBranches:t,currentWorktrees:o}=e,n=o.filter(a=>a.startsWith(Rt));return{branchesToCreate:t.filter(a=>!n.includes(a))}},xt=async(e,t,o)=>{let n=[];for(let s of e)try{let a=`${t}/${s}`;await qe`git worktree add ${a} ${s}`;let l=`${o}/.env`;vt(l)&&(ht(l,`${a}/.env`),r.info("\u{1F4CB} Copied .env to worktree")),n.push(s)}catch(a){r.error({error:a,branch:s},`\u274C Failed to create worktree for ${s}`)}return n},Ct=e=>{e.length>0?(r.info(`
|
|
12
29
|
`),r.info("\u2705 Created worktrees:"),r.info(e.join(`
|
|
13
|
-
`)),r.info("")):r.info("\u2139\uFE0F No new worktrees to create")}
|
|
14
|
-
`).filter(Boolean);return
|
|
30
|
+
`)),r.info("")):r.info("\u2139\uFE0F No new worktrees to create")},$t={name:"worktrees-add",description:"Create worktrees for selected release branches",inputSchema:{all:Y.boolean().describe("Add worktrees for all release branches without prompting"),cursor:Y.boolean().optional().describe("Open created worktrees in Cursor")},outputSchema:{createdWorktrees:Y.array(Y.string()).describe("List of created worktree branches"),count:Y.number().describe("Number of worktrees created")},handler:be};import{z as k}from"zod";import{$ as Q}from"zx";var Re=async()=>{try{let[e,t]=await Promise.all([S("release"),S("feature")]),o=await R(),n=await St(e,t,o);Nt(n);let s={worktrees:n,totalCount:n.length,releaseCount:e.length,featureCount:t.length};return{content:[{type:"text",text:JSON.stringify(s,null,2)}],structuredContent:s}}catch(e){throw r.error({error:e},"\u274C Error listing worktrees"),e}},St=async(e,t,o)=>{let n=[...e.map(a=>({branch:a,type:"release"})),...t.map(a=>({branch:a,type:"feature"}))],s=[];for(let{branch:a,type:l}of n)try{let c=`${o}/${a}`,m=await Et(a),p=await Tt(c),u=await At(c),d=await It(c),h=await Pt(c);s.push({branch:a,path:c,commit:p.substring(0,8),isCurrent:m,type:l,status:u,lastCommitMessage:d.substring(0,60)+(d.length>60?"...":""),aheadBehind:h})}catch(c){r.warn({error:c,branch:a},`\u26A0\uFE0F Could not process worktree ${a}`)}return s.sort((a,l)=>a.type!==l.type?a.type==="release"?-1:1:a.branch.localeCompare(l.branch))},Et=async e=>{try{return(await Q`git branch --show-current`).stdout.trim()===e}catch{return!1}},Tt=async e=>{try{return(await Q`cd ${e} && git rev-parse HEAD`).stdout.trim()}catch{return"unknown"}},At=async e=>{try{let o=(await Q`cd ${e} && git status --porcelain`).stdout.trim().split(`
|
|
31
|
+
`).filter(Boolean);return o.length===0?"clean":o.length<=3?"modified":"dirty"}catch{return"unknown"}},It=async e=>{try{return(await Q`cd ${e} && git log -1 --pretty=format:"%s"`).stdout.trim()}catch{return"No commit message available"}},Pt=async e=>{try{let o=(await Q`cd ${e} && git rev-list --count --left-right @{u}...HEAD 2>/dev/null || echo "0 0"`).stdout.trim().split(" ").map(Number),n=o[0]||0,s=o[1]||0;return s===0&&n===0?"up to date":s>0&&n===0?`\u2191${s} ahead`:n>0&&s===0?`\u2193${n} behind`:`\u2191${s} \u2193${n}`}catch{return"unknown"}},Nt=e=>{if(e.length===0){r.info(`
|
|
15
32
|
\u{1F33F} Git Worktrees`),r.info("\u2500".repeat(80)),r.info("\u2139\uFE0F No worktrees found"),r.info("\u2500".repeat(80));return}r.info(`
|
|
16
|
-
\u{1F33F} Git Worktrees`),r.info("\u2550".repeat(100));let
|
|
17
|
-
${"\u2550".repeat(100)}`),r.info(`\u{1F4CA} Summary: ${e.length} total worktrees (${
|
|
18
|
-
${e}`),r.info("\u2500".repeat(50));for(let[
|
|
19
|
-
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},
|
|
20
|
-
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},
|
|
33
|
+
\u{1F33F} Git Worktrees`),r.info("\u2550".repeat(100));let t=e.filter(s=>s.type==="release"),o=e.filter(s=>s.type==="feature");pr("\u{1F680} Releases",t),o.length>0&&t.length>0&&r.info(""),pr("\u2728 Features",o);let n=e.find(s=>s.isCurrent);r.info(`
|
|
34
|
+
${"\u2550".repeat(100)}`),r.info(`\u{1F4CA} Summary: ${e.length} total worktrees (${t.length} releases, ${o.length} features)`),n&&r.info(`\u{1F4CD} Currently on: ${n.branch}`),r.info("")},pr=(e,t)=>{if(t.length!==0){r.info(`
|
|
35
|
+
${e}`),r.info("\u2500".repeat(50));for(let[o,n]of t.entries())_t(n),o<t.length-1&&r.info("")}},_t=e=>{let t=e.isCurrent?"\u{1F4CD}":" ",o=Dt(e.status),s=`${e.type==="release"?"\u{1F680}":"\u2728"} ${e.branch}`;r.info(`${t} ${o} ${s}`);let a=e.aheadBehind!=="unknown"?` | ${e.aheadBehind}`:"";r.info(` \u{1F4DD} ${e.commit}${a}`),r.info(` \u{1F4AC} ${e.lastCommitMessage}`);let l=e.path.split("/").slice(-2).join("/");r.info(` \u{1F4C1} ${l}`)},Dt=e=>{switch(e){case"clean":return"\u2705";case"modified":return"\u26A0\uFE0F ";case"dirty":return"\u{1F534}";default:return"\u2753"}},Ot={name:"worktrees-list",description:"List all git worktrees with detailed information",inputSchema:{},outputSchema:{worktrees:k.array(k.object({branch:k.string(),path:k.string(),commit:k.string(),isCurrent:k.boolean(),type:k.enum(["release","feature"]),status:k.string(),lastCommitMessage:k.string(),aheadBehind:k.string()})).describe("List of all worktrees with details"),totalCount:k.number().describe("Total number of worktrees"),releaseCount:k.number().describe("Number of release worktrees"),featureCount:k.number().describe("Number of feature worktrees")},handler:Re};import Jt from"@inquirer/checkbox";import Lt from"@inquirer/confirm";import jt from"node:process";import{z as ke}from"zod";import{$ as Vt}from"zx";var xe=async e=>{let{confirmedCommand:t,all:o}=e;i.start("worktrees-remove");try{let n=await S("release");if(n.length===0)return r.info("\u2139\uFE0F No active worktrees to remove"),i.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let a=`${await R()}${W}`,l=[];o?l=n:(i.setInteractive(),l=await Jt({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(d=>({name:d.replace("release/v",""),value:d}))}));let c=l.length===n.length;c?i.addOption("--all",!0):i.addOption("--branches",l);let m=t?!0:await Lt({message:"Are you sure you want to proceed with these worktree changes?"});t||i.setInteractive(),m||(r.info("Operation cancelled. Exiting..."),jt.exit(0)),c&&i.addOption("--yes",!0);let p=await Ft(l,a);Wt(p),i.print();let u={removedWorktrees:p,count:p.length};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(n){throw r.error({error:n},"\u274C Error managing worktrees"),n}},Ft=async(e,t)=>{let o=[];for(let n of e)try{let s=`${t}/${n}`;await Vt`git worktree remove ${s}`,o.push(n)}catch(s){r.error({error:s,branch:n},`\u274C Failed to remove worktree for ${n}`)}return o},Wt=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
|
|
36
|
+
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},Mt={name:"worktrees-remove",description:"Remove selected worktrees",inputSchema:{all:ke.boolean().describe("Remove all worktrees without prompting")},outputSchema:{removedWorktrees:ke.array(ke.string()).describe("List of removed worktree branches"),count:ke.number().describe("Number of worktrees removed")},handler:xe};import Bt from"@inquirer/confirm";import qt from"node:process";import{z as Ue}from"zod";import{$ as Ut}from"zx";var Gt="release/v",Ce=async e=>{let{confirmedCommand:t}=e;i.start("worktrees-sync");try{let o=await S("release"),s=`${await R()}${W}`,a=await y(),l=t?!0:await Bt({message:"Are you sure you want to proceed with these worktree changes?"});t||i.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),qt.exit(0)),t||i.addOption("--yes",!0);let{branchesToRemove:c}=zt({releasePRsList:a,currentWorktrees:o}),m=await Kt(c,s);Ht(m),i.print();let p={removedWorktrees:m,count:m.length};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}}catch(o){throw r.error({error:o},"\u274C Error managing worktrees"),o}},zt=e=>{let{releasePRsList:t,currentWorktrees:o}=e;return{branchesToRemove:o.filter(a=>a.startsWith(Gt)).filter(a=>!t.includes(a))}},Kt=async(e,t)=>{let o=[];for(let n of e)try{let s=`${t}/${n}`;await Ut`git worktree remove ${s}`,o.push(n)}catch(s){r.error({error:s,branch:n},`\u274C Failed to remove worktree for ${n}`)}return o},Ht=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
|
|
37
|
+
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},Xt={name:"worktrees-sync",description:"Synchronize worktrees with active release branches",inputSchema:{},outputSchema:{removedWorktrees:Ue.array(Ue.string()).describe("List of removed worktree branches"),count:Ue.number().describe("Number of worktrees removed during sync")},handler:Ce};var v=new Yt;v.command("merge-dev").description("Merge dev branch into every release branch").option("-a, --all","Select all active release branches").option("-y, --yes","Skip confirmation prompt").action(async e=>{await pe({all:e.all,confirmedCommand:e.yes})});v.command("release-list").description("List all release branches").action(async()=>{await ve()});v.command("release-create").description("Create a single release branch").option("-v, --version <version>","Specify the version to create, e.g. 1.2.5").option("-d, --description <description>","Optional description for the Jira version").option("-y, --yes","Skip confirmation prompt").option("--no-checkout","Do not checkout the created branch after creation (checkout is default)").action(async e=>{await ye({version:e.version,description:e.description,confirmedCommand:e.yes,checkout:e.checkout})});v.command("release-create-batch").description("Create multiple release branches (batch operation)").option("-v, --versions <versions>","Specify the versions to create by comma, e.g. 1.2.5, 1.2.6").option("-d, --description <description>","Optional description for the Jira versions").option("-y, --yes","Skip confirmation prompt").action(async e=>{await we({versions:e.versions,description:e.description,confirmedCommand:e.yes})});v.command("release-deploy-all").description("Deploy any release branch to any environment").option("-v, --version <version>","Specify the version to deploy, e.g. 1.2.5").option("-e, --env <env>","Specify the environment to deploy to, e.g. dev").option("--skip-terraform","Skip terraform deployment step").action(async e=>{await ue({version:e.version,env:e.env,skipTerraform:e.skipTerraform})});v.command("release-deploy-service").description("Deploy specific service in release branch to any environment").option("-v, --version <version>","Specify the version to deploy, e.g. 1.2.5").option("-e, --env <env>","Specify the environment to deploy to, e.g. dev").option("-s, --service <service>","Specify the service to deploy, e.g. client-be").option("--skip-terraform","Skip terraform deployment step").action(async e=>{await he({version:e.version,env:e.env,service:e.service,skipTerraform:e.skipTerraform})});v.command("release-deploy-selected").description("Deploy selected services from release branch to any environment").option("-v, --version <version>","Specify the version to deploy, e.g. 1.2.5").option("-e, --env <env>","Specify the environment to deploy to, e.g. dev").option("-s, --services <services...>","Specify services to deploy, e.g. client-be client-fe").option("--skip-terraform","Skip terraform deployment step").action(async e=>{await fe({version:e.version,env:e.env,services:e.services,skipTerraform:e.skipTerraform})});v.command("release-deliver").description("Release a new version to production").option("-v, --version <version>","Specify the version to release, e.g. 1.2.5").option("-y, --yes","Skip confirmation prompt").action(async e=>{await de({version:e.version,confirmedCommand:e.yes})});v.command("worktrees-sync").description("Remove release worktrees whose PRs are no longer open").option("-y, --yes","Skip confirmation prompt").action(async e=>{await Ce({confirmedCommand:e.yes})});v.command("worktrees-add").description("Add git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").option("-a, --all","Select all active release branches").option("-c, --cursor","Open created worktrees in Cursor").action(async e=>{await be({confirmedCommand:e.yes,all:e.all,cursor:e.cursor})});v.command("worktrees-list").description("List all git worktrees with detailed information").action(async()=>{await Re()});v.command("worktrees-remove").description("Remove git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").option("-a, --all","Select all active release branches").action(async e=>{await xe({confirmedCommand:e.yes,all:e.all})});v.command("doctor").description("Check installation and authentication status of gh and doppler CLIs").action(async()=>{await ee()});v.command("env-status").description("Show Doppler authentication status and detected project info").action(async()=>{await ce()});v.command("env-list").description("List available Doppler configs for the detected project").action(async()=>{await ne()});v.command("env-init").description("Set up shell functions for env-load/env-clear in .zshrc").action(async()=>{await Te()});v.command("env-load").description("Load environment variables from Doppler. Usage: env-load -c dev (after shell init)").option("-c, --config <config>","Environment config name to load (e.g. dev, arthur)").option("-q, --quiet","Suppress info logging").action(async e=>{await ae({config:e.config,quiet:e.quiet})});v.command("env-clear").description("Clear previously loaded environment variables. Usage: env-clear (after shell init)").action(async()=>{await oe()});v.parse();
|
|
21
38
|
//# sourceMappingURL=cli.js.map
|