Skip to content

Commit

Permalink
fix(cli): Don't error on ios sync on non macOS (#4723)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jun 15, 2021
1 parent 99c21dc commit 368ffad
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
11 changes: 11 additions & 0 deletions cli/src/ios/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,14 @@ 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;
}
24 changes: 15 additions & 9 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '../cordova';
import type { Config } from '../definitions';
import { fatal } from '../errors';
import { logger } from '../log';
import {
PluginType,
getAllElements,
Expand All @@ -33,7 +34,7 @@ import { resolveNode } from '../util/node';
import { runCommand } from '../util/subprocess';
import { extractTemplate } from '../util/template';

import { getIOSPlugins } from './common';
import { getIOSPlugins, shouldPodInstall } from './common';

const platform = 'ios';

Expand Down Expand Up @@ -77,14 +78,18 @@ export async function installCocoaPodsPlugins(
plugins: Plugin[],
deployment: boolean,
): Promise<void> {
await runTask(
`Updating iOS native dependencies with ${c.input(
`${config.ios.podPath} install`,
)}`,
() => {
return updatePodfile(config, plugins, deployment);
},
);
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');
}
}

async function updatePodfile(
Expand All @@ -101,6 +106,7 @@ async function updatePodfile(
`$1${dependenciesContent}$2`,
);
await writeFile(podfilePath, podfileContent, { encoding: 'utf-8' });

if (!deployment) {
await remove(podfileLockPath);
}
Expand Down
27 changes: 8 additions & 19 deletions cli/src/tasks/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
getProjectPlatformDirectory,
} from '../common';
import type { CheckFunction } from '../common';
import { OS } from '../definitions';
import type { Config } from '../definitions';
import { fatal, isFatal } from '../errors';
import { addIOS } from '../ios/add';
Expand Down Expand Up @@ -92,16 +91,14 @@ export async function addCommand(
await doAdd(config, platformName);
await editPlatforms(config, platformName);

if (shouldSync(config, platformName)) {
if (await pathExists(config.app.webDirAbs)) {
sync(config, platformName, false);
} else {
logger.warn(
`${c.success(c.strong('sync'))} could not run--missing ${c.strong(
config.app.webDir,
)} directory.`,
);
}
if (await pathExists(config.app.webDirAbs)) {
sync(config, platformName, false);
} else {
logger.warn(
`${c.success(c.strong('sync'))} could not run--missing ${c.strong(
config.app.webDir,
)} directory.`,
);
}

printNextSteps(platformName);
Expand Down Expand Up @@ -154,14 +151,6 @@ async function editPlatforms(config: Config, platformName: string) {
}
}

function shouldSync(config: Config, platformName: string) {
// Don't sync if we're adding the iOS platform not on a mac
if (config.cli.os !== OS.Mac && platformName === 'ios') {
return false;
}
return true;
}

function webWarning() {
logger.error(
`Not adding platform ${c.strong('web')}.\n` +
Expand Down

0 comments on commit 368ffad

Please sign in to comment.