Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7602310
feat: add run:ios command
thymikee Dec 2, 2024
57e21c6
refactor output for more feedback with spinners
thymikee Dec 3, 2024
e2facb6
adjust error handling
thymikee Dec 3, 2024
e0664e9
slightly better handling of ios-deploy
thymikee Dec 3, 2024
593f1a6
remove --list-devices flag
thymikee Dec 3, 2024
18addb5
move error to normalizer
thymikee Dec 3, 2024
32d293f
drastically simplify createRun data flow
thymikee Dec 3, 2024
b5f745a
cleanup
thymikee Dec 3, 2024
13289b6
add warnings and handle devices case
thymikee Dec 4, 2024
940240a
use spawn
thymikee Dec 4, 2024
966c436
create runOnMac helper
thymikee Dec 4, 2024
5b5a257
move single-use utils closer to callsites
thymikee Dec 4, 2024
464f577
handle prompt cancellation
thymikee Dec 4, 2024
6120d9b
move code under src/lib to match repo convention
thymikee Dec 4, 2024
bdbc946
add success message
thymikee Dec 4, 2024
b75619f
add missing dot
thymikee Dec 4, 2024
d483139
remove copyright
thymikee Dec 5, 2024
e45f312
support preferred device; ts was right
thymikee Dec 6, 2024
395bb58
extract selectDevice
thymikee Dec 6, 2024
8e176e1
move warnings to helper
thymikee Dec 6, 2024
dd0d362
cache per platform, remove unused legacyPath
thymikee Dec 6, 2024
e2112b5
fix test
thymikee Dec 6, 2024
d1cf059
remove fallback sim logic; prompt for devices when none open or cached
thymikee Dec 6, 2024
4142e56
allow for --simulator without specified name
thymikee Dec 6, 2024
c8a19fb
remove unixifyPaths
thymikee Dec 6, 2024
3800e9d
remove preferred device logic
thymikee Dec 6, 2024
1376ab6
perf: use devicectl instead of xcdevice; refactor Device
thymikee Dec 6, 2024
5907dbe
base catalyst support with --catalyst flag
thymikee Dec 7, 2024
ec12ff0
get rid of chdir
thymikee Dec 9, 2024
f3261dc
feat: recent devices sort
thymikee Dec 9, 2024
5bbd4a7
filter devices by platform
thymikee Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const args: Flags = {
port: '8081',
appId: '',
appIdSuffix: '',
mode: 'debug',
};

const androidProject: AndroidProjectConfig = {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-platform-apple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@react-native-community/cli-config-apple": "^15.1.2",
"fast-glob": "^3.3.2",
"fast-xml-parser": "^4.5.0",
"is-interactive": "^2.0.0",
"nano-spawn": "^0.2.0",
"picocolors": "^1.1.1",
"tslib": "^2.3.0"
Expand Down
31 changes: 0 additions & 31 deletions packages/plugin-platform-apple/src/commands/build/index.ts

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type BuildFlags = {
target?: string;
extraParams?: string[];
device?: string;
catalyst?: boolean;
buildFolder?: string;
destination?: string;
};
Expand Down Expand Up @@ -47,8 +48,11 @@ export const getBuildOptions = ({ platformName }: BuilderCommand) => {
{
name: '--device [string]',
description:
'Explicitly set the device to use by name or by unique device identifier. If the value is not provided,' +
'the app will run on the first available physical device.',
'Explicitly set the device to use by name or by unique device identifier. If the value is not provided, the app will run on the first available physical device.',
},
{
name: '--catalyst',
description: 'Run on Mac Catalyst.',
},
{
name: '--buildFolder <string>',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import type { BuildFlags } from './buildOptions.js';
import { supportedPlatforms } from '../../supportedPlatforms.js';
import { supportedPlatforms } from '../../utils/supportedPlatforms.js';
import { ApplePlatform, XcodeProjectInfo } from '../../types/index.js';
import { logger } from '@callstack/rnef-tools';
import { getConfiguration } from './getConfiguration.js';
import { simulatorDestinationMap } from './simulatorDestinationMap.js';
import { spinner } from '@clack/prompts';
import spawn from 'nano-spawn';
import { selectFromInteractiveMode } from '../../utils/selectFromInteractiveMode.js';
import path from 'node:path';
import spawn, { SubprocessError } from 'nano-spawn';

const buildProject = async (
export const buildProject = async (
xcodeProject: XcodeProjectInfo,
sourceDir: string,
platformName: ApplePlatform,
udid: string | undefined,
scheme: string,
mode: string,
args: BuildFlags
) => {
normalizeArgs(args, xcodeProject);
const simulatorDest = simulatorDestinationMap[platformName];

if (!simulatorDest) {
Expand All @@ -26,15 +25,6 @@ const buildProject = async (
);
}

const { scheme, mode } = args.interactive
? await selectFromInteractiveMode(xcodeProject, args.scheme, args.mode)
: await getConfiguration(
xcodeProject,
args.scheme,
args.mode,
platformName
);

const xcodebuildArgs = [
xcodeProject.isWorkspace ? '-workspace' : '-project',
xcodeProject.name,
Expand All @@ -56,7 +46,9 @@ const buildProject = async (
}
}

return udid
return args.catalyst
? 'platform=macOS,variant=Mac Catalyst'
: udid
? `id=${udid}`
: mode === 'Debug' || args.device
? `generic/platform=${simulatorDest}`
Expand All @@ -74,33 +66,22 @@ const buildProject = async (
`Builing the app with xcodebuild for ${scheme} scheme in ${mode} mode.`
);
logger.debug(`Running "xcodebuild ${xcodebuildArgs.join(' ')}.`);

try {
await spawn('xcodebuild', xcodebuildArgs, {
stdio: logger.isVerbose() ? 'inherit' : ['ignore', 'ignore', 'inherit'],
const { output } = await spawn('xcodebuild', xcodebuildArgs, {
cwd: sourceDir,
});
loader.stop(
`Built the app with xcodebuild for ${scheme} scheme in ${mode} mode.`
);
return output;
} catch (error) {
logger.log('');
logger.log((error as SubprocessError).stdout);
logger.error((error as SubprocessError).stderr);
loader.stop(
'Running xcodebuild failed. Check the error message above for details.',
1
);
throw error;
throw new Error('Running xcodebuild failed');
}
};

function normalizeArgs(args: BuildFlags, xcodeProject: XcodeProjectInfo) {
if (!args.mode) {
args.mode = 'Debug';
}
if (!args.scheme) {
args.scheme = path.basename(
xcodeProject.name,
path.extname(xcodeProject.name)
);
}
}

export { buildProject };
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { BuildFlags } from './buildOptions.js';
import { buildProject } from './buildProject.js';
import {
BuilderCommand,
ProjectConfig,
XcodeProjectInfo,
} from '../../types/index.js';
import { logger } from '@callstack/rnef-tools';
import { outro, cancel } from '@clack/prompts';
import path from 'path';
import { selectFromInteractiveMode } from '../../utils/selectFromInteractiveMode.js';
import { getConfiguration } from './getConfiguration.js';
import isInteractive from 'is-interactive';

export const createBuild = async (
platformName: BuilderCommand['platformName'],
projectConfig: ProjectConfig,
args: BuildFlags
) => {
// TODO: add logic for installing Cocoapods based on @expo/fingerprint & pod-install package.

const { xcodeProject, sourceDir } = projectConfig;

if (!xcodeProject) {
logger.error(
`Could not find Xcode project files in "${sourceDir}" folder. Please make sure that you have installed Cocoapods and "${sourceDir}" is a valid path`
);
process.exit(1);
}

normalizeArgs(args, xcodeProject);

const { scheme, mode } = args.interactive
? await selectFromInteractiveMode(
xcodeProject,
sourceDir,
args.scheme,
args.mode
)
: await getConfiguration(
xcodeProject,
sourceDir,
args.scheme,
args.mode,
platformName
);

try {
await buildProject(
xcodeProject,
sourceDir,
platformName,
undefined,
scheme,
mode,
args
);
outro('Success 🎉.');
} catch {
cancel('Command failed.');
}
};

function normalizeArgs(args: BuildFlags, xcodeProject: XcodeProjectInfo) {
if (!args.mode) {
args.mode = 'Debug';
}
if (!args.scheme) {
args.scheme = path.basename(
xcodeProject.name,
path.extname(xcodeProject.name)
);
}
if (args.interactive && !isInteractive()) {
logger.warn(
'Interactive mode is not supported in non-interactive environments.'
);
args.interactive = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import color from 'picocolors';

export async function getConfiguration(
xcodeProject: XcodeProjectInfo,
sourceDir: string,
inputScheme: string,
inputMode: string,
platformName: ApplePlatform
) {
const sourceDir = process.cwd();
const info = await getInfo(xcodeProject, sourceDir);

checkIfConfigurationExists(info?.configurations ?? [], inputMode);

let scheme = inputScheme;

if (!info?.schemes?.includes(scheme)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApplePlatform } from '../../types/index.js';

export const simulatorDestinationMap: Record<ApplePlatform, string> = {
ios: 'iOS Simulator',
// macos: 'macOS',
// visionos: 'visionOS Simulator',
// tvos: 'tvOS Simulator',
macos: 'macOS',
visionos: 'visionOS Simulator',
tvos: 'tvOS Simulator',
};
Loading
Loading