Skip to content

Commit 5907dbe

Browse files
committed
base catalyst support with --catalyst flag
1 parent 1376ab6 commit 5907dbe

9 files changed

Lines changed: 89 additions & 65 deletions

File tree

packages/plugin-platform-apple/src/lib/commands/build/buildOptions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type BuildFlags = {
99
target?: string;
1010
extraParams?: string[];
1111
device?: string;
12+
catalyst?: boolean;
1213
buildFolder?: string;
1314
destination?: string;
1415
};
@@ -49,6 +50,10 @@ export const getBuildOptions = ({ platformName }: BuilderCommand) => {
4950
description:
5051
'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.',
5152
},
53+
{
54+
name: '--catalyst',
55+
description: 'Run on Mac Catalyst.',
56+
},
5257
{
5358
name: '--buildFolder <string>',
5459
description: `Location for ${readableName} build artifacts. Corresponds to Xcode's "-derivedDataPath".`,

packages/plugin-platform-apple/src/lib/commands/build/buildProject.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export const buildProject = async (
4545
}
4646
}
4747

48-
return udid
48+
return args.catalyst
49+
? 'platform=macOS,variant=Mac Catalyst'
50+
: udid
4951
? `id=${udid}`
5052
: mode === 'Debug' || args.device
5153
? `generic/platform=${simulatorDest}`

packages/plugin-platform-apple/src/lib/commands/run/createRun.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { RunFlags } from './runOptions.js';
1919
import { selectFromInteractiveMode } from '../../utils/selectFromInteractiveMode.js';
2020
import { outro, spinner } from '@clack/prompts';
2121
import { runOnMac } from './runOnMac.js';
22+
import { runOnMacCatalyst } from './runOnMacCatalyst.js';
2223

2324
export const createRun = async (
2425
platformName: ApplePlatform,
@@ -50,7 +51,13 @@ export const createRun = async (
5051
);
5152

5253
if (platformName === 'macos') {
53-
return await runOnMac(xcodeProject, mode, scheme, args);
54+
await runOnMac(xcodeProject, mode, scheme, args);
55+
outro('Success 🎉.');
56+
return;
57+
} else if (args.catalyst) {
58+
await runOnMacCatalyst(platformName, mode, scheme, xcodeProject, args);
59+
outro('Success 🎉.');
60+
return;
5461
}
5562

5663
const loader = spinner();
@@ -74,9 +81,10 @@ export const createRun = async (
7481
scheme,
7582
args
7683
);
77-
} else {
84+
} else if (device.type === 'device') {
7885
await runOnDevice(device, platformName, mode, scheme, xcodeProject, args);
7986
}
87+
outro('Success 🎉.');
8088
return;
8189
} else {
8290
const bootedSimulators = devices.filter(

packages/plugin-platform-apple/src/lib/commands/run/getBuildPath.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { ApplePlatform } from '../../types/index.js';
44

55
export function getBuildPath(
66
buildSettings: BuildSettings,
7-
platform: ApplePlatform = 'ios',
8-
isCatalyst = false
7+
platform: ApplePlatform
98
) {
109
const targetBuildDir = buildSettings.TARGET_BUILD_DIR;
1110
const executableFolderPath = buildSettings.EXECUTABLE_FOLDER_PATH;
@@ -23,9 +22,7 @@ export function getBuildPath(
2322
throw new Error('Failed to get product name.');
2423
}
2524

26-
if (isCatalyst) {
27-
return path.join(`${targetBuildDir}-maccatalyst`, executableFolderPath);
28-
} else if (platform === 'macos') {
25+
if (platform === 'macos') {
2926
return path.join(targetBuildDir, fullProductName);
3027
} else {
3128
return path.join(targetBuildDir, executableFolderPath);

packages/plugin-platform-apple/src/lib/commands/run/installApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Options = {
1313
target?: string;
1414
udid: string;
1515
binaryPath?: string;
16-
platform?: ApplePlatform;
16+
platform: ApplePlatform;
1717
};
1818

1919
export default async function installApp({

packages/plugin-platform-apple/src/lib/commands/run/runOnDevice.ts

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ export async function runOnDevice(
1515
xcodeProject: XcodeProjectInfo,
1616
args: RunFlags
1717
) {
18-
if (args.binaryPath && selectedDevice.type === 'catalyst') {
19-
throw new Error(
20-
'binary-path was specified for catalyst device, which is not supported.'
21-
);
22-
}
23-
2418
try {
2519
await spawn('ios-deploy', ['--version']);
2620
} catch {
@@ -31,8 +25,9 @@ export async function runOnDevice(
3125
);
3226
}
3327

34-
if (selectedDevice.type === 'catalyst') {
35-
const buildOutput = await buildProject(
28+
let buildOutput, appPath;
29+
if (!args.binaryPath) {
30+
buildOutput = await buildProject(
3631
xcodeProject,
3732
platform,
3833
selectedDevice.udid,
@@ -52,57 +47,27 @@ export async function runOnDevice(
5247
throw new Error('Failed to get build settings for your project');
5348
}
5449

55-
const appPath = getBuildPath(buildSettings, platform, true);
56-
const appProcess = spawn(`${appPath}/${scheme}`, [], {
57-
detached: true,
58-
stdio: 'ignore',
59-
});
60-
(await appProcess.nodeChildProcess).unref();
50+
appPath = getBuildPath(buildSettings, platform);
6151
} else {
62-
let buildOutput, appPath;
63-
if (!args.binaryPath) {
64-
buildOutput = await buildProject(
65-
xcodeProject,
66-
platform,
67-
selectedDevice.udid,
68-
scheme,
69-
mode,
70-
args
71-
);
72-
73-
const buildSettings = await getBuildSettings(
74-
xcodeProject,
75-
mode,
76-
buildOutput,
77-
scheme
78-
);
79-
80-
if (!buildSettings) {
81-
throw new Error('Failed to get build settings for your project');
82-
}
83-
84-
appPath = getBuildPath(buildSettings, platform);
85-
} else {
86-
appPath = args.binaryPath;
87-
}
52+
appPath = args.binaryPath;
53+
}
8854

89-
const iosDeployInstallArgs = [
90-
'--bundle',
91-
appPath,
92-
'--id',
93-
selectedDevice.udid,
94-
'--justlaunch',
95-
];
55+
const iosDeployInstallArgs = [
56+
'--bundle',
57+
appPath,
58+
'--id',
59+
selectedDevice.udid,
60+
'--justlaunch',
61+
];
9662

97-
logger.info(`Installing and launching your app on ${selectedDevice.name}`);
63+
logger.info(`Installing and launching your app on ${selectedDevice.name}`);
9864

99-
try {
100-
await spawn('ios-deploy', iosDeployInstallArgs, { stdio: 'inherit' });
101-
} catch (error) {
102-
throw new Error(
103-
`Failed to install the app on the device with "ios-deploy": ${error}`
104-
);
105-
}
65+
try {
66+
await spawn('ios-deploy', iosDeployInstallArgs, { stdio: 'inherit' });
67+
} catch (error) {
68+
throw new Error(
69+
`Failed to install the app on the device with "ios-deploy": ${error}`
70+
);
10671
}
10772

10873
return logger.success('Installed the app on the device.');
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { ApplePlatform, XcodeProjectInfo } from '../../types/index.js';
2+
import { buildProject } from '../build/buildProject.js';
3+
import { getBuildPath } from './getBuildPath.js';
4+
import { getBuildSettings } from './getBuildSettings.js';
5+
import { RunFlags } from './runOptions.js';
6+
import spawn from 'nano-spawn';
7+
8+
export async function runOnMacCatalyst(
9+
platform: ApplePlatform,
10+
mode: string,
11+
scheme: string,
12+
xcodeProject: XcodeProjectInfo,
13+
args: RunFlags
14+
) {
15+
if (args.binaryPath) {
16+
throw new Error(
17+
'The "--binary-path" flag is not supported for Mac Catalyst device.'
18+
);
19+
}
20+
const buildOutput = await buildProject(
21+
xcodeProject,
22+
platform,
23+
undefined,
24+
scheme,
25+
mode,
26+
args
27+
);
28+
29+
const buildSettings = await getBuildSettings(
30+
xcodeProject,
31+
mode,
32+
buildOutput,
33+
scheme
34+
);
35+
36+
if (!buildSettings) {
37+
throw new Error('Failed to get build settings for your project');
38+
}
39+
40+
const appPath = getBuildPath(buildSettings, platform);
41+
const appProcess = spawn(`${appPath}/${scheme}`, [], {
42+
detached: true,
43+
stdio: 'ignore',
44+
});
45+
(await appProcess.nodeChildProcess).unref();
46+
}

packages/plugin-platform-apple/src/lib/commands/run/runOnSimulator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export async function runOnSimulator(
6363
target,
6464
udid: simulator.udid,
6565
binaryPath,
66+
platform,
6667
});
6768
loader.stop(`Installed the app on "${simulator.name}".`);
6869
}

packages/plugin-platform-apple/src/lib/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface Device {
1212
state?: 'Booted' | 'Shutdown';
1313
}
1414

15-
export type DeviceType = 'simulator' | 'device' | 'catalyst';
15+
export type DeviceType = 'simulator' | 'device';
1616

1717
export interface Info {
1818
name: string;

0 commit comments

Comments
 (0)