infra-kit 0.1.58 → 0.1.59
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 +15 -15
- package/dist/cli.js.map +4 -4
- package/dist/mcp.js +15 -15
- package/dist/mcp.js.map +4 -4
- package/package.json +7 -6
- package/src/commands/{gh-release-deploy/gh-release-deploy.ts → gh-release-deploy-all/gh-release-deploy-all.ts} +5 -5
- package/src/commands/gh-release-deploy-all/index.ts +1 -0
- package/src/commands/gh-release-deploy-service/gh-release-deploy-service.ts +159 -0
- package/src/commands/gh-release-deploy-service/index.ts +1 -0
- package/src/commands/release-create/release-create.ts +1 -1
- package/src/entry/cli.ts +14 -3
- package/src/lib/git-utils/git-utils.ts +1 -0
- package/src/lib/load-env/load-env.ts +4 -4
- package/src/mcp/tools/index.ts +4 -2
- package/src/commands/gh-release-deploy/index.ts +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import{Command as
|
|
2
|
-
\u26A0\uFE0F ${
|
|
1
|
+
import{Command as Lr}from"commander";import Ne from"@inquirer/checkbox";import je from"@inquirer/confirm";import Ie from"node:process";import{z as S}from"zod";import{$ as y}from"zx";import fe from"node:process";import{$ as he}from"zx";import Ee from"node:process";import Ae from"pino";import Je from"pino-pretty";var Te=()=>{let e=Ee.argv.includes("--debug")?"debug":"info",t=["time","pid","hostname"];return e==="debug"&&t.push("level"),Ae({level:e},Je({ignore:t.join(","),colorize:!0}))},r=Te();var O=async()=>{try{await he`gh --version`}catch(e){r.error({error:e},"Error: GitHub CLI (gh) is not installed."),r.error("Please install it from: https://cli.github.com/"),fe.exit(1)}try{await he`gh auth status`}catch(e){r.error({error:e},"Error: GitHub CLI (gh) is not authenticated."),r.error('Please authenticate it from: https://cli.github.com/manual/gh_auth_login or type "gh auth login"'),fe.exit(1)}};import ve from"node:process";import{$ as w}from"zx";var ee=e=>e.replace("release/","").slice(1).split(".").map(Number),re=e=>[...e].sort((t,i)=>{let[o,s,a]=ee(t),[n,c,l]=ee(i);return o!==n?(o??0)-(n??0):s!==c?(s??0)-(c??0):(a??0)-(l??0)});var d=async()=>{try{let e=await w`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..."),ve.exit(1));let i=t.map(o=>o.headRefName);return re(i)}catch(e){r.error({error:e},"\u274C Error fetching release PRs"),ve.exit(1)}},B=async e=>{let{version:t,jiraVersionUrl:i}=e,o=`release/v${t}`;try{w.quiet=!0,await w`git switch dev`,await w`git pull origin dev`,await w`git checkout -b ${o}`,await w`git push -u origin ${o}`,await w`git commit --allow-empty-message --allow-empty --message ''`,await w`git push origin ${o}`;let a=(await w`gh pr create --title "Release v${t}" --body "${i} \n" --base dev --head ${o}`).stdout.trim();return await w`git switch dev`,w.quiet=!1,{branchName:o,prUrl:a}}catch(s){throw r.error({error:s,branchName:o},`Error creating release branch ${o}`),s}};var L=async e=>{let{all:t,confirmedCommand:i}=e,o=await d(),s=[];t?s=o:s=await Ne({required:!0,message:"\u{1F33F} Select release branches",choices:o.map(l=>({name:l.replace("release/v",""),value:l}))}),i||await je({message:`Are you sure you want to merge dev into these branches: ${s.join(", ")}?`})||(r.info("Operation cancelled. Exiting..."),Ie.exit(0)),y.quiet=!0,await y`git fetch origin`,await y`git switch dev`,await y`git pull origin dev`;let n=[];for(let l of s)await De(l)||n.push(l);if(y.quiet=!1,n.length>0){r.info(`
|
|
2
|
+
\u26A0\uFE0F ${n.length} branch(es) failed to merge automatically.
|
|
3
3
|
`),r.info(`\u{1F4CB} Manual merge script for failed branches:
|
|
4
|
-
`),r.info("```bash");for(let l of
|
|
5
|
-
`);throw new Error(
|
|
4
|
+
`),r.info("```bash");for(let l of n)r.info(`# Phase #1: Merge dev into ${l}`),r.info(`git switch ${l} && git pull origin ${l} && git merge origin/dev`),r.info("# Phase #2:Resolve conflicts if any, then:"),r.info(`git push origin ${l} && git switch dev`);r.info(`\u2705 ${s.length-n.length}/${s.length} merges completed successfully.`)}else r.info("\u2705 All merges completed successfully!");let c={successfulMerges:s.length-n.length,failedMerges:n.length,failedBranches:n,totalBranches:s.length};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}},De=async e=>{try{return await y`git switch ${e}`,await y`git pull origin ${e}`,await y`git merge origin/dev --no-edit`,await y`git push origin ${e}`,await y`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 y`git reset --merge HEAD~1`,!1}},We={name:"gh-merge-dev",description:"Merge dev branch into selected release branches",inputSchema:{all:S.boolean().describe("Merge dev into all release branches without prompting")},outputSchema:{successfulMerges:S.number().describe("Number of successful merges"),failedMerges:S.number().describe("Number of failed merges"),failedBranches:S.array(S.string()).describe("List of branches that failed to merge"),totalBranches:S.number().describe("Total number of branches processed")},handler:L};import Ve from"@inquirer/confirm";import Me from"@inquirer/select";import ie from"node:process";import{z as V}from"zod";import{$ as k}from"zx";import N from"node:process";var te=async(e,t)=>{try{let{baseUrl:i,token:o,email:s,projectId:a}=t,n={name:e.name,projectId:e.projectId||a,description:e.description||"",released:e.released||!1,archived:e.archived||!1},c=`${i}/rest/api/3/version`,l=btoa(`${s}:${o}`),m=await fetch(c,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${l}`},body:JSON.stringify(n)});if(!m.ok){let u=await m.text();throw r.error({status:m.status,statusText:m.statusText,error:u},"Failed to create Jira version"),new Error(`HTTP ${m.status}: ${m.statusText}`)}return{success:!0,version:await m.json()}}catch(i){throw r.error({error:i},"Error creating Jira version"),i}},Oe=async e=>{try{let{baseUrl:t,token:i,email:o,projectId:s}=e,a=`${t}/rest/api/3/project/${s}/versions`,n=btoa(`${o}:${i}`),c=await fetch(a,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${n}`}});if(!c.ok){let m=await c.text();throw r.error({status:c.status,statusText:c.statusText,error:m},"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}},Be=async(e,t)=>{try{return(await Oe(t)).find(s=>s.name===e)||null}catch(i){throw r.error({error:i,versionName:e},"Error finding Jira version by name"),i}},Le=async(e,t)=>{try{let{baseUrl:i,token:o,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 n=`${i}/rest/api/3/version/${e.versionId}`,c=btoa(`${s}:${o}`),l=await fetch(n,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Basic ${c}`},body:JSON.stringify(a)});if(!l.ok){let p=await l.text();throw r.error({status:l.status,statusText:l.statusText,error:p},"Failed to update Jira version"),new Error(`HTTP ${l.status}: ${l.statusText}`)}return{success:!0,version:await l.json()}}catch(i){throw r.error({error:i},"Error updating Jira version"),i}},oe=async(e,t)=>{try{let{versionName:i}=e,o=await Be(i,t);if(!o)throw r.error({versionName:i},"Jira version not found"),new Error(`Version "${i}" not found in Jira project`);return await Le({versionId:o.id,released:!0,releaseDate:new Date().toISOString().split("T")[0]},t)}catch(i){throw r.error({error:i},"Error delivering Jira release"),i}},E=async()=>{let e=N.env.JIRA_BASE_URL,t=N.env.JIRA_TOKEN||N.env.JIRA_API_TOKEN,i=N.env.JIRA_PROJECT_ID,o=N.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)"),i||s.push("JIRA_PROJECT_ID (numeric project ID)"),o||s.push("JIRA_EMAIL (your Jira email address)"),s.length>0){let n=["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(`
|
|
5
|
+
`);throw new Error(n)}let a=Number.parseInt(i,10);if(Number.isNaN(a))throw new TypeError(`Invalid JIRA_PROJECT_ID: "${i}" must be a numeric value (e.g., 10001)`);return{baseUrl:e.replace(/\/$/,""),token:t,projectId:a,email:o}},se=async()=>{try{return await E()}catch(e){return r.warn({error:e},"Jira configuration not available, skipping Jira integration"),null}};var M=async e=>{let{version:t,confirmedCommand:i}=e,o=await d(),s="";t?s=`release/v${t}`:s=await Me({message:"\u{1F33F} Select release branch",choices:o.map(n=>({name:n.replace("release/v",""),value:n}))}),o.includes(s)||(r.error(`\u274C Release branch ${s} not found in open PRs. Exiting...`),ie.exit(1)),i||await Ve({message:`Are you sure you want to deliver version ${s} to production?`})||(r.info("Operation cancelled. Exiting..."),ie.exit(0));try{k.quiet=!0,await k`gh pr merge ${s} --squash --admin --delete-branch`,await k`gh pr create --base main --head dev --title "Release v${s.replace("release/v","")} (RC)" --body ""`,await k`gh pr merge dev --squash --admin`,k.quiet=!1,await k`gh workflow run deploy-all.yml --ref main -f environment=prod`,k.quiet=!0,await k`git switch main && git pull && git switch dev && git pull && git merge main --no-edit && git push`,k.quiet=!1;let n=await se();if(n)try{let l=s.replace("release/","");await oe({versionName:l},n)}catch(l){r.error({error:l},"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!`);let c={releaseBranch:s,version:s.replace("release/v",""),success:!0};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}}catch(n){r.error({error:n},"\u274C Error merging release branch into dev"),ie.exit(1)}},Ue={name:"gh-release-deliver",description:"Deliver a release branch to production",inputSchema:{version:V.string().describe('Version to deliver to production (e.g., "1.2.5")')},outputSchema:{releaseBranch:V.string().describe("The release branch that was delivered"),version:V.string().describe("The version that was delivered"),success:V.boolean().describe("Whether the delivery was successful")},handler:M};import we from"@inquirer/select";import ne from"node:process";import{z as T}from"zod";import{$ as ae}from"zx";var A=["dev","arthur","renana","roman","eliran","oriana"],J="-worktrees";var U=async e=>{let{version:t,env:i}=e,o=["dev"],s=await d();o.push(...s);let a="";t?a=`release/v${t}`:a=await we({message:"\u{1F33F} Select release branch",choices:o.map(c=>({name:c.replace("release/v",""),value:c}))}),o.includes(a)||(r.error(`\u274C Release branch ${a} not found in open PRs. Exiting...`),ne.exit(1));let n="";i?n=i:n=await we({message:"\u{1F9EA} Select environment",choices:A.map(c=>({name:c,value:c}))}),A.includes(n)||(r.error(`\u274C Invalid environment: ${n}. Exiting...`),ne.exit(1));try{ae.quiet=!0,await ae`gh workflow run deploy-all.yml --ref ${a} -f environment=${n}`,ae.quiet=!1,r.info(`Successfully launched deploy-all workflow_dispatch for release branch: ${a} and environment: ${n}`);let c={releaseBranch:a,version:a.replace("release/v",""),environment:n,success:!0};return{content:[{type:"text",text:JSON.stringify(c,null,2)}],structuredContent:c}}catch(c){r.error({error:c},"\u274C Error launching workflow"),ne.exit(1)}},qe={name:"gh-release-deploy-all",description:"Deploy 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")')},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"),success:T.boolean().describe("Whether the deployment was successful")},handler:U};import ce from"@inquirer/select";import Ge from"node:fs/promises";import{resolve as ze}from"node:path";import q from"node:process";import He from"yaml";import{z as $}from"zod";import{$ as le}from"zx";import{$ as ye}from"zx";var R=async e=>{let i=(await ye`git worktree list`).stdout.split(`
|
|
6
|
+
`).filter(Boolean),o={release:_e,feature:Fe};return i.map(o[e]).filter(s=>s!==null)},_e=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("release/v")?null:`release/${t[0]?.split("/").pop()||""}`},Fe=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("feature/")?null:`feature/${t[0]?.split("/").pop()||""}`},f=async()=>(await ye`git rev-parse --show-toplevel`).stdout.trim();var _=async e=>{let{version:t,env:i,service:o}=e,s=["dev"],a=await d();s.push(...a);let n="";t?n=`release/v${t}`:n=await ce({message:"\u{1F33F} Select release branch",choices:s.map(p=>({name:p.replace("release/v",""),value:p}))}),s.includes(n)||(r.error(`\u274C Release branch ${n} not found in open PRs. Exiting...`),q.exit(1));let c="";i?c=i:c=await ce({message:"\u{1F9EA} Select environment",choices:A.map(p=>({name:p,value:p}))}),A.includes(c)||(r.error(`\u274C Invalid environment: ${c}. Exiting...`),q.exit(1));let l=await Ke(),m="";o?m=o:m=await ce({message:"\u{1F680} Select service to deploy",choices:l.map(p=>({name:p,value:p}))}),l.includes(m)||(r.error(`\u274C Invalid service: ${m}. Available services: ${l.join(", ")}`),q.exit(1));try{le.quiet=!0,await le`gh workflow run deploy-single-service.yml --ref ${n} -f environment=${c} -f service=${m}`,le.quiet=!1,r.info(`Successfully launched deploy-single-service workflow_dispatch for release branch: ${n}, environment: ${c}, service: ${m}`);let p={releaseBranch:n,version:n.replace("release/v",""),environment:c,service:m,success:!0};return{content:[{type:"text",text:JSON.stringify(p,null,2)}],structuredContent:p}}catch(p){r.error({error:p},"\u274C Error launching workflow"),q.exit(1)}},Ke=async()=>{let e=await f(),t=ze(e,".github/workflows/deploy-single-service.yml"),i=await Ge.readFile(t,"utf-8");return He.parse(i).on.workflow_dispatch.inputs.service.options},Xe={name:"gh-release-deploy-service",description:"Deploy a specific service in a release branch to a specified environment",inputSchema:{version:$.string().describe('Version to deploy (e.g., "1.2.5")'),env:$.string().describe('Environment to deploy to (e.g., "dev", "renana", "oriana")'),service:$.string().describe('Service to deploy (e.g., "client-be", "client-fe")')},outputSchema:{releaseBranch:$.string().describe("The release branch that was deployed"),version:$.string().describe("The version that was deployed"),environment:$.string().describe("The environment deployed to"),service:$.string().describe("The service that was deployed"),success:$.boolean().describe("Whether the deployment was successful")},handler:_};import{z as me}from"zod";var F=async()=>{let t=(await d()).map(o=>o.replace("release/",""));r.info(`All release branches:
|
|
6
7
|
`),r.info(`
|
|
7
8
|
${t.join(`
|
|
8
|
-
`)}`);let i={releases:t,count:t.length};return{content:[{type:"text",text:JSON.stringify(i,null,2)}],structuredContent:i}},
|
|
9
|
-
`)}catch(
|
|
10
|
-
`)}let p=l.length,u=m.length;p===
|
|
11
|
-
`).filter(Boolean),o={release:_e,feature:Fe};return i.map(o[e]).filter(s=>s!==null)},_e=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("release/v")?null:`release/${t[0]?.split("/").pop()||""}`},Fe=e=>{let t=e.split(" ").filter(Boolean);return t.length<3||!t[0]?.includes("feature/")?null:`feature/${t[0]?.split("/").pop()||""}`},k=async()=>(await ye`git rev-parse --show-toplevel`).stdout.trim();var Ke="feature",Xe="release",Ye="release/v",F=async e=>{let{confirmedCommand:t,all:i}=e;try{let o=await b("release"),n=`${await k()}${J}`;await be(`${n}/${Xe}`),await be(`${n}/${Ke}`);let a=await d(),c=[];i?c=a:c=await Ge({required:!0,message:"\u{1F33F} Select release branches",choices:a.map(y=>({name:y.replace("release/v",""),value:y}))}),t||await ze({message:"Are you sure you want to proceed with these worktree changes?"})||(r.info("Operation cancelled. Exiting..."),He.exit(0));let{branchesToCreate:m}=Qe({selectedReleaseBranches:c,currentWorktrees:o}),p=await Ze(m,n);er(p);let u={createdWorktrees:p,count:p.length};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(o){throw r.error({error:o},"\u274C Error managing worktrees"),o}},be=async e=>{await Re`mkdir -p ${e}`},Qe=e=>{let{selectedReleaseBranches:t,currentWorktrees:i}=e,o=i.filter(n=>n.startsWith(Ye));return{branchesToCreate:t.filter(n=>!o.includes(n))}},Ze=async(e,t)=>{let i=[];for(let o of e)try{let s=`${t}/${o}`;await Re`git worktree add ${s} ${o}`,i.push(o)}catch(s){r.error({error:s,branch:o},`\u274C Failed to create worktree for ${o}`)}return i},er=e=>{e.length>0?(r.info(`
|
|
9
|
+
`)}`);let i={releases:t,count:t.length};return{content:[{type:"text",text:JSON.stringify(i,null,2)}],structuredContent:i}},Ye={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:F};import be from"@inquirer/confirm";import Re from"node:process";import{z as C}from"zod";import{$ as pe,question as ke}from"zx";import{$ as j}from"zx";var I=async()=>{j.quiet=!0,await j`git fetch origin`,await j`git switch dev`,await j`git pull origin dev`,j.quiet=!1},D=async(e,t,i)=>{let o=`v${e}`,s=await te({name:o,projectId:t.projectId,description:i||"",released:!1,archived:!1},t),a=`${t.baseUrl}/projects/${s.version.projectId}/versions/${s.version.id}/tab/release-report-all-issues`,n=await B({version:e,jiraVersionUrl:a});return{version:e,branchName:n.branchName,prUrl:n.prUrl,jiraVersionUrl:a}};var G=async e=>{let{version:t,description:i,confirmedCommand:o,checkout:s}=e,a=t,n=i,c=s,l=await E();a||(a=await ke("Enter version (e.g. 1.2.5): ")),(!a||a.trim()==="")&&(r.error("No version provided. Exiting..."),Re.exit(1));let m=a.trim();n===void 0&&(n=await ke("Enter description (optional, press Enter to skip): "),n.trim()===""&&(n="")),o||await be({message:`Are you sure you want to create release branch for version ${m}?`})||(r.info("Operation cancelled. Exiting..."),Re.exit(0)),await I();let u=await D(m,l,n);r.info(`\u2705 Successfully created release: v${m}`),r.info(`\u{1F517} GitHub PR: ${u.prUrl}`),r.info(`\u{1F517} Jira Version: ${u.jiraVersionUrl}`),c===void 0&&(c=await be({message:`Do you want to checkout to the created branch ${u.branchName}?`,default:!0})),c&&(pe.quiet=!0,await pe`git switch ${u.branchName}`,pe.quiet=!1,r.info(`\u{1F504} Switched to branch ${u.branchName}`));let b={version:m,branchName:u.branchName,prUrl:u.prUrl,jiraVersionUrl:u.jiraVersionUrl,isCheckedOut:c};return{content:[{type:"text",text:JSON.stringify(b,null,2)}],structuredContent:b}},Qe={name:"release-create",description:"Create a single release branch for specified version with Jira version creation",inputSchema:{version:C.string().describe('Version to create (e.g., "1.2.5")'),description:C.string().optional().describe("Optional description for the Jira version"),checkout:C.boolean().optional().default(!0).describe("Checkout to the created branch (default: true)")},outputSchema:{version:C.string().describe("Version number"),branchName:C.string().describe("Release branch name"),prUrl:C.string().describe("GitHub PR URL"),jiraVersionUrl:C.string().describe("Jira version URL"),isCheckedOut:C.boolean().describe("Whether the branch was checked out")},handler:G};import Ze from"@inquirer/confirm";import xe from"node:process";import{z as g}from"zod";import{question as er}from"zx";var z=async e=>{let{versions:t,description:i,confirmedCommand:o}=e,s=t,a=await E();s||(s=await er("Enter versions by comma (e.g. 1.2.5, 1.2.6): "));let n=s.split(",").map(x=>x.trim());n.length===0&&(r.error("No versions provided. Exiting..."),xe.exit(1)),n.length===1&&r.warn('\u{1F4A1} You are creating only one release. Consider using "create-release" command for single releases.'),o||await Ze({message:`Are you sure you want to create release branches for these versions: ${n.join(", ")}?`})||(r.info("Operation cancelled. Exiting..."),xe.exit(0)),await I();let l=[],m=[];for(let x of n)try{let P=await D(x,a,i);l.push(P),r.info(`\u2705 Successfully created release: v${x}`),r.info(`\u{1F517} GitHub PR: ${P.prUrl}`),r.info(`\u{1F517} Jira Version: ${P.jiraVersionUrl}
|
|
10
|
+
`)}catch(P){let ge=P instanceof Error?P.message:String(P);m.push({version:x,error:ge}),r.error(`\u274C Failed to create release: v${x}`),r.error(` Error: ${ge}
|
|
11
|
+
`)}let p=l.length,u=m.length;p===n.length?r.info(`\u2705 All ${n.length} release branches were created successfully.`):p>0?(r.warn(`\u26A0\uFE0F ${p} of ${n.length} release branches were created successfully.`),r.warn(`\u274C ${u} release(s) failed.`)):r.error(`\u274C All ${n.length} release branches failed to create.`);let b={createdBranches:l.map(x=>x.branchName),successCount:p,failureCount:u,releases:l,failedReleases:m};return{content:[{type:"text",text:JSON.stringify(b,null,2)}],structuredContent:b}},rr={name:"release-create-batch",description:"Create multiple release branches for specified versions with Jira version creation (batch operation)",inputSchema:{versions:g.string().describe('Comma-separated list of versions to create (e.g., "1.2.5, 1.2.6")'),description:g.string().optional().describe("Optional description for the Jira versions")},outputSchema:{createdBranches:g.array(g.string()).describe("List of created release branches"),successCount:g.number().describe("Number of releases created successfully"),failureCount:g.number().describe("Number of releases that failed"),releases:g.array(g.object({version:g.string().describe("Version number"),branchName:g.string().describe("Release branch name"),prUrl:g.string().describe("GitHub PR URL"),jiraVersionUrl:g.string().describe("Jira version URL")})).describe("Detailed information for each created release with URLs"),failedReleases:g.array(g.object({version:g.string().describe("Version number that failed"),error:g.string().describe("Error message")})).describe("List of releases that failed with error messages")},handler:z};import tr from"@inquirer/checkbox";import or from"@inquirer/confirm";import sr from"node:process";import{z as H}from"zod";import{$ as Ce}from"zx";var ir="feature",nr="release",ar="release/v",K=async e=>{let{confirmedCommand:t,all:i}=e;try{let o=await R("release"),a=`${await f()}${J}`;await $e(`${a}/${nr}`),await $e(`${a}/${ir}`);let n=await d(),c=[];i?c=n:c=await tr({required:!0,message:"\u{1F33F} Select release branches",choices:n.map(b=>({name:b.replace("release/v",""),value:b}))}),t||await or({message:"Are you sure you want to proceed with these worktree changes?"})||(r.info("Operation cancelled. Exiting..."),sr.exit(0));let{branchesToCreate:m}=cr({selectedReleaseBranches:c,currentWorktrees:o}),p=await lr(m,a);mr(p);let u={createdWorktrees:p,count:p.length};return{content:[{type:"text",text:JSON.stringify(u,null,2)}],structuredContent:u}}catch(o){throw r.error({error:o},"\u274C Error managing worktrees"),o}},$e=async e=>{await Ce`mkdir -p ${e}`},cr=e=>{let{selectedReleaseBranches:t,currentWorktrees:i}=e,o=i.filter(a=>a.startsWith(ar));return{branchesToCreate:t.filter(a=>!o.includes(a))}},lr=async(e,t)=>{let i=[];for(let o of e)try{let s=`${t}/${o}`;await Ce`git worktree add ${s} ${o}`,i.push(o)}catch(s){r.error({error:s,branch:o},`\u274C Failed to create worktree for ${o}`)}return i},mr=e=>{e.length>0?(r.info(`
|
|
12
12
|
`),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 i.length===0?"clean":i.length<=3?"modified":"dirty"}catch{return"unknown"}},
|
|
13
|
+
`)),r.info("")):r.info("\u2139\uFE0F No new worktrees to create")},pr={name:"worktrees-add",description:"Create worktrees for selected release branches",inputSchema:{all:H.boolean().describe("Add worktrees for all release branches without prompting")},outputSchema:{createdWorktrees:H.array(H.string()).describe("List of created worktree branches"),count:H.number().describe("Number of worktrees created")},handler:K};import{z as h}from"zod";import{$ as W}from"zx";var X=async()=>{try{let[e,t]=await Promise.all([R("release"),R("feature")]),i=await f(),o=await ur(e,t,i);wr(o);let s={worktrees:o,totalCount:o.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}},ur=async(e,t,i)=>{let o=[...e.map(a=>({branch:a,type:"release"})),...t.map(a=>({branch:a,type:"feature"}))],s=[];for(let{branch:a,type:n}of o)try{let c=`${i}/${a}`,l=await dr(a),m=await gr(c),p=await fr(c),u=await hr(c),b=await vr(c);s.push({branch:a,path:c,commit:m.substring(0,8),isCurrent:l,type:n,status:p,lastCommitMessage:u.substring(0,60)+(u.length>60?"...":""),aheadBehind:b})}catch(c){r.warn({error:c,branch:a},`\u26A0\uFE0F Could not process worktree ${a}`)}return s.sort((a,n)=>a.type!==n.type?a.type==="release"?-1:1:a.branch.localeCompare(n.branch))},dr=async e=>{try{return(await W`git branch --show-current`).stdout.trim()===e}catch{return!1}},gr=async e=>{try{return(await W`cd ${e} && git rev-parse HEAD`).stdout.trim()}catch{return"unknown"}},fr=async e=>{try{let i=(await W`cd ${e} && git status --porcelain`).stdout.trim().split(`
|
|
14
|
+
`).filter(Boolean);return i.length===0?"clean":i.length<=3?"modified":"dirty"}catch{return"unknown"}},hr=async e=>{try{return(await W`cd ${e} && git log -1 --pretty=format:"%s"`).stdout.trim()}catch{return"No commit message available"}},vr=async e=>{try{let i=(await W`cd ${e} && git rev-list --count --left-right @{u}...HEAD 2>/dev/null || echo "0 0"`).stdout.trim().split(" ").map(Number),o=i[0]||0,s=i[1]||0;return s===0&&o===0?"up to date":s>0&&o===0?`\u2191${s} ahead`:o>0&&s===0?`\u2193${o} behind`:`\u2191${s} \u2193${o}`}catch{return"unknown"}},wr=e=>{if(e.length===0){r.info(`
|
|
15
15
|
\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 t=e.filter(s=>s.type==="release"),i=e.filter(s=>s.type==="feature");
|
|
17
|
-
${"\u2550".repeat(100)}`),r.info(`\u{1F4CA} Summary: ${e.length} total worktrees (${t.length} releases, ${i.length} features)`),o&&r.info(`\u{1F4CD} Currently on: ${o.branch}`),r.info("")},
|
|
18
|
-
${e}`),r.info("\u2500".repeat(50));for(let[i,o]of t.entries())
|
|
19
|
-
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},
|
|
20
|
-
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},
|
|
16
|
+
\u{1F33F} Git Worktrees`),r.info("\u2550".repeat(100));let t=e.filter(s=>s.type==="release"),i=e.filter(s=>s.type==="feature");Pe("\u{1F680} Releases",t),i.length>0&&t.length>0&&r.info(""),Pe("\u2728 Features",i);let o=e.find(s=>s.isCurrent);r.info(`
|
|
17
|
+
${"\u2550".repeat(100)}`),r.info(`\u{1F4CA} Summary: ${e.length} total worktrees (${t.length} releases, ${i.length} features)`),o&&r.info(`\u{1F4CD} Currently on: ${o.branch}`),r.info("")},Pe=(e,t)=>{if(t.length!==0){r.info(`
|
|
18
|
+
${e}`),r.info("\u2500".repeat(50));for(let[i,o]of t.entries())yr(o),i<t.length-1&&r.info("")}},yr=e=>{let t=e.isCurrent?"\u{1F4CD}":" ",i=br(e.status),s=`${e.type==="release"?"\u{1F680}":"\u2728"} ${e.branch}`;r.info(`${t} ${i} ${s}`);let a=e.aheadBehind!=="unknown"?` | ${e.aheadBehind}`:"";r.info(` \u{1F4DD} ${e.commit}${a}`),r.info(` \u{1F4AC} ${e.lastCommitMessage}`);let n=e.path.split("/").slice(-2).join("/");r.info(` \u{1F4C1} ${n}`)},br=e=>{switch(e){case"clean":return"\u2705";case"modified":return"\u26A0\uFE0F ";case"dirty":return"\u{1F534}";default:return"\u2753"}},Rr={name:"worktrees-list",description:"List all git worktrees with detailed information",inputSchema:{},outputSchema:{worktrees:h.array(h.object({branch:h.string(),path:h.string(),commit:h.string(),isCurrent:h.boolean(),type:h.enum(["release","feature"]),status:h.string(),lastCommitMessage:h.string(),aheadBehind:h.string()})).describe("List of all worktrees with details"),totalCount:h.number().describe("Total number of worktrees"),releaseCount:h.number().describe("Number of release worktrees"),featureCount:h.number().describe("Number of feature worktrees")},handler:X};import kr from"@inquirer/checkbox";import xr from"@inquirer/confirm";import $r from"node:process";import{z as Y}from"zod";import{$ as Cr}from"zx";var Q=async e=>{let{confirmedCommand:t,all:i}=e;try{let o=await R("release"),a=`${await f()}${J}`,n=[];i?n=o:n=await kr({required:!0,message:"\u{1F33F} Select release branches",choices:o.map(p=>({name:p.replace("release/v",""),value:p}))}),t||await xr({message:"Are you sure you want to proceed with these worktree changes?"})||(r.info("Operation cancelled. Exiting..."),$r.exit(0));let l=await Pr(n,a);Sr(l);let m={removedWorktrees:l,count:l.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(o){throw r.error({error:o},"\u274C Error managing worktrees"),o}},Pr=async(e,t)=>{let i=[];for(let o of e)try{let s=`${t}/${o}`;await Cr`git worktree remove ${s}`,i.push(o)}catch(s){r.error({error:s,branch:o},`\u274C Failed to remove worktree for ${o}`)}return i},Sr=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
|
|
19
|
+
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},Er={name:"worktrees-remove",description:"Remove selected worktrees",inputSchema:{all:Y.boolean().describe("Remove all worktrees without prompting")},outputSchema:{removedWorktrees:Y.array(Y.string()).describe("List of removed worktree branches"),count:Y.number().describe("Number of worktrees removed")},handler:Q};import Ar from"@inquirer/confirm";import Jr from"node:process";import{z as ue}from"zod";import{$ as Tr}from"zx";var Nr="release/v",Z=async e=>{let{confirmedCommand:t}=e;try{let i=await R("release"),s=`${await f()}${J}`,a=await d();t||await Ar({message:"Are you sure you want to proceed with these worktree changes?"})||(r.info("Operation cancelled. Exiting..."),Jr.exit(0));let{branchesToRemove:c}=jr({releasePRsList:a,currentWorktrees:i}),l=await Ir(c,s);Dr(l);let m={removedWorktrees:l,count:l.length};return{content:[{type:"text",text:JSON.stringify(m,null,2)}],structuredContent:m}}catch(i){throw r.error({error:i},"\u274C Error managing worktrees"),i}},jr=e=>{let{releasePRsList:t,currentWorktrees:i}=e;return{branchesToRemove:i.filter(a=>a.startsWith(Nr)).filter(a=>!t.includes(a))}},Ir=async(e,t)=>{let i=[];for(let o of e)try{let s=`${t}/${o}`;await Tr`git worktree remove ${s}`,i.push(o)}catch(s){r.error({error:s,branch:o},`\u274C Failed to remove worktree for ${o}`)}return i},Dr=e=>{e.length>0?(r.info("\u274C Removed worktrees:"),r.info(e.join(`
|
|
20
|
+
`)),r.info("")):r.info("\u2139\uFE0F No unused worktrees to remove")},Wr={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:Z};import{config as Or}from"dotenv";import{resolve as Br}from"node:path";import{$ as Se}from"zx";var de=async()=>{try{Se.quiet=!0;let e=await f();Or({path:Br(e,".env"),quiet:!0}),r.info("Loaded .env file from git repository root")}catch{}finally{Se.quiet=!1}};await de();var v=new Lr;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 L({all:e.all,confirmedCommand:e.yes})});v.command("release-list").description("List all release branches").action(async()=>{await F()});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 G({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 z({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").action(async e=>{await U({version:e.version,env:e.env})});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").action(async e=>{await _({version:e.version,env:e.env,service:e.service})});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 M({version:e.version,confirmedCommand:e.yes})});v.command("worktrees-sync").description("Sync git worktrees for release branches").option("-y, --yes","Skip confirmation prompt").action(async e=>{await Z({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").action(async e=>{await K({confirmedCommand:e.yes,all:e.all})});v.command("worktrees-list").description("List all git worktrees with detailed information").action(async()=>{await X()});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 Q({confirmedCommand:e.yes,all:e.all})});await O();v.parse();
|
|
21
21
|
//# sourceMappingURL=cli.js.map
|