Skip to content

Commit 94ddf56

Browse files
committed
ref(device): Share platform mapping helper
Extract device platform string-to-enum mapping into a shared helper used by build_run_device and get_device_app_path. This removes duplicated mapping logic while preserving existing behavior and keeps device tool platform handling consistent in one place.
1 parent 9c49bf8 commit 94ddf56

3 files changed

Lines changed: 21 additions & 35 deletions

File tree

src/mcp/tools/device/build-settings.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ function resolvePathFromCwd(pathValue?: string): string | undefined {
1414
return path.resolve(process.cwd(), pathValue);
1515
}
1616

17+
export type DevicePlatform = 'iOS' | 'watchOS' | 'tvOS' | 'visionOS';
18+
19+
export function mapDevicePlatform(platform?: DevicePlatform): XcodePlatform {
20+
switch (platform) {
21+
case 'watchOS':
22+
return XcodePlatform.watchOS;
23+
case 'tvOS':
24+
return XcodePlatform.tvOS;
25+
case 'visionOS':
26+
return XcodePlatform.visionOS;
27+
case 'iOS':
28+
case undefined:
29+
default:
30+
return XcodePlatform.iOS;
31+
}
32+
}
33+
1734
export function getBuildSettingsDestination(platform: XcodePlatform, deviceId?: string): string {
1835
if (deviceId) {
1936
return `platform=${platform},id=${deviceId}`;

src/mcp/tools/device/build_run_device.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { nullifyEmptyStrings } from '../../../utils/schema-helpers.ts';
2323
import { extractBundleIdFromAppPath } from '../../../utils/bundle-id.ts';
2424
import { install_app_deviceLogic } from './install_app_device.ts';
2525
import { launch_app_deviceLogic } from './launch_app_device.ts';
26-
import { resolveAppPathFromBuildSettings } from './build-settings.ts';
26+
import { mapDevicePlatform, resolveAppPathFromBuildSettings } from './build-settings.ts';
2727

2828
const baseSchemaObject = z.object({
2929
projectPath: z.string().optional().describe('Path to the .xcodeproj file'),
@@ -54,21 +54,6 @@ const buildRunDeviceSchema = z.preprocess(
5454

5555
export type BuildRunDeviceParams = z.infer<typeof buildRunDeviceSchema>;
5656

57-
function mapPlatform(platform?: BuildRunDeviceParams['platform']): XcodePlatform {
58-
switch (platform) {
59-
case 'watchOS':
60-
return XcodePlatform.watchOS;
61-
case 'tvOS':
62-
return XcodePlatform.tvOS;
63-
case 'visionOS':
64-
return XcodePlatform.visionOS;
65-
case 'iOS':
66-
case undefined:
67-
default:
68-
return XcodePlatform.iOS;
69-
}
70-
}
71-
7257
function extractResponseText(response: ToolResponse): string {
7358
return String(response.content[0]?.text ?? 'Unknown error');
7459
}
@@ -94,7 +79,7 @@ export async function build_run_deviceLogic(
9479
executor: CommandExecutor,
9580
fileSystemExecutor: FileSystemExecutor = getDefaultFileSystemExecutor(),
9681
): Promise<ToolResponse> {
97-
const platform = mapPlatform(params.platform);
82+
const platform = mapDevicePlatform(params.platform);
9883

9984
const sharedBuildParams: SharedBuildParams = {
10085
projectPath: params.projectPath,

src/mcp/tools/device/get_device_app_path.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import * as z from 'zod';
99
import type { ToolResponse } from '../../../types/common.ts';
10-
import { XcodePlatform } from '../../../types/common.ts';
1110
import { log } from '../../../utils/logging/index.ts';
1211
import { createTextResponse } from '../../../utils/responses/index.ts';
1312
import type { CommandExecutor } from '../../../utils/execution/index.ts';
@@ -17,7 +16,7 @@ import {
1716
getSessionAwareToolSchemaShape,
1817
} from '../../../utils/typed-tool-factory.ts';
1918
import { nullifyEmptyStrings } from '../../../utils/schema-helpers.ts';
20-
import { resolveAppPathFromBuildSettings } from './build-settings.ts';
19+
import { mapDevicePlatform, resolveAppPathFromBuildSettings } from './build-settings.ts';
2120

2221
// Unified schema: XOR between projectPath and workspacePath, sharing common options
2322
const baseOptions = {
@@ -54,26 +53,11 @@ const publicSchemaObject = baseSchemaObject.omit({
5453
platform: true,
5554
} as const);
5655

57-
function mapPlatform(platform?: GetDeviceAppPathParams['platform']): XcodePlatform {
58-
switch (platform) {
59-
case 'watchOS':
60-
return XcodePlatform.watchOS;
61-
case 'tvOS':
62-
return XcodePlatform.tvOS;
63-
case 'visionOS':
64-
return XcodePlatform.visionOS;
65-
case 'iOS':
66-
case undefined:
67-
default:
68-
return XcodePlatform.iOS;
69-
}
70-
}
71-
7256
export async function get_device_app_pathLogic(
7357
params: GetDeviceAppPathParams,
7458
executor: CommandExecutor,
7559
): Promise<ToolResponse> {
76-
const platform = mapPlatform(params.platform);
60+
const platform = mapDevicePlatform(params.platform);
7761
const configuration = params.configuration ?? 'Debug';
7862

7963
log('info', `Getting app path for scheme ${params.scheme} on platform ${platform}`);

0 commit comments

Comments
 (0)