Skip to content

Commit 4009ec0

Browse files
author
The Debuggernaut
committed
chore: move scripts to be ts files
1 parent 776af51 commit 4009ec0

File tree

5 files changed

+115
-19
lines changed

5 files changed

+115
-19
lines changed

scripts/ci.sh

100644100755
Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,23 +159,7 @@ function start_appium_server() {
159159
# Function to stop running simulators
160160
function stop_simulators_from_env_iOS() {
161161
echo "Stopping iOS simulators from environment variables..."
162+
xcrun simctl shutdown "all"
163+
}
162164

163-
for i in {1..12}; do
164-
simulator_label=$i
165-
env_var="IOS_${simulator_label}_SIMULATOR"
166-
simulator_udid=$(printenv "$env_var")
167-
168-
if [[ -n "$simulator_udid" ]]; then
169-
# Check if the simulator is running
170-
if xcrun simctl list devices booted | grep -q "$simulator_udid"; then
171-
echo "Stopping $simulator_label simulator: $simulator_udid"
172-
xcrun simctl shutdown "$simulator_udid"
173-
else
174-
echo "$simulator_label simulator is not running or does not exist... skipping"
175-
fi
176-
else
177-
echo "Skipping $simulator_label simulator (not set)"
178-
return 120
179-
fi
180-
done
181-
}
165+
set +x

scripts/ios_shared.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
import { execSync } from 'child_process';
3+
4+
5+
export function getSimulatorUDID(index: number) {
6+
const envVar = `IOS_${index}_SIMULATOR`;
7+
return process.env[envVar];
8+
}
9+
10+
11+
12+
export function isSimulatorBooted(udid: string) {
13+
try {
14+
const result = execSync(`xcrun simctl list devices booted`).toString();
15+
return result.includes(udid);
16+
} catch (error: any) {
17+
console.error("Error checking booted devices", error.message);
18+
return false;
19+
}
20+
}
21+
22+
23+
24+
export function isAnySimulatorBooted() {
25+
try {
26+
const result = execSync(`xcrun simctl list devices booted`).toString();
27+
return result.includes("Booted");
28+
} catch (error: any) {
29+
console.error("Error checking booted devices", error.message);
30+
return false;
31+
}
32+
}

scripts/shared.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export async function sleep(ms: number) {
2+
return new Promise(resolve => setTimeout(resolve, ms));
3+
}

scripts/start_ios.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { execSync, spawnSync } from 'child_process';
2+
import { getSimulatorUDID, isSimulatorBooted } from './ios_shared';
3+
import { sleep } from './shared';
4+
5+
const START_CHUNK = 6;
6+
const MAX_SIMULATORS = 12;
7+
8+
function bootSimulator(udid: string, label: number) {
9+
try {
10+
console.log(`Booting simulator ${label}: ${udid}`);
11+
const result = execSync(`xcrun simctl boot ${udid}`, { stdio: 'pipe' }).toString();
12+
console.log(`Boot command output: ${result}`);
13+
} catch (error: any) {
14+
console.error(`Error: Boot command failed for ${udid}`);
15+
console.error(error.stderr?.toString() || error.message);
16+
return false;
17+
}
18+
19+
return true;
20+
}
21+
22+
async function startSimulatorsFromEnvIOS() {
23+
console.log("Starting iOS simulators from environment variables...");
24+
25+
const simulators = [];
26+
for (let i = 1; i <= MAX_SIMULATORS; i++) {
27+
const udid = getSimulatorUDID(i);
28+
if (!udid) {
29+
throw new Error(`Error: Simulator ${i} (IOS_${i}_SIMULATOR) is not set`);
30+
}
31+
simulators.push({ label: i, udid });
32+
}
33+
34+
for (let i = 0; i < simulators.length; i += START_CHUNK) {
35+
const chunk = simulators.slice(i, i + START_CHUNK);
36+
37+
for (const sim of chunk) {
38+
const success = bootSimulator(sim.udid, sim.label);
39+
if (!success) throw new Error(`Failed to boot simulator with parameters: ${sim.udid}:${sim.label}`);
40+
}
41+
42+
// Wait for simulators to boot
43+
await sleep(5000);
44+
45+
for (const sim of chunk) {
46+
const booted = isSimulatorBooted(sim.udid);
47+
console.log(`Post-boot status for ${sim.udid}: ${booted ? 'Booted' : 'Not booted'}`);
48+
if (!booted) {
49+
console.error(`Error: Simulator ${sim.udid} did not boot successfully.`);
50+
return;
51+
}
52+
}
53+
}
54+
55+
console.log("Opening iOS Simulator app...");
56+
spawnSync('open', ['-a', 'Simulator']);
57+
}
58+
59+
startSimulatorsFromEnvIOS();

scripts/stop_ios.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { execSync } from 'child_process';
2+
import { isAnySimulatorBooted } from './ios_shared';
3+
4+
5+
async function stopSimulatorsFromEnvIOS() {
6+
console.log("Stopping all iOS simulators");
7+
execSync(`xcrun simctl shutdown "all"`).toString();
8+
if (isAnySimulatorBooted()) {
9+
execSync(`xcrun simctl shutdown "all"`).toString();
10+
}
11+
if (isAnySimulatorBooted()) {
12+
throw new Error("Failed to kill all running simulators")
13+
}
14+
15+
console.log("All iOS simulators closed...");
16+
}
17+
18+
stopSimulatorsFromEnvIOS();

0 commit comments

Comments
 (0)