@@ -3,13 +3,17 @@ import { parseCSV } from 'nx/src/command-line/yargs-utils/shared-options';
33import chalk from 'chalk' ;
44import { printHeader } from '../utils/output' ;
55import { execaSync } from 'execa' ;
6+ import { ReleaseChannel , releaseChannelPreid } from './release.consts' ;
7+ import { ReleasePreidValue } from './release.types' ;
68
79export function parseReleaseCliOptions ( ) {
810 return yargs
911 . version ( false ) // don't use the default meaning of version in yargs
10- . option ( 'version' , {
11- description : 'Explicit version specifier to use, if overriding conventional commits' ,
12+ . option ( 'channel' , {
13+ alias : 'c' ,
14+ description : 'Explicit channel specifier to use when not deploying based on branch' ,
1215 type : 'string' ,
16+ choices : Object . values ( ReleaseChannel ) ,
1317 } )
1418 . option ( 'dryRun' , {
1519 alias : 'd' ,
@@ -40,18 +44,42 @@ export function parseReleaseCliOptions() {
4044 . parseAsync ( ) ;
4145}
4246
43- export function getOptionsBasedOnBranch ( ) : { isPrerelease : boolean ; preid ?: string ; tag : string } {
44- // Get current branch
45- const { stdout : branch } = execaSync ( 'git' , [ 'branch' , '--show-current' ] ) ;
47+ export function parseReleaseOptions ( { channel } : { channel ?: ReleaseChannel } ) : {
48+ isPrerelease : boolean ;
49+ preid ?: string ;
50+ tag : ReleaseChannel ;
51+ } {
52+ let isPrerelease : boolean ;
53+ let preid : ReleasePreidValue ;
54+ let tag : ReleaseChannel ;
4655
47- // Determine options based on branch
48- const isPrerelease = branch !== 'main' ;
49- const preid : string | undefined = isPrerelease ? 'preview' : undefined ;
50- const tag : string = isPrerelease ? 'preview' : 'latest' ;
56+ let selectedChannel : ReleaseChannel ;
5157
52- // Output which branch is used
53- console . log ( printHeader ( 'branch' , 'blueBright' ) , `Detecting current git branch\n` ) ;
54- console . log ( `${ chalk . blueBright ( branch ) } 🔀 Using "${ chalk . yellow ( preid ?? '[empty]' ) } " preid\n` ) ;
58+ console . log ( printHeader ( 'channel' , 'blueBright' ) , `Detecting release channel...\n` ) ;
59+
60+ if ( ! channel ) {
61+ // Auto determine based on branch
62+ const { stdout : branch } = execaSync ( 'git' , [ 'branch' , '--show-current' ] ) ;
63+ console . log ( `🚫 No channel specified, using current git branch ${ chalk . blueBright ( branch ) } ` ) ;
64+ selectedChannel = branch === 'main' ? ReleaseChannel . Latest : ReleaseChannel . Preview ;
65+ } else {
66+ selectedChannel = channel ;
67+ }
68+
69+ console . log ( `🔀 ${ chalk . yellow ( selectedChannel ) } channel selected for release\n` ) ;
70+
71+ switch ( selectedChannel ) {
72+ case ReleaseChannel . Latest :
73+ isPrerelease = false ;
74+ break ;
75+ case ReleaseChannel . Preview :
76+ default :
77+ isPrerelease = true ;
78+ break ;
79+ }
80+
81+ preid = releaseChannelPreid [ selectedChannel ] ;
82+ tag = selectedChannel ;
5583
5684 return {
5785 isPrerelease,
0 commit comments