From 32ecf22de0a550756dbfa68b3b17c2333c89a430 Mon Sep 17 00:00:00 2001 From: Thomas Vidas Date: Wed, 27 Oct 2021 15:25:25 -0400 Subject: [PATCH] feat(cli): add support for 'pod install' in VM based environments (#5144) * feat(cli): add support for 'pod install' in VM based environments * fix(cli): Don't run xcodebuild if it isn't available * Update cli/src/ios/update.ts Co-authored-by: jcesarmobile * Update cli/src/ios/update.ts Co-authored-by: jcesarmobile * Update cli/src/ios/update.ts Co-authored-by: jcesarmobile * refactor: change explicit 'canRun' functions to 'isInstalled' * lint * remove unused * remove platform check * move pod check right before pod install Co-authored-by: jcesarmobile --- cli/src/ios/common.ts | 11 -------- cli/src/ios/update.ts | 65 ++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/cli/src/ios/common.ts b/cli/src/ios/common.ts index 1c21b6ef55..4a254b80d4 100644 --- a/cli/src/ios/common.ts +++ b/cli/src/ios/common.ts @@ -85,14 +85,3 @@ export async function editProjectSettingsIOS(config: Config): Promise { await writeFile(plistPath, plistContent, { encoding: 'utf-8' }); await writeFile(pbxPath, pbxContent, { encoding: 'utf-8' }); } - -export function shouldPodInstall( - config: Config, - platformName: string, -): boolean { - // Don't run pod install or xcodebuild if not on macOS - if (config.cli.os !== OS.Mac && platformName === 'ios') { - return false; - } - return true; -} diff --git a/cli/src/ios/update.ts b/cli/src/ios/update.ts index 1384a1ceb1..5e248de1f6 100644 --- a/cli/src/ios/update.ts +++ b/cli/src/ios/update.ts @@ -32,10 +32,10 @@ import type { Plugin } from '../plugin'; import { copy as copyTask } from '../tasks/copy'; import { convertToUnixPath } from '../util/fs'; import { resolveNode } from '../util/node'; -import { runCommand } from '../util/subprocess'; +import { runCommand, isInstalled } from '../util/subprocess'; import { extractTemplate } from '../util/template'; -import { getIOSPlugins, shouldPodInstall } from './common'; +import { getIOSPlugins } from './common'; const platform = 'ios'; @@ -79,18 +79,14 @@ export async function installCocoaPodsPlugins( plugins: Plugin[], deployment: boolean, ): Promise { - if (shouldPodInstall(config, platform)) { - await runTask( - `Updating iOS native dependencies with ${c.input( - `${config.ios.podPath} install`, - )}`, - () => { - return updatePodfile(config, plugins, deployment); - }, - ); - } else { - logger.warn('Skipping pod install on unsupported OS'); - } + await runTask( + `Updating iOS native dependencies with ${c.input( + `${config.ios.podPath} install`, + )}`, + () => { + return updatePodfile(config, plugins, deployment); + }, + ); } async function updatePodfile( @@ -108,23 +104,34 @@ async function updatePodfile( ); await writeFile(podfilePath, podfileContent, { encoding: 'utf-8' }); - if (!deployment) { - await remove(podfileLockPath); + const podCommandExists = await isInstalled('pod'); + if (podCommandExists) { + if (!deployment) { + await remove(podfileLockPath); + } + await runCommand( + config.ios.podPath, + ['install', ...(deployment ? ['--deployment'] : [])], + { cwd: config.ios.nativeProjectDirAbs }, + ); + } else { + logger.warn('Skipping pod install because CocoaPods is not installed'); } - await runCommand( - config.ios.podPath, - ['install', ...(deployment ? ['--deployment'] : [])], - { cwd: config.ios.nativeProjectDirAbs }, - ); - - await runCommand( - 'xcodebuild', - ['-project', basename(`${config.ios.nativeXcodeProjDirAbs}`), 'clean'], - { - cwd: config.ios.nativeProjectDirAbs, - }, - ); + const isXcodebuildAvailable = await isInstalled('xcodebuild'); + if (isXcodebuildAvailable) { + await runCommand( + 'xcodebuild', + ['-project', basename(`${config.ios.nativeXcodeProjDirAbs}`), 'clean'], + { + cwd: config.ios.nativeProjectDirAbs, + }, + ); + } else { + logger.warn( + 'Unable to find "xcodebuild". Skipping xcodebuild clean step...', + ); + } } async function generatePodFile(