infra-kit 0.1.72 → 0.1.74
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 +29 -15
- package/dist/cli.js.map +4 -4
- package/dist/mcp.js +32 -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 +99 -0
- package/src/commands/env-clear/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 +94 -0
- package/src/commands/env-load/index.ts +1 -0
- package/src/commands/env-status/env-status.ts +97 -0
- package/src/commands/env-status/index.ts +1 -0
- package/src/entry/cli.ts +40 -3
- 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 +18 -0
- package/src/lib/load-env/load-env.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/dist/cli.js
CHANGED
|
@@ -1,21 +1,35 @@
|
|
|
1
|
-
import{Command as
|
|
1
|
+
import{Command as Lt}from"commander";import{z as j}from"zod";import{$ as mr}from"zx";import ar from"node:process";import cr from"pino";import lr from"pino-pretty";var pr=()=>{let e=ar.argv.includes("--debug")?"debug":"info",t=["time","pid","hostname"];return e==="debug"&&t.push("level"),cr({level:e},lr({ignore:t.join(","),colorize:!0}))},r=pr();var Z=async(e,t,o,n)=>{try{return await mr`${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}},dr={name:"doctor",description:"Check installation and authentication status of gh and doppler CLIs",inputSchema:{},outputSchema:{checks:j.array(j.object({name:j.string().describe("Name of the check"),status:j.enum(["pass","fail"]).describe("Check result"),message:j.string().describe("Details about the check result")})).describe("List of all check results"),allPassed:j.boolean().describe("Whether all checks passed")},handler:ee};import Ce from"node:fs";import ur from"node:path";import F from"node:process";import{z as $e}from"zod";var R=["dev","arthur","renana","roman","eliran","oriana"],xe={"hulyo-monorepo":"hulyo","travelist-monorepo":"travelist"},D="./node_modules/.cache/infra-kit",L="env-cache.json",O="INFRA_KIT_ENV_CONFIG",V="INFRA_KIT_ENV_PROJECT",W="INFRA_KIT_ENV_LOADED_AT",M="-worktrees";var re=async()=>{let e=ur.join(D,L);if(!F.env[O])return r.error("No loaded environment found. Run `env-load` first."),{content:[{type:"text",text:"No loaded environment found. Run `env-load` first."}]};let n=JSON.parse(Ce.readFileSync(e,"utf-8")).varNames.filter(i=>i in F.env);if(n.length===0)return Ce.unlinkSync(e),r.info("Current session is clear, no environment variables to unset."),{content:[{type:"text",text:"Current session is clear, no environment variables to unset."}]};for(let i of n)F.stdout.write(`unset ${i}
|
|
3
|
+
`);F.stdout.write(`unset ${O}
|
|
4
|
+
`),F.stdout.write(`unset ${V}
|
|
5
|
+
`),F.stdout.write(`unset ${W}
|
|
6
|
+
`),Ce.unlinkSync(e),r.info(`Cleared ${n.length} environment variables`);let s={variableCount:n.length,unsetStatements:n.map(i=>`unset ${i}`)};return{content:[{type:"text",text:JSON.stringify(s,null,2)}],structuredContent:s}},fr={name:"env-clear",description:"Clear previously loaded environment variables. Usage: source <(infra-kit env-clear)",inputSchema:{},outputSchema:{variableCount:$e.number().describe("Number of variables cleared"),unsetStatements:$e.array($e.string()).describe("Unset statements generated")},handler:re};import{z as Ee}from"zod";import Ue 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"),Ue.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"),Ue.exit(1)}};import vr from"node:path";import{$ as Ge}from"zx";var E=async e=>{let o=(await Ge`git worktree list`).stdout.split(`
|
|
7
|
+
`).filter(Boolean),n={release:gr,feature:hr};return o.map(n[e]).filter(s=>s!==null)},gr=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("release/v")?null:`release/${t[0]?.split("/").pop()||""}`},hr=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("feature/")?null:`feature/${t[0]?.split("/").pop()||""}`},y=async()=>(await Ge`git rev-parse --show-toplevel`).stdout.trim();var J=async()=>{let e=await y(),t=vr.basename(e),o=xe[t];if(!o)throw new Error(`Could not determine Doppler project for directory "${t}". Expected one of: ${Object.keys(xe).join(", ")}`);return o};var te=async()=>{await _();let e=await J();r.info(`Doppler Project: ${e}
|
|
8
|
+
`),r.info("Available Configs:");for(let o of R)r.info(` - ${o}`);let t={project:e,configs:R};return{content:[{type:"text",text:JSON.stringify(t,null,2)}],structuredContent:t}},yr={name:"env-list",description:"List available Doppler configs for the detected project",inputSchema:{},outputSchema:{project:Ee.string().describe("Detected Doppler project name"),configs:Ee.array(Ee.string()).describe("Available environment configs")},handler:te};import He from"node:fs";import wr from"node:path";import B from"node:process";import{z as oe}from"zod";import{$ as br}from"zx";var se=async e=>{await _();let{config:t}=e,o=await J(),s=(await br`doppler secrets download --no-file --format env --project ${o} --config ${t}`).stdout.trim();B.stdout.write(`set -a
|
|
9
|
+
`),B.stdout.write(`${s}
|
|
10
|
+
`),B.stdout.write(`set +a
|
|
11
|
+
`),B.stdout.write(`export ${O}=${t}
|
|
12
|
+
`),B.stdout.write(`export ${V}=${o}
|
|
13
|
+
`),B.stdout.write(`export ${W}=${new Date().toISOString()}
|
|
14
|
+
`);let i=s.split(`
|
|
15
|
+
`).filter(p=>p.includes("=")).map(p=>p.split("=")[0]),l=wr.join(D,L),a={config:t,loadedAt:new Date().toISOString(),varNames:i};He.mkdirSync(D,{recursive:!0}),He.writeFileSync(l,JSON.stringify(a,null,2)),r.info(`Loaded ${i.length} variables from ${o}/${t}`);let m={variableCount:i.length,project:o,config:t};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},Rr={name:"env-load",description:"Load environment variables from Doppler for a given config. Usage: source <(infra-kit env-load -c dev)",inputSchema:{config:oe.string().describe("Environment config name to load (e.g. dev, arthur, renana)")},outputSchema:{variableCount:oe.number().describe("Number of variables loaded"),project:oe.string().describe("Doppler project name"),config:oe.string().describe("Doppler config name")},handler:se};import ze from"node:fs";import kr from"node:path";import ne from"node:process";import{z as T}from"zod";var ie=async()=>{await _();let e=await J();r.info(`Doppler Environment Status:
|
|
16
|
+
`),r.info(" Authenticated: yes"),r.info(` Detected Project: ${e}`),r.info(` Available Configs: ${R.join(", ")}`);let t=kr.join(D,L),o=0,n=0,s=ne.env[O]??null,i=ne.env[V]??null,l=ne.env[W]??null;if(s){if(ze.existsSync(t)){let m=JSON.parse(ze.readFileSync(t,"utf-8"));n=m.varNames.length,o=m.varNames.filter(p=>p in ne.env).length}r.info(` Session: ${o} of ${n} vars loaded (project: ${i}, config: ${s}, loaded at: ${l})`)}else r.info(" Session: no env loaded");let a={authenticated:!0,project:e,configs:R,sessionLoadedCount:o,sessionTotalCount:n,sessionConfig:s,sessionProject:i,sessionLoadedAt:l};return{content:[{type:"text",text:JSON.stringify(a,null,2)}],structuredContent:a}},xr={name:"env-status",description:"Show Doppler authentication status and detected project info",inputSchema:{},outputSchema:{authenticated:T.boolean().describe("Whether the user is authenticated"),project:T.string().describe("Detected Doppler project name"),configs:T.array(T.string()).describe("Available environment configs"),sessionLoadedCount:T.number().describe("Number of cached vars active in the current session"),sessionTotalCount:T.number().describe("Total number of cached var names"),sessionConfig:T.string().nullable().describe("Doppler config name of the loaded session"),sessionProject:T.string().nullable().describe("Doppler project name of the loaded session"),sessionLoadedAt:T.string().nullable().describe("ISO 8601 timestamp of when the env was loaded")},handler:ie};import Er from"@inquirer/checkbox";import Sr from"@inquirer/confirm";import Tr from"node:process";import{z as U}from"zod";import{$}from"zx";import{$ as Zo}from"zx";import Ke from"node:process";import{$ as C}from"zx";var Se=e=>e.replace("release/","").slice(1).split(".").map(Number),Te=e=>[...e].sort((t,o)=>{let[n,s,i]=Se(t),[l,a,m]=Se(o);return n!==l?(n??0)-(l??0):s!==a?(s??0)-(a??0):(i??0)-(m??0)});var h=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..."),Ke.exit(1));let o=t.map(n=>n.headRefName);return Te(o)}catch(e){r.error({error:e},"\u274C Error fetching release PRs"),Ke.exit(1)}},ae=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 i=(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:i}}catch(s){throw r.error({error:s,branchName:n},`Error creating release branch ${n}`),s}};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}}},c=$r();var ce=async e=>{let{all:t,confirmedCommand:o}=e;c.start("merge-dev");let n=await h();if(n.length===0)return r.info("\u2139\uFE0F No open release branches found"),c.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:(c.setInteractive(),s=await Er({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(p=>({name:p.replace("release/v",""),value:p}))}));let i=s.length===n.length;i?c.addOption("--all",!0):c.addOption("--branches",s);let l=o?!0:await Sr({message:`Are you sure you want to merge dev into these branches: ${s.join(", ")}?`});o||c.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),Tr.exit(0)),i&&c.addOption("--yes",!0),$.quiet=!0,await $`git fetch origin`,await $`git switch dev`,await $`git pull origin dev`;let a=[];for(let p of s)await Ar(p)||a.push(p);if($.quiet=!1,a.length>0){r.info(`
|
|
2
17
|
\u26A0\uFE0F ${a.length} branch(es) failed to merge automatically.
|
|
3
18
|
`),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:
|
|
19
|
+
`),r.info("```bash");for(let p of a)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-a.length}/${s.length} merges completed successfully.`)}else r.info("\u2705 All merges completed successfully!");c.print();let m={successfulMerges:s.length-a.length,failedMerges:a.length,failedBranches:a,totalBranches:s.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}},Ar=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}},Pr={name:"gh-merge-dev",description:"Merge dev branch into selected release branches",inputSchema:{all:U.boolean().describe("Merge dev into all release branches without prompting")},outputSchema:{successfulMerges:U.number().describe("Number of successful merges"),failedMerges:U.number().describe("Number of failed merges"),failedBranches:U.array(U.string()).describe("List of branches that failed to merge"),totalBranches:U.number().describe("Total number of branches processed")},handler:ce};import Or from"@inquirer/confirm";import _r from"@inquirer/select";import Ne from"node:process";import{z as le}from"zod";import{$ as A}from"zx";import H from"node:process";var Ae=async(e,t)=>{try{let{baseUrl:o,token:n,email:s,projectId:i}=t,l={name:e.name,projectId:e.projectId||i,description:e.description||"",released:e.released||!1,archived:e.archived||!1},a=`${o}/rest/api/3/version`,m=btoa(`${s}:${n}`),p=await fetch(a,{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}},Ir=async e=>{try{let{baseUrl:t,token:o,email:n,projectId:s}=e,i=`${t}/rest/api/3/project/${s}/versions`,l=btoa(`${n}:${o}`),a=await fetch(i,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${l}`}});if(!a.ok){let p=await a.text();throw r.error({status:a.status,statusText:a.statusText,error:p},"Failed to get Jira project versions"),new Error(`HTTP ${a.status}: ${a.statusText}`)}return await a.json()}catch(t){throw r.error({error:t},"Error getting Jira project versions"),t}},Nr=async(e,t)=>{try{return(await Ir(t)).find(s=>s.name===e)||null}catch(o){throw r.error({error:o,versionName:e},"Error finding Jira version by name"),o}},Dr=async(e,t)=>{try{let{baseUrl:o,token:n,email:s}=t,i={released:e.released??!0,archived:e.archived??!1};e.releaseDate?i.releaseDate=e.releaseDate:e.released!==!1&&(i.releaseDate=new Date().toISOString().split("T")[0]),e.description!==void 0&&(i.description=e.description);let l=`${o}/rest/api/3/version/${e.versionId}`,a=btoa(`${s}:${n}`),m=await fetch(l,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${a}`},body:JSON.stringify(i)});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}},Pe=async(e,t)=>{try{let{versionName:o}=e,n=await Nr(o,t);if(!n)throw r.error({versionName:o},"Jira version not found"),new Error(`Version "${o}" not found in Jira project`);return await Dr({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}},q=async()=>{let e=H.env.JIRA_BASE_URL,t=H.env.JIRA_TOKEN||H.env.JIRA_API_TOKEN,o=H.env.JIRA_PROJECT_ID,n=H.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(a=>` - ${a}`),"","You can set these in your .env file or as environment variables."].join(`
|
|
20
|
+
`);throw new Error(l)}let i=Number.parseInt(o,10);if(Number.isNaN(i))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${o}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:t,projectId:i,email:n}},Ie=async()=>{try{return await q()}catch(e){return r.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var pe=async e=>{let{version:t,confirmedCommand:o}=e;c.start("release-deliver");let n=await h(),s="";t?s=`release/v${t}`:(c.setInteractive(),s=await _r({message:"\u{1F33F} Select release branch",choices:n.map(a=>({name:a.replace("release/v",""),value:a}))}));let i=s.replace("release/v","");c.addOption("--version",i),n.includes(s)||(r.error(`\u274C Release branch ${s} not found in open PRs. Exiting...`),Ne.exit(1));let l=o?!0:await Or({message:`Are you sure you want to deliver version ${s} to production?`});o||c.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),Ne.exit(0)),c.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 a=await Ie();if(a)try{let p=s.replace("release/","");await Pe({versionName:p},a)}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!`),c.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(a){r.error({error:a},"\u274C Error merging release branch into dev"),Ne.exit(1)}},Jr={name:"gh-release-deliver",description:"Deliver a release branch to production",inputSchema:{version:le.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:le.string().describe("The release branch that was delivered"),version:le.string().describe("The version that was delivered"),success:le.boolean().describe("Whether the delivery was successful")},handler:pe};import Xe from"@inquirer/select";import De from"node:process";import{z as I}from"zod";import{$ as Oe}from"zx";var me=async e=>{let{version:t,env:o,skipTerraform:n}=e;c.start("release-deploy-all");let s=["dev"],i=await h();s.push(...i);let l="";t?l=t==="dev"?"dev":`release/v${t}`:(c.setInteractive(),l=await Xe({message:"\u{1F33F} Select release branch",choices:s.map(u=>({name:u.replace("release/v",""),value:u}))}));let a=l==="dev"?"dev":l.replace("release/v","");c.addOption("--version",a),s.includes(l)||(r.error(`\u274C Release branch ${l} not found in open PRs. Exiting...`),De.exit(1));let m="";o?m=o:(c.setInteractive(),m=await Xe({message:"\u{1F9EA} Select environment",choices:R.map(u=>({name:u,value:u}))})),c.addOption("--env",m),R.includes(m)||(r.error(`\u274C Invalid environment: ${m}. Exiting...`),De.exit(1));let p=n??!1;p&&c.addOption("--skip-terraform",!0);try{Oe.quiet=!0,await Oe`gh workflow run deploy-all.yml --ref ${l} -f environment=${m} ${p?["-f","skip_terraform_deploy=true"]:[]}`,Oe.quiet=!1,r.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${l} and environment: ${m}`),c.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"),De.exit(1)}},jr={name:"gh-release-deploy-all",description:"Deploy a release branch to a specified environment",inputSchema:{version:I.string().describe('Version to deploy (e.g., "1.2.5")'),env:I.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),skipTerraform:I.boolean().optional().describe("Skip terraform deployment step")},outputSchema:{releaseBranch:I.string().describe("The release branch that was deployed"),version:I.string().describe("The version that was deployed"),environment:I.string().describe("The environment deployed to"),skipTerraformDeploy:I.boolean().describe("Whether terraform deployment was skipped"),success:I.boolean().describe("Whether the deployment was successful")},handler:me};import Lr from"@inquirer/checkbox";import Ye from"@inquirer/select";import Vr from"node:fs/promises";import{resolve as Wr}from"node:path";import G from"node:process";import Mr from"yaml";import{z as x}from"zod";import{$ as _e}from"zx";var de=async e=>{let{version:t,env:o,services:n,skipTerraform:s}=e;c.start("release-deploy-selected");let i=["dev"],l=await h();i.push(...l);let a="";t?a=t==="dev"?"dev":`release/v${t}`:(c.setInteractive(),a=await Ye({message:"\u{1F33F} Select release branch",choices:i.map(g=>({name:g.replace("release/v",""),value:g}))}));let m=a==="dev"?"dev":a.replace("release/v","");c.addOption("--version",m),i.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),G.exit(1));let p="";o?p=o:(c.setInteractive(),p=await Ye({message:"\u{1F9EA} Select environment",choices:R.map(g=>({name:g,value:g}))})),c.addOption("--env",p),R.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),G.exit(1));let u=await Fr();u.length===0&&(r.error("\u274C No services found in workflow file. Exiting..."),G.exit(1));let d=[];n&&n.length>0?d=n:(c.setInteractive(),d=await Lr({message:"\u{1F680} Select services to deploy (space to select, enter to confirm)",choices:u.map(g=>({name:g,value:g}))})),c.addOption("--services",d),d.length===0&&(r.error("\u274C No services selected. Exiting..."),G.exit(1));let w=d.filter(g=>!u.includes(g));w.length>0&&(r.error(`\u274C Invalid services: ${w.join(", ")}. Available services: ${u.join(", ")}`),G.exit(1));let f=s??!1;f&&c.addOption("--skip-terraform",!0);try{_e.quiet=!0;let g=d.flatMap(ir=>["-f",`${ir}=true`]);await _e`gh workflow run deploy-selected-services.yml --ref ${a} -f environment=${p} ${g} ${f?["-f","skip_terraform_deploy=true"]:[]}`,_e.quiet=!1,r.info(`Successfully launched deploy-selected-services workflow_dispatch for release branch: ${a}, environment: ${p}, services: ${d.join(", ")}`),c.print();let Be={releaseBranch:a,version:a.replace("release/v",""),environment:p,services:d,skipTerraformDeploy:f,success:!0};return{content:[{type:"text",text:JSON.stringify(Be,null,2)}],structuredContent:Be}}catch(g){r.error({error:g},"\u274C Error launching workflow"),G.exit(1)}},Fr=async()=>{let e=await y(),t=Wr(e,".github/workflows/deploy-selected-services.yml"),o=await Vr.readFile(t,"utf-8"),s=Mr.parse(o).on.workflow_dispatch.inputs,i=[];for(let[l,a]of Object.entries(s))a.type==="boolean"&&l!=="skip_terraform_deploy"&&i.push(l);return i},Br={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:de};import Je from"@inquirer/select";import Ur from"node:fs/promises";import{resolve as qr}from"node:path";import ue from"node:process";import Gr from"yaml";import{z as S}from"zod";import{$ as je}from"zx";var fe=async e=>{let{version:t,env:o,service:n,skipTerraform:s}=e;c.start("release-deploy-service");let i=["dev"],l=await h();i.push(...l);let a="";t?a=t==="dev"?"dev":`release/v${t}`:(c.setInteractive(),a=await Je({message:"\u{1F33F} Select release branch",choices:i.map(f=>({name:f.replace("release/v",""),value:f}))}));let m=a==="dev"?"dev":a.replace("release/v","");c.addOption("--version",m),i.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),ue.exit(1));let p="";o?p=o:(c.setInteractive(),p=await Je({message:"\u{1F9EA} Select environment",choices:R.map(f=>({name:f,value:f}))})),c.addOption("--env",p),R.includes(p)||(r.error(`\u274C Invalid environment: ${p}. Exiting...`),ue.exit(1));let u=await Hr(),d="";n?d=n:(c.setInteractive(),d=await Je({message:"\u{1F680} Select service to deploy",choices:u.map(f=>({name:f,value:f}))})),c.addOption("--service",d),u.includes(d)||(r.error(`\u274C Invalid service: ${d}. Available services: ${u.join(", ")}`),ue.exit(1));let w=s??!1;w&&c.addOption("--skip-terraform",!0);try{je.quiet=!0,await je`gh workflow run deploy-single-service.yml --ref ${a} -f environment=${p} -f service=${d} ${w?["-f","skip_terraform_deploy=true"]:[]}`,je.quiet=!1,r.info(`Successfully launched deploy-single-service workflow_dispatch for release branch: ${a}, environment: ${p}, service: ${d}`),c.print();let g={releaseBranch:a,version:a.replace("release/v",""),environment:p,service:d,skipTerraformDeploy:w,success:!0};return{content:[{type:"text",text:JSON.stringify(g,null,2)}],structuredContent:g}}catch(f){r.error({error:f},"\u274C Error launching workflow"),ue.exit(1)}},Hr=async()=>{let e=await y(),t=qr(e,".github/workflows/deploy-single-service.yml"),o=await Ur.readFile(t,"utf-8");return Gr.parse(o).on.workflow_dispatch.inputs.service.options},zr={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:fe};import{z as Le}from"zod";var ge=async()=>{let t=(await h()).map(n=>n.replace("release/",""));r.info(`All release branches:
|
|
7
21
|
`),r.info(`
|
|
8
|
-
${
|
|
9
|
-
`)}`);let
|
|
10
|
-
`)}catch(g){let P=g instanceof Error?g.message:String(g);
|
|
11
|
-
`)}let u=
|
|
22
|
+
${t.join(`
|
|
23
|
+
`)}`);let o={releases:t,count:t.length};return{content:[{type:"text",text:JSON.stringify(o,null,2)}],structuredContent:o}},Kr={name:"gh-release-list",description:"List all open release branches",inputSchema:{},outputSchema:{releases:Le.array(Le.string()).describe("List of all release branches"),count:Le.number().describe("Number of release branches")},handler:ge};import Qe from"@inquirer/confirm";import Ze from"node:process";import{z as N}from"zod";import{$ as Ve,question as er}from"zx";import{$ as z}from"zx";var K=async()=>{z.quiet=!0,await z`git fetch origin`,await z`git switch dev`,await z`git pull origin dev`,z.quiet=!1},X=async(e,t,o)=>{let n=`v${e}`,s=await Ae({name:n,projectId:t.projectId,description:o||"",released:!1,archived:!1},t),i=`${t.baseUrl}/projects/${s.version.projectId}/versions/${s.version.id}/tab/release-report-all-issues`,l=await ae({version:e,jiraVersionUrl:i});return{version:e,branchName:l.branchName,prUrl:l.prUrl,jiraVersionUrl:i}};var he=async e=>{let{version:t,description:o,confirmedCommand:n,checkout:s}=e;c.start("release-create");let i=t,l=o,a=s,m=await q();i||(c.setInteractive(),i=await er("Enter version (e.g. 1.2.5): ")),(!i||i.trim()==="")&&(r.error("No version provided. Exiting..."),Ze.exit(1));let p=i.trim();c.addOption("--version",p),l===void 0&&(c.setInteractive(),l=await er("Enter description (optional, press Enter to skip): "),l.trim()===""&&(l="")),l&&c.addOption("--description",l);let u=n?!0:await Qe({message:`Are you sure you want to create release branch for version ${p}?`});n||c.setInteractive(),u||(r.info("Operation cancelled. Exiting..."),Ze.exit(0)),c.addOption("--yes",!0),await K();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}`),a===void 0&&(c.setInteractive(),a=await Qe({message:`Do you want to checkout to the created branch ${d.branchName}?`,default:!0})),a||c.addOption("--no-checkout",!0),a&&(Ve.quiet=!0,await Ve`git switch ${d.branchName}`,Ve.quiet=!1,r.info(`\u{1F504} Switched to branch ${d.branchName}`)),c.print();let w={version:p,branchName:d.branchName,prUrl:d.prUrl,jiraVersionUrl:d.jiraVersionUrl,isCheckedOut:a};return{content:[{type:"text",text:JSON.stringify(w,null,2)}],structuredContent:w}},Xr={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:he};import Yr from"@inquirer/confirm";import rr from"node:process";import{z as b}from"zod";import{question as Qr}from"zx";var ve=async e=>{let{versions:t,description:o,confirmedCommand:n}=e;c.start("release-create-batch");let s=t,i=await q();s||(c.setInteractive(),s=await Qr("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let l=s.split(",").map(f=>f.trim());c.addOption("--versions",l.join(", ")),l.length===0&&(r.error("No versions provided. Exiting..."),rr.exit(1)),l.length===1&&r.warn('\u{1F4A1} You are creating only one release. Consider using "create-release" command for single releases.');let a=n?!0:await Yr({message:`Are you sure you want to create release branches for these versions: ${l.join(", ")}?`});n||c.setInteractive(),a||(r.info("Operation cancelled. Exiting..."),rr.exit(0)),c.addOption("--yes",!0),o&&c.addOption("--description",o),await K();let m=[],p=[];for(let f of l)try{let g=await X(f,i,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}
|
|
24
|
+
`)}catch(g){let P=g instanceof Error?g.message:String(g);p.push({version:f,error:P}),r.error(`\u274C Failed to create release: v${f}`),r.error(` Error: ${P}
|
|
25
|
+
`)}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.`),c.print();let w={createdBranches:m.map(f=>f.branchName),successCount:u,failureCount:d,releases:m,failedReleases:p};return{content:[{type:"text",text:JSON.stringify(w,null,2)}],structuredContent:w}},Zr={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:ve};import et from"@inquirer/checkbox";import tr from"@inquirer/confirm";import{copyFileSync as rt,existsSync as tt}from"node:fs";import ot from"node:process";import{z as Y}from"zod";import{$ as We}from"zx";var st="feature",nt="release",it="release/v",ye=async e=>{let{confirmedCommand:t,all:o,cursor:n}=e;c.start("worktrees-add");try{let s=await E("release"),i=await y(),l=`${i}${M}`;await or(`${l}/${nt}`),await or(`${l}/${st}`);let a=await h();if(a.length===0)return r.info("\u2139\uFE0F No open release branches found"),c.print(),{content:[{type:"text",text:JSON.stringify({createdWorktrees:[],count:0},null,2)}],structuredContent:{createdWorktrees:[],count:0}};let m=[];o?m=a:(c.setInteractive(),m=await et({required:!0,message:"\u{1F33F} Select release branches",choices:a.map(P=>({name:P.replace("release/v",""),value:P}))}));let p=m.length===a.length;p?c.addOption("--all",!0):c.addOption("--branches",m);let u=t?!0:await tr({message:"Are you sure you want to proceed with these worktree changes?"});t||c.setInteractive(),u||(r.info("Operation cancelled. Exiting..."),ot.exit(0)),p&&c.addOption("--yes",!0);let d=n?!0:await tr({message:"Open created worktrees in Cursor?"});d||c.setInteractive(),d&&c.addOption("--cursor",!0);let{branchesToCreate:w}=at({selectedReleaseBranches:m,currentWorktrees:s}),f=await ct(w,l,i);if(lt(f),d)for(let P of f)await We`cursor ${l}/${P}`;c.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}},or=async e=>{await We`mkdir -p ${e}`},at=e=>{let{selectedReleaseBranches:t,currentWorktrees:o}=e,n=o.filter(i=>i.startsWith(it));return{branchesToCreate:t.filter(i=>!n.includes(i))}},ct=async(e,t,o)=>{let n=[];for(let s of e)try{let i=`${t}/${s}`;await We`git worktree add ${i} ${s}`;let l=`${o}/.env`;tt(l)&&(rt(l,`${i}/.env`),r.info("\u{1F4CB} Copied .env to worktree")),n.push(s)}catch(i){r.error({error:i,branch:s},`\u274C Failed to create worktree for ${s}`)}return n},lt=e=>{e.length>0?(r.info(`
|
|
12
26
|
`),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
|
|
27
|
+
`)),r.info("")):r.info("\u2139\uFE0F No new worktrees to create")},pt={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:ye};import{z as k}from"zod";import{$ as Q}from"zx";var we=async()=>{try{let[e,t]=await Promise.all([E("release"),E("feature")]),o=await y(),n=await mt(e,t,o);vt(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}},mt=async(e,t,o)=>{let n=[...e.map(i=>({branch:i,type:"release"})),...t.map(i=>({branch:i,type:"feature"}))],s=[];for(let{branch:i,type:l}of n)try{let a=`${o}/${i}`,m=await dt(i),p=await ut(a),u=await ft(a),d=await gt(a),w=await ht(a);s.push({branch:i,path:a,commit:p.substring(0,8),isCurrent:m,type:l,status:u,lastCommitMessage:d.substring(0,60)+(d.length>60?"...":""),aheadBehind:w})}catch(a){r.warn({error:a,branch:i},`\u26A0\uFE0F Could not process worktree ${i}`)}return s.sort((i,l)=>i.type!==l.type?i.type==="release"?-1:1:i.branch.localeCompare(l.branch))},dt=async e=>{try{return(await Q`git branch --show-current`).stdout.trim()===e}catch{return!1}},ut=async e=>{try{return(await Q`cd ${e} && git rev-parse HEAD`).stdout.trim()}catch{return"unknown"}},ft=async e=>{try{let o=(await Q`cd ${e} && git status --porcelain`).stdout.trim().split(`
|
|
28
|
+
`).filter(Boolean);return o.length===0?"clean":o.length<=3?"modified":"dirty"}catch{return"unknown"}},gt=async e=>{try{return(await Q`cd ${e} && git log -1 --pretty=format:"%s"`).stdout.trim()}catch{return"No commit message available"}},ht=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"}},vt=e=>{if(e.length===0){r.info(`
|
|
15
29
|
\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")},
|
|
30
|
+
\u{1F33F} Git Worktrees`),r.info("\u2550".repeat(100));let t=e.filter(s=>s.type==="release"),o=e.filter(s=>s.type==="feature");sr("\u{1F680} Releases",t),o.length>0&&t.length>0&&r.info(""),sr("\u2728 Features",o);let n=e.find(s=>s.isCurrent);r.info(`
|
|
31
|
+
${"\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("")},sr=(e,t)=>{if(t.length!==0){r.info(`
|
|
32
|
+
${e}`),r.info("\u2500".repeat(50));for(let[o,n]of t.entries())yt(n),o<t.length-1&&r.info("")}},yt=e=>{let t=e.isCurrent?"\u{1F4CD}":" ",o=wt(e.status),s=`${e.type==="release"?"\u{1F680}":"\u2728"} ${e.branch}`;r.info(`${t} ${o} ${s}`);let i=e.aheadBehind!=="unknown"?` | ${e.aheadBehind}`:"";r.info(` \u{1F4DD} ${e.commit}${i}`),r.info(` \u{1F4AC} ${e.lastCommitMessage}`);let l=e.path.split("/").slice(-2).join("/");r.info(` \u{1F4C1} ${l}`)},wt=e=>{switch(e){case"clean":return"\u2705";case"modified":return"\u26A0\uFE0F ";case"dirty":return"\u{1F534}";default:return"\u2753"}},bt={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:we};import Rt from"@inquirer/checkbox";import kt from"@inquirer/confirm";import xt from"node:process";import{z as be}from"zod";import{$ as Ct}from"zx";var Re=async e=>{let{confirmedCommand:t,all:o}=e;c.start("worktrees-remove");try{let n=await E("release");if(n.length===0)return r.info("\u2139\uFE0F No active worktrees to remove"),c.print(),{content:[{type:"text",text:JSON.stringify({removedWorktrees:[],count:0},null,2)}],structuredContent:{removedWorktrees:[],count:0}};let i=`${await y()}${M}`,l=[];o?l=n:(c.setInteractive(),l=await Rt({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(d=>({name:d.replace("release/v",""),value:d}))}));let a=l.length===n.length;a?c.addOption("--all",!0):c.addOption("--branches",l);let m=t?!0:await kt({message:"Are you sure you want to proceed with these worktree changes?"});t||c.setInteractive(),m||(r.info("Operation cancelled. Exiting..."),xt.exit(0)),a&&c.addOption("--yes",!0);let p=await $t(l,i);Et(p),c.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}},$t=async(e,t)=>{let o=[];for(let n of e)try{let s=`${t}/${n}`;await Ct`git worktree remove ${s}`,o.push(n)}catch(s){r.error({error:s,branch:n},`\u274C Failed to remove worktree for ${n}`)}return o},Et=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
|
|
33
|
+
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},St={name:"worktrees-remove",description:"Remove selected worktrees",inputSchema:{all:be.boolean().describe("Remove all worktrees without prompting")},outputSchema:{removedWorktrees:be.array(be.string()).describe("List of removed worktree branches"),count:be.number().describe("Number of worktrees removed")},handler:Re};import Tt from"@inquirer/confirm";import At from"node:process";import{z as Me}from"zod";import{$ as Pt}from"zx";var It="release/v",ke=async e=>{let{confirmedCommand:t}=e;c.start("worktrees-sync");try{let o=await E("release"),s=`${await y()}${M}`,i=await h(),l=t?!0:await Tt({message:"Are you sure you want to proceed with these worktree changes?"});t||c.setInteractive(),l||(r.info("Operation cancelled. Exiting..."),At.exit(0)),t||c.addOption("--yes",!0);let{branchesToRemove:a}=Nt({releasePRsList:i,currentWorktrees:o}),m=await Dt(a,s);Ot(m),c.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}},Nt=e=>{let{releasePRsList:t,currentWorktrees:o}=e;return{branchesToRemove:o.filter(i=>i.startsWith(It)).filter(i=>!t.includes(i))}},Dt=async(e,t)=>{let o=[];for(let n of e)try{let s=`${t}/${n}`;await Pt`git worktree remove ${s}`,o.push(n)}catch(s){r.error({error:s,branch:n},`\u274C Failed to remove worktree for ${n}`)}return o},Ot=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
|
|
34
|
+
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},_t={name:"worktrees-sync",description:"Synchronize worktrees with active release branches",inputSchema:{},outputSchema:{removedWorktrees:Me.array(Me.string()).describe("List of removed worktree branches"),count:Me.number().describe("Number of worktrees removed during sync")},handler:ke};import{config as Jt}from"dotenv";import{resolve as jt}from"node:path";import{$ as nr}from"zx";var Fe=async()=>{try{nr.quiet=!0;let e=await y();Jt({path:jt(e,".env"),quiet:!0}),r.info("Loaded .env file from git repository root")}catch{}finally{nr.quiet=!1}};await Fe();var v=new Lt;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 ce({all:e.all,confirmedCommand:e.yes})});v.command("release-list").description("List all release branches").action(async()=>{await ge()});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 he({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 ve({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 me({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 fe({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 de({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 pe({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 ke({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 ye({confirmedCommand:e.yes,all:e.all,cursor:e.cursor})});v.command("worktrees-list").description("List all git worktrees with detailed information").action(async()=>{await we()});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 Re({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 ie()});v.command("env-list").description("List available Doppler configs for the detected project").action(async()=>{await te()});v.command("env-load").description("Load environment variables from Doppler. Usage: source <(infra-kit env-load -c dev)").requiredOption("-c, --config <config>","Environment config name to load (e.g. dev, arthur)").action(async e=>{await se({config:e.config})});v.command("env-clear").description("Clear previously loaded environment variables. Usage: source <(infra-kit env-clear)").action(async()=>{await re()});v.parse();
|
|
21
35
|
//# sourceMappingURL=cli.js.map
|