1- import { Jira } from "../src/jira" ;
2- import { PackageListing , selectPackage } from "../src/monorepo" ;
1+ import { Jira , JiraVersion } from "../src/jira" ;
32import chalk from "chalk" ;
43import { prompt } from "enquirer" ;
5- import { getNextVersion , writeVersion } from "../src/bump-version" ;
4+ import { bumpPackageJson , bumpXml , getNextVersion } from "../src/bump-version" ;
65import { exec } from "../src/shell" ;
76import { gh } from "../src/github" ;
7+ import { printGithubAuthHelp } from "../src/cli-utils" ;
8+ import { printPkgInformation , selectPackageV2 } from "../src/prepare-release-helpers" ;
89
910async function main ( ) : Promise < void > {
1011 try {
@@ -17,33 +18,32 @@ async function main(): Promise<void> {
1718 await gh . ensureAuth ( ) ;
1819 console . log ( chalk . green ( "✅ GitHub authentication verified" ) ) ;
1920 } catch ( error ) {
20- console . log ( chalk . red ( `❌ GitHub authentication failed: ${ ( error as Error ) . message } ` ) ) ;
21- console . log ( chalk . yellow ( "\n💡 First, make sure GitHub CLI is installed:" ) ) ;
22- console . log ( chalk . cyan ( " Download from: https://cli.github.com/" ) ) ;
23- console . log ( chalk . cyan ( " Or install via brew: brew install gh" ) ) ;
24- console . log ( chalk . yellow ( "\n💡 Then authenticate with GitHub using one of these options:" ) ) ;
25- console . log ( chalk . yellow ( " 1. Set GITHUB_TOKEN environment variable:" ) ) ;
26- console . log ( chalk . cyan ( " export GITHUB_TOKEN=your_token_here" ) ) ;
27- console . log ( chalk . yellow ( " 2. Set GH_PAT environment variable:" ) ) ;
28- console . log ( chalk . cyan ( " export GH_PAT=your_token_here" ) ) ;
29- console . log ( chalk . yellow ( " 3. Use GitHub CLI to authenticate:" ) ) ;
30- console . log ( chalk . cyan ( " gh auth login" ) ) ;
31- console . log ( chalk . yellow ( "\n Get a token at: https://github.com/settings/tokens" ) ) ;
21+ printGithubAuthHelp ( ( error as Error ) . message ) ;
3222 process . exit ( 1 ) ;
3323 }
3424
3525 // Step 1: Initialize Jira client
36- let jira : Jira ;
26+ let jira : Jira | undefined ;
3727 try {
3828 jira = await initializeJiraClient ( ) ;
39- } catch ( error ) {
40- console . log ( chalk . red ( `❌ ${ ( error as Error ) . message } ` ) ) ;
41- process . exit ( 1 ) ;
29+ } catch ( _e ) {
30+ // Ask user if they want to continue without it
31+ const { confirmSkipJira } = await prompt < { confirmSkipJira : boolean } > ( {
32+ type : "confirm" ,
33+ name : "confirmSkipJira" ,
34+ message : `❓ Do you want to skip Jira? You won't be able to create Jira version automatically.` ,
35+ initial : true
36+ } ) ;
37+
38+ if ( ! confirmSkipJira ) {
39+ process . exit ( 1 ) ;
40+ }
4241 }
4342
4443 // Step 2: Select package and determine version
4544 console . log ( chalk . bold ( "\n📋 STEP 2: Package Selection" ) ) ;
46- const { pkg, baseName, nextVersion, jiraVersionName, isVersionBumped } = await selectPackageAndVersion ( ) ;
45+ const { selectedPackage, baseName, nextVersion, jiraVersionName, isVersionBumped } =
46+ await selectPackageAndVersion ( ) ;
4747
4848 // Step 3: Check if Jira version exists
4949 console . log ( chalk . bold ( "\n📋 STEP 3: Jira Version Setup" ) ) ;
@@ -58,11 +58,28 @@ async function main(): Promise<void> {
5858
5959 // Step 4.1: Write versions to the files (if user chose to bump version)
6060 if ( isVersionBumped ) {
61- await writeVersion ( pkg , nextVersion ) ;
62- console . log ( chalk . green ( `✅ Updated ${ baseName } to ${ nextVersion } ` ) ) ;
61+ if ( selectedPackage . type === "module" ) {
62+ bumpPackageJson ( selectedPackage . path , nextVersion ) ;
63+ console . log ( chalk . green ( `✅ Bumped ${ chalk . bold ( selectedPackage . info . name ) } to ${ nextVersion } ` ) ) ;
64+ for ( const widget of selectedPackage . widgets ) {
65+ await bumpXml ( widget . path , nextVersion ) ;
66+ bumpPackageJson ( widget . path , nextVersion ) ;
67+ console . log ( chalk . green ( `✅ Bumped ${ chalk . bold ( widget . info . name ) } to ${ nextVersion } ` ) ) ;
68+ }
69+ } else {
70+ bumpPackageJson ( selectedPackage . path , nextVersion ) ;
71+ await bumpXml ( selectedPackage . path , nextVersion ) ;
72+ console . log ( chalk . green ( `✅ Bumped ${ chalk . bold ( baseName ) } to ${ nextVersion } ` ) ) ;
73+ }
6374
6475 await exec ( `git reset` , { stdio : "pipe" } ) ; // Unstage all files
65- await exec ( `git add ${ pkg . path } ` , { stdio : "pipe" } ) ; // Stage only the package
76+ await exec ( `git add ${ selectedPackage . path } ` , { stdio : "pipe" } ) ; // Stage only the package
77+ if ( selectedPackage . type === "module" ) {
78+ // stage widgets as well
79+ for ( const widget of selectedPackage . widgets ) {
80+ await exec ( `git add ${ widget . path } ` , { stdio : "pipe" } ) ; // Stage only the package
81+ }
82+ }
6683
6784 // Step 4.2: Commit changes
6885 const { confirmCommit } = await prompt < { confirmCommit : boolean } > ( {
@@ -101,10 +118,12 @@ async function main(): Promise<void> {
101118 console . log ( chalk . green ( "✅ Branch pushed to GitHub" ) ) ;
102119
103120 console . log ( chalk . bold ( "\n📋 STEP 5: GitHub Release Workflow" ) ) ;
104- await triggerGitHubReleaseWorkflow ( pkg . name , tmpBranchName ) ;
121+ await triggerGitHubReleaseWorkflow ( selectedPackage . info . name , tmpBranchName ) ;
105122
106- console . log ( chalk . bold ( "\n📋 STEP 6: Jira Issue Management" ) ) ;
107- await manageIssuesForVersion ( jira , jiraVersion . id , jiraVersionName ) ;
123+ if ( jira && jiraVersion ) {
124+ console . log ( chalk . bold ( "\n📋 STEP 6: Jira Issue Management" ) ) ;
125+ await manageIssuesForVersion ( jira , jiraVersion . id , jiraVersionName ) ;
126+ }
108127
109128 console . log ( chalk . cyan ( "\n🎉 Release preparation completed! 🎉" ) ) ;
110129 console . log ( chalk . cyan ( ` Package: ${ baseName } v${ nextVersion } ` ) ) ;
@@ -368,68 +387,69 @@ async function initializeJiraClient(): Promise<Jira> {
368387 // Initialize Jira client
369388 const jira = new Jira ( projectKey , baseUrl , apiToken ) ;
370389
371- // Initialize Jira project data with retry mechanism
372- let initialized = false ;
373- while ( ! initialized ) {
374- try {
375- console . log ( "🔄 Initializing Jira project data..." ) ;
376- await jira . initializeProjectData ( ) ;
377- console . log ( chalk . green ( "✅ Jira project data initialized" ) ) ;
378- initialized = true ;
379- } catch ( error ) {
380- console . error ( chalk . red ( `❌ Jira init failed: ${ ( error as Error ) . message } ` ) ) ;
381-
382- const { retry } = await prompt < { retry : boolean } > ( {
383- type : "confirm" ,
384- name : "retry" ,
385- message : "❓ Retry Jira initialization?" ,
386- initial : true
387- } ) ;
388-
389- if ( ! retry ) {
390- throw new Error ( "Cannot proceed without Jira initialization" ) ;
391- }
392- }
390+ try {
391+ console . log ( "🔄 Initializing Jira project data..." ) ;
392+ await jira . initializeProjectData ( ) ;
393+ console . log ( chalk . green ( "✅ Jira project data initialized" ) ) ;
394+ } catch ( error ) {
395+ console . error ( chalk . red ( `❌ Jira init failed: ${ ( error as Error ) . message } ` ) ) ;
396+ throw new Error ( "Jira initialization failed" ) ;
393397 }
394398
395399 return jira ;
396400}
397401
398402async function selectPackageAndVersion ( ) : Promise < {
399- pkg : PackageListing ;
403+ selectedPackage : Awaited < ReturnType < typeof selectPackageV2 > > ;
400404 baseName : string ;
401405 nextVersion : string ;
402406 jiraVersionName : string ;
403407 isVersionBumped : boolean ;
404408} > {
405- const pkg = await selectPackage ( ) ;
406- const baseName = pkg . name . split ( "/" ) . pop ( ) ! ;
409+ const selectedPackage = await selectPackageV2 ( ) ;
407410
408- console . log ( `📦 Selected: ${ chalk . blue ( baseName ) } (current: ${ chalk . green ( pkg . version ) } )` ) ;
411+ if ( selectedPackage . type === "widget" ) {
412+ console . log ( `📦 Selected widget:` ) ;
413+ } else {
414+ console . log ( `📦 Selected module:` ) ;
415+ }
416+ printPkgInformation ( selectedPackage ) ;
409417
410418 // Ask user if they want to bump the version before showing version selection dialog
411419 const { confirmBumpVersion } = await prompt < { confirmBumpVersion : boolean } > ( {
412420 type : "confirm" ,
413421 name : "confirmBumpVersion" ,
414- message : `❓ Do you want to bump ${ baseName } from version ${ chalk . green ( pkg . version ) } ?` ,
422+ message : `❓ Do you want to bump version for ${ chalk . bold ( selectedPackage . info . name ) } ?` ,
415423 initial : true
416424 } ) ;
417425
418426 // Only call getNextVersion if user wants to bump version
419- let nextVersion = pkg . version ;
427+ let nextVersion = selectedPackage . info . version . format ( ) ;
420428 if ( confirmBumpVersion ) {
421- nextVersion = await getNextVersion ( pkg . version ) ;
429+ nextVersion = await getNextVersion ( selectedPackage . info . version . format ( ) ) ;
422430 console . log ( `🔼 Next version: ${ chalk . green ( nextVersion ) } ` ) ;
423431 } else {
424- console . log ( chalk . yellow ( `⚠️ Version bump skipped. Keeping version ${ chalk . green ( pkg . version ) } ` ) ) ;
432+ console . log (
433+ chalk . yellow (
434+ `⚠️ Version bump skipped. Keeping version ${ chalk . green ( selectedPackage . info . version . format ( ) ) } `
435+ )
436+ ) ;
425437 }
426438
427- const jiraVersionName = `${ baseName } -v${ nextVersion } ` ;
439+ const jiraName = selectedPackage . info . name . split ( "/" ) [ 1 ] ! ;
440+ const jiraVersionName = `${ jiraName } -v${ nextVersion } ` ;
428441
429- return { pkg , baseName, nextVersion, jiraVersionName, isVersionBumped : confirmBumpVersion } ;
442+ return { selectedPackage , baseName : jiraName , nextVersion, jiraVersionName, isVersionBumped : confirmBumpVersion } ;
430443}
431444
432- async function checkAndCreateJiraVersion ( jira : Jira , jiraVersionName : string ) : Promise < any > {
445+ async function checkAndCreateJiraVersion (
446+ jira : Jira | undefined ,
447+ jiraVersionName : string
448+ ) : Promise < JiraVersion | undefined > {
449+ if ( ! jira ) {
450+ console . log ( chalk . yellow ( " ⚠️ Skipping jira version creation" ) ) ;
451+ return undefined ;
452+ }
433453 let jiraVersion = jira . findVersion ( jiraVersionName ) ;
434454 if ( jiraVersion ) {
435455 console . log ( chalk . yellow ( `⚠️ Jira version ${ chalk . blue ( jiraVersionName ) } already exists` ) ) ;
@@ -443,8 +463,8 @@ async function checkAndCreateJiraVersion(jira: Jira, jiraVersionName: string): P
443463 } ) ;
444464
445465 if ( ! createVersion ) {
446- console . log ( chalk . red ( "❌ Process canceled ") ) ;
447- process . exit ( 1 ) ;
466+ console . log ( chalk . yellow ( " ⚠️ Skipping jira version creation ") ) ;
467+ return undefined ;
448468 }
449469
450470 // Create Jira version
0 commit comments