All files CodePushCli.js

0% Statements 0/11
0% Branches 0/16
0% Functions 0/3
0% Lines 0/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                                                                                                                               
// @flow
 
import {
  execp
} from './childProcess'
import inquirer from 'inquirer'
 
export default class CodePushCli {
  _binaryPath: ?string
 
  constructor (binaryPath?: string) {
    this._binaryPath = binaryPath
  }
 
  get binaryPath () : string {
    return this._binaryPath ? this._binaryPath : `code-push`
  }
 
  async releaseReact (
    appName: string,
    platform: 'android' | 'ios', {
      targetBinaryVersion,
      mandatory,
      deploymentName,
      rolloutPercentage,
      askForConfirmation
    } : {
      targetBinaryVersion?: string,
      mandatory?: boolean,
      deploymentName: string,
      rolloutPercentage?: string,
      askForConfirmation?: boolean
    }) : Promise<boolean> {
    const codePushCommand =
      `${this.binaryPath} release-react \
${appName} \
${platform} \
${targetBinaryVersion ? `-t ${targetBinaryVersion}` : ''} \
${mandatory ? `-m` : ''} \
${deploymentName ? `-d ${deploymentName}` : ''} \
${rolloutPercentage ? `-r ${rolloutPercentage}` : ''} \
${platform === 'ios' ? `-b MiniApp.jsbundle` : ''}`
 
    let shouldExecuteCodePushCommand = true
 
    if (askForConfirmation) {
      log.info(`Will run:\n${codePushCommand}`)
      const {userConfirmedCodePushCommand} = await inquirer.prompt({
        type: 'confirm',
        name: 'userConfirmedCodePushCommand',
        message: 'Do you confirm code push command execution ?',
        default: true
      })
      shouldExecuteCodePushCommand = userConfirmedCodePushCommand
    }
 
    if (shouldExecuteCodePushCommand) {
      await execp(codePushCommand)
    }
 
    return shouldExecuteCodePushCommand
  }
}