-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimctl.js
More file actions
94 lines (74 loc) · 1.89 KB
/
simctl.js
File metadata and controls
94 lines (74 loc) · 1.89 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
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
83
84
85
86
87
88
89
90
91
92
93
94
const core = require('@actions/core');
const exec = require('@actions/exec');
const Runtime = require('./runtime');
const Simulator = require('./simulator');
exports.listSimulators = async() => {
let output = '';
let error = '';
const options = {};
options.listeners = {
stdout: (data) => {
output += data.toString();
},
stderr: (data) => {
error += data.toString();
}
};
if (core.isDebug()) {
options.silent = false;
} else {
options.silent = true;
}
await exec.exec('xcrun simctl list devices', ['--json'], options);
if (error.length > 0) {
throw error;
}
const rawDeviceObject = JSON.parse(output).devices;
return Object.entries(rawDeviceObject).flatMap(([rawRuntime, rawSimulators]) => {
const runtime = new Runtime(rawRuntime);
return rawSimulators.map(rawSimulator => new Simulator(rawSimulator, runtime));
});
};
exports.findMatchingSimulator = async(platform, name, os) => {
const simulators = await exports.listSimulators();
const matchingSimulators = simulators.filter(simulator => {
if (simulator.name != name) {
return false;
}
if (platform.length > 0 && simulator.runtime.platform != platform) {
return false;
}
if (os.length > 0 && simulator.runtime.os != os) {
return false;
}
return true;
})
.sort((a, b) => {
if (a.runtime.os > b.runtime.os) {
return -1;
}
if (a.runtime.os < b.runtime.os) {
return 1;
}
return 0;
});
return matchingSimulators[0];
};
exports.boot = async(simulator) => {
let error = '';
const options = {};
options.listeners = {
stderr: (data) => {
error += data.toString();
}
};
if (core.isDebug()) {
options.silent = false;
} else {
options.silent = true;
}
await exec.exec('xcrun simctl boot', [simulator.udid], options);
if (error.length > 0) {
throw error;
}
};