Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
[pod-install] show alternative message in managed projects (#4566)
Browse files Browse the repository at this point in the history
Co-authored-by: Brent Vatne <brentvatne@gmail.com>
  • Loading branch information
Simek and brentvatne authored Aug 9, 2023
1 parent 785cf12 commit 1e8769c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/expo-doctor/src/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { getConfig } from '@expo/config';
import chalk from 'chalk';
import semver from 'semver';

import { ExpoConfigCommonIssueCheck } from './checks/ExpoConfigCommonIssueCheck';
import { DirectPackageInstallCheck } from './checks/DirectPackageInstallCheck';
import { ExpoConfigCommonIssueCheck } from './checks/ExpoConfigCommonIssueCheck';
import { ExpoConfigSchemaCheck } from './checks/ExpoConfigSchemaCheck';
import { GlobalPackageInstalledCheck } from './checks/GlobalPackageInstalledCheck';
import { GlobalPrereqsVersionCheck } from './checks/GlobalPrereqsVersionCheck';
Expand Down
1 change: 1 addition & 0 deletions packages/pod-install/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@expo/package-manager": "0.0.56",
"chalk": "^4.0.0",
"commander": "2.20.0",
"terminal-link": "^2.1.1",
"update-check": "1.5.3"
}
}
26 changes: 21 additions & 5 deletions packages/pod-install/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import { CocoaPodsPackageManager } from '@expo/package-manager/build/CocoaPodsPackageManager';
import chalk from 'chalk';
import { Command } from 'commander';
import { resolve } from 'path';
import { existsSync, readFileSync } from 'fs';
import { join, resolve } from 'path';

import shouldUpdate from './update';
import { learnMore } from './utils';

const packageJSON = require('../package.json');

Expand All @@ -29,10 +31,7 @@ const info = (message: string) => {
};

async function runAsync(): Promise<void> {
if (typeof projectRoot === 'string') {
projectRoot = projectRoot.trim();
}
projectRoot = resolve(projectRoot);
projectRoot = resolve(projectRoot.trim());

if (process.platform !== 'darwin') {
info(chalk.red('CocoaPods is only supported on darwin machines'));
Expand All @@ -41,6 +40,23 @@ async function runAsync(): Promise<void> {

const possibleProjectRoot = CocoaPodsPackageManager.getPodProjectRoot(projectRoot);
if (!possibleProjectRoot) {
const packageJsonPath = join(projectRoot, 'package.json');

if (existsSync(packageJsonPath)) {
const jsonData = JSON.parse(readFileSync(packageJsonPath).toString());
const hasExpoPackage = jsonData.dependencies?.hasOwnProperty('expo');

if (hasExpoPackage) {
info(
chalk.yellow(
`No 'ios' directory found, skipping installing pods. Pods will be automatically installed when the 'ios' directory is generated with 'npx expo prebuild' or 'npx expo run:ios'.`,
learnMore('https://docs.expo.dev/workflow/prebuild/')
)
);
return;
}
}

info(chalk.yellow('CocoaPods is not supported in this project'));
return;
} else {
Expand Down
12 changes: 12 additions & 0 deletions packages/pod-install/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import chalk from 'chalk';
import terminalLink from 'terminal-link';

/**
* When linking isn't available, format the learn more link better.
* @param url
*/
export function learnMore(url: string): string {
return terminalLink(chalk.underline('Learn more.'), url, {
fallback: (_, url) => `Learn more: ${chalk.underline(url)}`,
});
}

0 comments on commit 1e8769c

Please sign in to comment.