@@ -13,7 +13,7 @@ export class BaseReleaseTask {
1313 constructor ( public git : GitClient ) { }
1414
1515 /** Checks if the user is on an allowed publish branch for the specified version. */
16- protected switchToPublishBranch ( newVersion : Version ) : string {
16+ protected async assertValidPublishBranch ( newVersion : Version ) : Promise < string > {
1717 const allowedBranches = getAllowedPublishBranches ( newVersion ) ;
1818 const currentBranchName = this . git . getCurrentBranch ( ) ;
1919
@@ -24,30 +24,24 @@ export class BaseReleaseTask {
2424 return currentBranchName ;
2525 }
2626
27- // In case there are multiple allowed publish branches for this version, we just
28- // exit and let the user decide which branch they want to release from.
29- if ( allowedBranches . length !== 1 ) {
30- console . warn ( chalk . yellow ( ' ✘ You are not on an allowed publish branch.' ) ) ;
31- console . warn ( chalk . yellow ( ` Please switch to one of the following branches: ` +
32- `${ allowedBranches . join ( ', ' ) } ` ) ) ;
33- process . exit ( 0 ) ;
34- }
35-
36- // For this version there is only *one* allowed publish branch, so we could
37- // automatically switch to that branch in case the user isn't on it yet.
38- const defaultPublishBranch = allowedBranches [ 0 ] ;
27+ console . error ( chalk . red ( ' ✘ You are not on an allowed publish branch.' ) ) ;
28+ console . info ( chalk . yellow (
29+ ` Allowed branches are: ${ chalk . bold ( allowedBranches . join ( ', ' ) ) } ` ) ) ;
30+ console . info ( ) ;
3931
40- if ( ! this . git . checkoutBranch ( defaultPublishBranch ) ) {
41- console . error ( chalk . red (
42- ` ✘ Could not switch to the "${ chalk . italic ( defaultPublishBranch ) } " branch.` ) ) ;
43- console . error ( chalk . red (
44- ` Please ensure that the branch exists or manually switch to the branch.` ) ) ;
45- process . exit ( 1 ) ;
32+ // Prompt the user if they wants to forcibly use the current branch. We support this
33+ // because in some cases, releases do not use the common publish branches. e.g. a major
34+ // release is delayed, and new features for the next minor version are collected.
35+ if ( await this . promptConfirm (
36+ `Do you want to forcibly use the current branch? (${ chalk . italic ( currentBranchName ) } )` ) ) {
37+ console . log ( ) ;
38+ console . log ( chalk . green ( ` ✓ Using the "${ chalk . italic ( currentBranchName ) } " branch.` ) ) ;
39+ return currentBranchName ;
4640 }
4741
48- console . log ( chalk . green (
49- ` ✓ Switched to the " ${ chalk . italic ( defaultPublishBranch ) } " branch.` ) ) ;
50- return defaultPublishBranch ;
42+ console . warn ( ) ;
43+ console . warn ( chalk . yellow ( ' Please switch to one of the allowed publish branches.' ) ) ;
44+ process . exit ( 0 ) ;
5145 }
5246
5347 /** Verifies that the local branch is up to date with the given publish branch. */
@@ -73,11 +67,12 @@ export class BaseReleaseTask {
7367 }
7468
7569 /** Prompts the user with a confirmation question and a specified message. */
76- protected async promptConfirm ( message : string ) : Promise < boolean > {
70+ protected async promptConfirm ( message : string , defaultValue = false ) : Promise < boolean > {
7771 return ( await prompt < { result : boolean } > ( {
7872 type : 'confirm' ,
7973 name : 'result' ,
8074 message : message ,
75+ default : defaultValue ,
8176 } ) ) . result ;
8277 }
8378}
0 commit comments