Skip to content

Commit

Permalink
fix(tvOS): Replace ios-deploy with xcrun commands in @react-native-co…
Browse files Browse the repository at this point in the history
…mmunity/cli-platfom-ios
  • Loading branch information
RicardasN committed Oct 17, 2024
1 parent 82bf6de commit 88d97f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
"{\n isAvailable: device.available,": "{\n modelName:device.modelName, // <= PATCHED BY RENATIVE\n isAvailable: device.available,"
},
"build/commands/runIOS/index.js": {
"_cliTools().logger.error(`Could not find a device named: \"${_chalk().default.bold(String(deviceName))}\". ${printFoundDevices(devices)}`);": "_cliTools().logger.error(`Could not find a device: \"${_chalk().default.bold(String(deviceName))}\". ${printFoundDevices(devices)}`);\n throw 'Could not find device'; // <= PATCHED BY RENATIVE"
"_cliTools().logger.error(`Could not find a device named: \"${_chalk().default.bold(String(deviceName))}\". ${printFoundDevices(devices)}`);": "_cliTools().logger.error(`Could not find a device: \"${_chalk().default.bold(String(deviceName))}\". ${printFoundDevices(devices)}`);\n throw 'Could not find device'; // <= PATCHED BY RENATIVE",
"const isIOSDeployInstalled = _child_process().default.spawnSync('ios-deploy', ['--version'], {\n encoding: 'utf8'\n });\n if (isIOSDeployInstalled.error) {\n throw new (_cliTools().CLIError)(`Failed to install the app on the device because we couldn't execute the \"ios-deploy\" command. Please install it by running \"${_chalk().default.bold('brew install ios-deploy')}\" and try again.`);\n }": "// <= PATCHED BY RENATIVE (removing ios-deploy dependency because of https://github.com/ios-control/ios-deploy/issues/588#issuecomment-1667938056)",
"const iosDeployInstallArgs = ['--bundle', appPath, '--id', selectedDevice.udid, '--justlaunch'];": "// <= PATCHED BY RENATIVE (removing ios-deploy dependency)",
" _cliTools().logger.info(`Installing your app on ${selectedDevice.name}`);": "_cliTools().logger.info(`Installing your app on ${selectedDevice.name}`);",
"const iosDeployOutput = _child_process().default.spawnSync('ios-deploy', iosDeployInstallArgs, {\n encoding: 'utf8'\n });": "const iosInstallArgs = ['devicectl', 'device', 'install', 'app', '--device', selectedDevice.udid, appPath];\n _cliTools().logger.info(`xcrun ${iosInstallArgs.join(' ')}`);\n const iosInstallOutput = _child_process().default.spawnSync('xcrun', iosInstallArgs, {\n stdio: 'pipe',\n encoding: 'utf8',\n });\n const res = JSON.stringify(iosInstallOutput)\n const installationUrl = res.substring(\n res.indexOf('file:') || 0,\n (res.indexOf('.app/') || 0) + '.app/'.length\n );\n _cliTools().logger.info(`Launching your app on ${selectedDevice.name}`);\n const iosLaunchArgs = ['devicectl', 'device', 'process', 'launch', '--device', selectedDevice.udid, installationUrl];\n _cliTools().logger.info(`xcrun ${iosLaunchArgs.join(' ')}`);\n _child_process().default.spawnSync('xcrun', iosLaunchArgs, {\n stdio: 'inherit'\n });",
"if (iosDeployOutput.error) {": "if (iosInstallOutput.stderr) {",
"throw new (_cliTools().CLIError)(`Failed to install the app on the device. We've encountered an error in \"ios-deploy\" command: ${iosDeployOutput.error.message}`);": "throw new (_cliTools().CLIError)(`Failed to install the app on the device. We've encountered an error: ${iosInstallOutput.stderr}`);"
}
}
}
43 changes: 5 additions & 38 deletions packages/sdk-apple/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
import { registerDevice } from './fastlane';
import { Context, getContext } from './getContext';
import { parsePrivacyManifest } from './privacyManifestParser';
import { getAppId } from '@rnv/sdk-utils';

export const packageBundleForXcode = () => {
return packageReactNativeIOS();
Expand Down Expand Up @@ -233,47 +232,16 @@ export const runXcodeProject = async (runDeviceArguments?: string) => {
const bundleAssets = getConfigProp('bundleAssets') === true;

if (runDeviceArguments) {
// await launchAppleSimulator(c, c.runtime.target); @TODO - do we still need this? RN CLI does it as well
//const allowProvisioningUpdates = getConfigProp('allowProvisioningUpdates', true);
//if (allowProvisioningUpdates) p = `${p} --allowProvisioningUpdates`;
if (bundleAssets) {
await packageReactNativeIOS(bundleIsDev);
}
if (c.platform === 'tvos' && !runDeviceArguments.includes('--simulator')) {
try {
await executeAsync(`ios-deploy -c`);
} catch (error) {
if (typeof error === 'string' && error.includes('Command failed with exit code 253')) {
logError(
`Ios-deploy couldn't find a connected device. For a more reliable connection, use a USB cable instead of wireless.`
);
const { confirm } = await inquirerPrompt({
type: 'confirm',
name: 'confirm',
message: 'Would you like to use an Xcode script to build and launch the app?',
});
if (confirm) {
try {
await buildXcodeProject();
} catch (e) {
await _handleMissingTeam(c, e);
}
const udid = runDeviceArguments.split(' ')[1];

await executeAsync(
`xcrun devicectl device install app -d ${udid} ${path.join(
appPath,
`build/RNVApp/Build/Products/${runScheme}-appletvos/RNVApp-tvOS.app`
)}`
);

return executeAsync(
`xcrun devicectl device process launch --device ${udid} --activate ${getAppId()?.toLowerCase()}`
);
}
return;
}
return _checkLockAndExec(c, appPath, schemeTarget, runScheme, runDeviceArguments);
} catch (e) {
await _handleMissingTeam(c, e);
}
return;
}
return _checkLockAndExec(c, appPath, schemeTarget, runScheme, runDeviceArguments);
}
Expand All @@ -293,7 +261,6 @@ export const runXcodeProject = async (runDeviceArguments?: string) => {
`open ${path.join(appPath, `build/RNVApp/Build/Products/${runScheme}-maccatalyst/RNVApp.app`)}`
);
}
// return Promise.reject('Missing options for react-native command!');
};

const _checkLockAndExec = async (
Expand Down Expand Up @@ -327,7 +294,7 @@ const _checkLockAndExec = async (
logWarning(
`${c.platform} DEVICE: ${chalk().bold.white(c.runtime.target)} with UDID: ${chalk().bold.white(
c.runtime.targetUDID
)} is not included in your provisionong profile in TEAM: ${chalk().bold.white(
)} is not included in your provisioning profile in TEAM: ${chalk().bold.white(
getConfigProp('teamID')
)}`
);
Expand Down

0 comments on commit 88d97f7

Please sign in to comment.