Skip to content

Commit

Permalink
feat(cli): add support for 'pod install' in VM based environments (#5144
Browse files Browse the repository at this point in the history
)

* 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 <jcesarmobile@gmail.com>

* Update cli/src/ios/update.ts

Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>

* Update cli/src/ios/update.ts

Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>

* refactor: change explicit 'canRun' functions to 'isInstalled'

* lint

* remove unused

* remove platform check

* move pod check right before pod install

Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
  • Loading branch information
thomasvidas and jcesarmobile committed Oct 27, 2021
1 parent b39f395 commit 32ecf22
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 40 deletions.
11 changes: 0 additions & 11 deletions cli/src/ios/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,3 @@ export async function editProjectSettingsIOS(config: Config): Promise<void> {
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;
}
65 changes: 36 additions & 29 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -79,18 +79,14 @@ export async function installCocoaPodsPlugins(
plugins: Plugin[],
deployment: boolean,
): Promise<void> {
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(
Expand All @@ -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(
Expand Down

0 comments on commit 32ecf22

Please sign in to comment.