From be1ba16a659d91829ad3912f8366dc317bb6f131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20R=C3=A4dle?= Date: Mon, 20 Dec 2021 11:13:26 -0800 Subject: [PATCH] Adds "cocoapods-installer" option Summary: Adds "cocoapods-installer" option to "setup-dev" command to decide who CocoaPods will be installed on the macOS host system. The options are "gem" and "homebrew". ## Gem ``` npx torchlive-cli setup-dev --cocoapods-installer=gem ``` ## Homebrew ``` npx torchlive-cli setup-dev --cocoapods-installer=homebrew ``` Note: the option will be used for the GitHub Action CI that tests the setup-dev command ## Test Tested in forked repo: https://github.com/raedle/live/runs/4576829417 Reviewed By: liuyinglao Differential Revision: D33229271 fbshipit-source-id: 2019748854c25c2f5a71db334040e116e56ef9a0 --- torchlive-cli/src/cli-commands/SetUpDev.ts | 5 +++ .../src/installers/ios/CocoaPodsInstaller.ts | 37 +++++++++++++------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/torchlive-cli/src/cli-commands/SetUpDev.ts b/torchlive-cli/src/cli-commands/SetUpDev.ts index 6f04093da..71d09e47d 100644 --- a/torchlive-cli/src/cli-commands/SetUpDev.ts +++ b/torchlive-cli/src/cli-commands/SetUpDev.ts @@ -23,6 +23,7 @@ import {runTasks} from '../utils/TaskUtils'; type SetupDevOptions = { yes: boolean; + cocoapodsInstaller: string | undefined; }; const setUpDev = async (options: SetupDevOptions): Promise => { @@ -47,5 +48,9 @@ export function makeSetUpDevCommand() { return new Command('setup-dev') .description('set up development dependencies') .option('-y, --yes', 'Accept all questions') + .option( + '--cocoapods-installer [installer]', + 'CocoaPods Package Installer (gem or homebrew)', + ) .action(setUpDev); } diff --git a/torchlive-cli/src/installers/ios/CocoaPodsInstaller.ts b/torchlive-cli/src/installers/ios/CocoaPodsInstaller.ts index ecc35a70a..4f50a047b 100644 --- a/torchlive-cli/src/installers/ios/CocoaPodsInstaller.ts +++ b/torchlive-cli/src/installers/ios/CocoaPodsInstaller.ts @@ -45,21 +45,36 @@ export default class CocoaPodsInstaller implements ICommandInstallerTask { } async run(context: TaskContext): Promise { - const source = await context.task.prompt([ - { - type: 'Select', - name: 'source', - message: - "CocoaPods (https://cocoapods.org/) is not installed. It's necessary for iOS project to run correctly. Do you want to install it?", - choices: ['Yes, with gem (may require sudo)', 'Yes,‎ with‎ Homebrew'], - }, - ]); + let {cocoapodsInstaller} = context.ctx; + if (cocoapodsInstaller == null) { + cocoapodsInstaller = await context.task.prompt([ + { + type: 'Select', + name: 'source', + message: + "CocoaPods (https://cocoapods.org/) is not installed. It's necessary for iOS project to run correctly. Do you want to install it?", + choices: [ + { + name: 'gem', + message: 'Yes, with gem (may require sudo)', + }, + { + name: 'homebrew', + message: 'Yes,‎ with‎ Homebrew', + }, + ], + }, + ]); + } - if (source === 'Yes, with gem (may require sudo)') { + if (cocoapodsInstaller === 'gem') { return await this.installWithGem(context); - } else { + } else if (cocoapodsInstaller === 'homebrew') { return await this.installWithHomebrew(context); } + throw new Error( + `${cocoapodsInstaller} is not a valid option to install CocoaPods`, + ); } private async installWithGem(context: TaskContext): Promise {