forked from react-native-community/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetBuildConfigurationFromXcScheme.ts
More file actions
53 lines (46 loc) · 1.47 KB
/
Copy pathgetBuildConfigurationFromXcScheme.ts
File metadata and controls
53 lines (46 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {CLIError} from '@react-native-community/cli-tools';
import chalk from 'chalk';
import {XMLParser} from 'fast-xml-parser';
import fs from 'fs';
import path from 'path';
import {IosInfo} from '../types';
const xmlParser = new XMLParser({ignoreAttributes: false});
export function getBuildConfigurationFromXcScheme(
scheme: string,
configuration: string,
sourceDir: string,
projectInfo: IosInfo | undefined,
): string {
// can not assume .xcodeproj exists.
// for more info see: https://github.com/react-native-community/cli/pull/2196
try {
const xcProject = fs
.readdirSync(sourceDir)
.find((dir) => dir.endsWith('.xcodeproj'));
if (xcProject) {
const xmlScheme = fs.readFileSync(
path.join(
sourceDir,
xcProject,
'xcshareddata',
'xcschemes',
`${scheme}.xcscheme`,
),
{
encoding: 'utf-8',
},
);
const {Scheme} = xmlParser.parse(xmlScheme);
return Scheme.LaunchAction['@_buildConfiguration'];
}
} catch {
const projectSchemes =
projectInfo?.schemes && projectInfo.schemes.length > 0
? `${projectInfo.schemes.map((name) => chalk.bold(name)).join(', ')}`
: 'No schemes';
throw new CLIError(
`Could not load the shared scheme for ${scheme}. Your project configuration includes: ${projectSchemes}. Please ensure a valid .xcscheme file exists in xcshareddata/xcschemes.`,
);
}
return configuration;
}