( executor: CommandExecutor, scheme: string, projectPath?: string | null, workspacePath?: string | null, )
| 45 | * Look up bundle ID for a scheme using xcodebuild -showBuildSettings |
| 46 | */ |
| 47 | export async function lookupBundleId( |
| 48 | executor: CommandExecutor, |
| 49 | scheme: string, |
| 50 | projectPath?: string | null, |
| 51 | workspacePath?: string | null, |
| 52 | ): Promise<string | undefined> { |
| 53 | const args = ['xcodebuild', '-showBuildSettings', '-scheme', scheme, '-skipPackageUpdates']; |
| 54 | |
| 55 | if (workspacePath) { |
| 56 | args.push('-workspace', workspacePath); |
| 57 | } else if (projectPath) { |
| 58 | args.push('-project', projectPath); |
| 59 | } else { |
| 60 | // No project/workspace specified, let xcodebuild find it |
| 61 | } |
| 62 | |
| 63 | const result = await executor(args, 'Get bundle ID from build settings', false); |
| 64 | |
| 65 | if (!result.success) { |
| 66 | log('debug', `[xcode-watcher] Failed to get build settings: ${result.error}`); |
| 67 | return undefined; |
| 68 | } |
| 69 | |
| 70 | const matches = [...result.output.matchAll(/PRODUCT_BUNDLE_IDENTIFIER\s*=\s*(.+)/g)] |
| 71 | .map((match) => match[1]?.trim()) |
| 72 | .filter((value): value is string => Boolean(value) && value !== 'NO'); |
| 73 | |
| 74 | const preferredMatch = matches.find((value) => value.includes('.')); |
| 75 | return preferredMatch ?? matches[0]; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Extract scheme and simulator ID from xcuserstate file |
no test coverage detected