forked from react-native-community/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunOnDevice.ts
82 lines (73 loc) · 2.03 KB
/
runOnDevice.ts
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import child_process from 'child_process';
import {ApplePlatform, Device} from '../../types';
import {IOSProjectInfo} from '@react-native-community/cli-types';
import {CLIError, logger} from '@react-native-community/cli-tools';
import {buildProject} from '../buildCommand/buildProject';
import {getBuildPath} from './getBuildPath';
import {FlagsT} from './createRun';
import {getBuildSettings} from './getBuildSettings';
import installApp from './installApp';
export async function runOnDevice(
selectedDevice: Device,
platform: ApplePlatform,
mode: string,
scheme: string,
xcodeProject: IOSProjectInfo,
args: FlagsT,
) {
if (args.binaryPath && selectedDevice.type === 'catalyst') {
throw new CLIError(
'binary-path was specified for catalyst device, which is not supported.',
);
}
if (selectedDevice.type === 'catalyst') {
const buildOutput = await buildProject(
xcodeProject,
platform,
selectedDevice.udid,
mode,
scheme,
args,
);
const buildSettings = await getBuildSettings(
xcodeProject,
mode,
buildOutput,
scheme,
);
if (!buildSettings) {
throw new CLIError('Failed to get build settings for your project');
}
const appPath = await getBuildPath(buildSettings, platform, true);
const appProcess = child_process.spawn(`${appPath}/${scheme}`, [], {
detached: true,
stdio: 'ignore',
});
appProcess.unref();
} else {
const {binaryPath, target} = args;
let buildOutput;
if (!binaryPath) {
buildOutput = await buildProject(
xcodeProject,
platform,
selectedDevice.udid,
mode,
scheme,
args,
);
}
logger.info(`Installing and launching your app on ${selectedDevice.name}`);
installApp({
buildOutput: buildOutput ?? '',
xcodeProject,
mode,
scheme,
target,
udid: selectedDevice.udid,
binaryPath,
isSimulator: false,
});
}
return logger.success('Installed the app on the device.');
}