import colors from 'colors/safe' ; import * as path from 'path' ; import * as rushLib from '@microsoft/rush-lib' ; type CommandName = 'rush' | 'rushx' | undefined ; microsoft export class RushCommandSelector { public static failIfNotInvokedAsRush ( version ) { if ( RushCommandSelector . _getCommandName ( ) === 'rushx' ) { RushCommandSelector . _failWithError ( `This repository is using Rush version ${ version } which does not support the "rushx" command` ) ; } } public static execute ( launcherVersion , selectedRushLib , options ) { const Rush = selectedRushLib . Rush ; if ( ! Rush ) { RushCommandSelector . _failWithError ( `Unable to find the "Rush" entry point in @microsoft/rush-lib` ) ; } if ( RushCommandSelector . _getCommandName ( ) === 'rushx' ) { if ( ! Rush . launchRushX ) { RushCommandSelector . _failWithError ( `This repository is using Rush version ${ Rush . version }` + ` which does not support the "rushx" command` ) ; } Rush . launchRushX ( launcherVersion , options ) ; } else { Rush . launch ( launcherVersion , options ) ; } } private static _failWithError ( message ) { console . log ( colors . red ( message ) ) ; return process . exit ( 1 ) ; } private static _getCommandName ( ) { if ( process . argv . length >= 2 ) { const basename = path . basename ( process . argv [ 1 ] ) . toUpperCase ( ) ; if ( basename === 'RUSHX' ) { return 'rushx' ; } if ( basename === 'RUSH' ) { return 'rush' ; } } return undefined ; } }