Skip to content

Commit 9661458

Browse files
committed
feat: changed name to ios-simulators to reflect plural form. Removed state parameter
1 parent 360fb4e commit 9661458

7 files changed

Lines changed: 51 additions & 80 deletions

File tree

completions-cron/src/__generated__/completions-index.ts

Lines changed: 24 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/resources/(resources)/ios-simulator.mdx renamed to docs/resources/(resources)/ios-simulators.mdx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ description: A reference page for the ios-simulator resource
55

66
The ios-simulator resource manages iOS (and iPadOS/watchOS/tvOS/visionOS) simulator instances on macOS
77
using `xcrun simctl`. A single resource declaration manages a list of simulators, making it easy to
8-
define a full testing matrix across device types and OS versions in one place. Simulators are created
9-
with the specified device type and runtime, and optionally booted. Removing the resource deletes all
8+
define a full testing matrix across device types and OS versions in one place. Simulators are created with the specified device type and runtime. Removing the resource deletes all
109
declared simulators from the system. Xcode Command Line Tools must be installed — add an
1110
`xcode-tools` resource as a dependency if you are not sure they are present.
1211

@@ -16,20 +15,20 @@ declared simulators from the system. Xcode Command Line Tools must be installed
1615
- **name** *(string, required)* — Human-readable name for the simulator instance (e.g. `"iPhone 15 Dev"`). Must be unique across your declared simulators.
1716
- **deviceType** *(string, required)* — CoreSimulator device type identifier. Use the format `com.apple.CoreSimulator.SimDeviceType.<Device>`. Run `xcrun simctl list devicetypes` to see identifiers available on your machine.
1817
- **runtime** *(string, required)* — CoreSimulator runtime identifier. Use the format `com.apple.CoreSimulator.SimRuntime.<Platform>-<Version>`. Run `xcrun simctl list runtimes` to see installed runtimes.
19-
- **state** *(string, optional)* — Desired runtime state of the simulator. One of `"Booted"` or `"Shutdown"`. Defaults to `"Shutdown"`. Can be modified after creation.
18+
2019

2120
## Example usage:
2221

2322
```json title="codify.jsonc"
2423
[
2524
{
26-
"type": "ios-simulator",
25+
"type": "ios-simulators",
2726
"simulators": [
2827
{
2928
"name": "iPhone 15 Dev",
3029
"deviceType": "com.apple.CoreSimulator.SimDeviceType.iPhone-15",
3130
"runtime": "com.apple.CoreSimulator.SimRuntime.iOS-18-0",
32-
"state": "Shutdown"
31+
3332
}
3433
],
3534
"os": ["macOS"]
@@ -44,19 +43,19 @@ declared simulators from the system. Xcode Command Line Tools must be installed
4443
"os": ["macOS"]
4544
},
4645
{
47-
"type": "ios-simulator",
46+
"type": "ios-simulators",
4847
"simulators": [
4948
{
5049
"name": "iPhone 15 Pro",
5150
"deviceType": "com.apple.CoreSimulator.SimDeviceType.iPhone-15-Pro",
5251
"runtime": "com.apple.CoreSimulator.SimRuntime.iOS-18-0",
53-
"state": "Shutdown"
52+
5453
},
5554
{
5655
"name": "iPad Pro 11-inch",
5756
"deviceType": "com.apple.CoreSimulator.SimDeviceType.iPad-Pro-11-inch-M4",
5857
"runtime": "com.apple.CoreSimulator.SimRuntime.iOS-18-0",
59-
"state": "Shutdown"
58+
6059
}
6160
],
6261
"os": ["macOS"]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "default",
3-
"version": "1.14.0",
3+
"version": "1.15.0-beta.2",
44
"description": "Default plugin for Codify - provides 50+ declarative resources for managing development tools and system configuration across macOS and Linux",
55
"main": "dist/index.js",
66
"scripts": {

src/resources/ios/ios-simulator/completions/ios-simulator.deviceType.ts renamed to src/resources/ios/ios-simulator/completions/ios-simulators.simulators.deviceType.ts

File renamed without changes.

src/resources/ios/ios-simulator/completions/ios-simulator.runtime.ts renamed to src/resources/ios/ios-simulator/completions/ios-simulators.simulators.runtime.ts

File renamed without changes.

src/resources/ios/ios-simulator/ios-simulator.ts

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ const simulatorSchema = z.object({
1616
name: z.string().describe('Name for the simulator instance (e.g. "iPhone 15 Dev")'),
1717
deviceType: z.string().describe('Device type identifier (e.g. "com.apple.CoreSimulator.SimDeviceType.iPhone-15")'),
1818
runtime: z.string().describe('Runtime identifier (e.g. "com.apple.CoreSimulator.SimRuntime.iOS-18-0")'),
19-
state: z
20-
.enum(['Booted', 'Shutdown'])
21-
.optional()
22-
.describe('Desired runtime state. Defaults to Shutdown.'),
2319
});
2420

2521
export type SimulatorDeclaration = z.infer<typeof simulatorSchema>;
@@ -53,13 +49,12 @@ const exampleBasic: ExampleConfig = {
5349
title: 'iPhone 15 simulator for development',
5450
description: 'Create an iPhone 15 simulator running iOS 18 for use in development and UI testing.',
5551
configs: [{
56-
type: 'ios-simulator',
52+
type: 'ios-simulators',
5753
simulators: [
5854
{
5955
name: 'iPhone 15 Dev',
6056
deviceType: 'com.apple.CoreSimulator.SimDeviceType.iPhone-15',
6157
runtime: 'com.apple.CoreSimulator.SimRuntime.iOS-18-0',
62-
state: 'Shutdown',
6358
},
6459
],
6560
os: ['macOS'],
@@ -72,19 +67,17 @@ const exampleMultiDevice: ExampleConfig = {
7267
configs: [
7368
{ type: 'xcode-tools', os: ['macOS'] },
7469
{
75-
type: 'ios-simulator',
70+
type: 'ios-simulators',
7671
simulators: [
7772
{
7873
name: 'iPhone 15 Pro',
7974
deviceType: 'com.apple.CoreSimulator.SimDeviceType.iPhone-15-Pro',
8075
runtime: 'com.apple.CoreSimulator.SimRuntime.iOS-18-0',
81-
state: 'Shutdown',
8276
},
8377
{
8478
name: 'iPad Pro 11-inch',
8579
deviceType: 'com.apple.CoreSimulator.SimDeviceType.iPad-Pro-11-inch-M4',
8680
runtime: 'com.apple.CoreSimulator.SimRuntime.iOS-18-0',
87-
state: 'Shutdown',
8881
},
8982
],
9083
os: ['macOS'],
@@ -95,7 +88,7 @@ const exampleMultiDevice: ExampleConfig = {
9588
export class IosSimulatorResource extends Resource<IosSimulatorConfig> {
9689
getSettings(): ResourceSettings<IosSimulatorConfig> {
9790
return {
98-
id: 'ios-simulator',
91+
id: 'ios-simulators',
9992
defaultConfig,
10093
exampleConfigs: {
10194
example1: exampleBasic,
@@ -111,8 +104,7 @@ export class IosSimulatorResource extends Resource<IosSimulatorConfig> {
111104
isElementEqual: (a, b) =>
112105
a.name === b.name &&
113106
a.deviceType === b.deviceType &&
114-
a.runtime === b.runtime &&
115-
a.state === b.state,
107+
a.runtime === b.runtime,
116108
filterInStatelessMode: (desired, current) =>
117109
current.filter((c) => desired.some((d) => d.name === c.name)),
118110
canModify: true,
@@ -132,7 +124,6 @@ export class IosSimulatorResource extends Resource<IosSimulatorConfig> {
132124
name: device.name,
133125
deviceType: device.deviceTypeIdentifier,
134126
runtime: runtimeId,
135-
state: device.state === 'Booted' ? 'Booted' : 'Shutdown',
136127
});
137128
}
138129
}
@@ -144,13 +135,10 @@ export class IosSimulatorResource extends Resource<IosSimulatorConfig> {
144135
await this.assertSimctlAvailable();
145136
const $ = getPty();
146137
for (const sim of plan.desiredConfig.simulators ?? []) {
147-
const { data: udid } = await $.spawn(
138+
await $.spawn(
148139
`xcrun simctl create "${sim.name}" "${sim.deviceType}" "${sim.runtime}"`,
149140
{ interactive: true },
150141
);
151-
if (sim.state === 'Booted') {
152-
await $.spawn(`xcrun simctl boot "${udid.trim()}"`, { interactive: true });
153-
}
154142
}
155143
}
156144

@@ -171,38 +159,18 @@ export class IosSimulatorResource extends Resource<IosSimulatorConfig> {
171159
const previous: SimulatorDeclaration[] = pc.previousValue ?? [];
172160
const desired: SimulatorDeclaration[] = pc.newValue ?? [];
173161

174-
// Remove simulators no longer declared
175162
const toRemove = previous.filter((p) => !desired.some((d) => d.name === p.name));
176163
for (const sim of toRemove) {
177164
const udid = findUdid(sim.name);
178165
if (udid) await $.spawn(`xcrun simctl delete "${udid}"`, { interactive: true });
179166
}
180167

181-
// Add newly declared simulators
182168
const toAdd = desired.filter((d) => !previous.some((p) => p.name === d.name));
183169
for (const sim of toAdd) {
184-
const { data: udid } = await $.spawn(
170+
await $.spawn(
185171
`xcrun simctl create "${sim.name}" "${sim.deviceType}" "${sim.runtime}"`,
186172
{ interactive: true },
187173
);
188-
if (sim.state === 'Booted') {
189-
await $.spawn(`xcrun simctl boot "${udid.trim()}"`, { interactive: true });
190-
}
191-
}
192-
193-
// Update state for simulators that changed only their state
194-
const stateChanged = desired.filter((d) => {
195-
const prev = previous.find((p) => p.name === d.name);
196-
return prev && prev.state !== d.state;
197-
});
198-
for (const sim of stateChanged) {
199-
const udid = findUdid(sim.name);
200-
if (!udid) continue;
201-
if (sim.state === 'Booted') {
202-
await $.spawn(`xcrun simctl boot "${udid}"`, { interactive: true });
203-
} else {
204-
await $.spawn(`xcrun simctl shutdown "${udid}"`, { interactive: true });
205-
}
206174
}
207175
}
208176

test/ios/ios-simulator.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ const skip = !Utils.isMacOS() || !isXcodeInstalled();
1414
describe('iOS Simulator tests', { skip }, async () => {
1515
const pluginPath = path.resolve('./src/index.ts');
1616

17-
it('Can create, modify state, and destroy iOS simulators', { timeout: 300000 }, async () => {
17+
it('Can create, add a simulator, and destroy iOS simulators', { timeout: 300000 }, async () => {
1818
await PluginTester.fullTest(pluginPath, [
1919
{
20-
type: 'ios-simulator',
20+
type: 'ios-simulators',
2121
simulators: [
2222
{
2323
name: 'codify-test-iphone',
2424
deviceType: 'com.apple.CoreSimulator.SimDeviceType.iPhone-15',
2525
runtime: 'com.apple.CoreSimulator.SimRuntime.iOS-18-0',
26-
state: 'Shutdown',
2726
},
2827
],
2928
},
@@ -33,37 +32,38 @@ describe('iOS Simulator tests', { skip }, async () => {
3332
expect(status).toBe(SpawnStatus.SUCCESS);
3433
const parsed = JSON.parse(data);
3534
const allDevices: any[] = Object.values(parsed.devices).flat();
36-
const sim = allDevices.find((d: any) => d.name === 'codify-test-iphone');
37-
expect(sim).toBeDefined();
38-
expect(sim.state).toBe('Shutdown');
35+
expect(allDevices.find((d: any) => d.name === 'codify-test-iphone')).toBeDefined();
3936
},
4037
testModify: {
4138
modifiedConfigs: [{
42-
type: 'ios-simulator',
39+
type: 'ios-simulators',
4340
simulators: [
4441
{
4542
name: 'codify-test-iphone',
4643
deviceType: 'com.apple.CoreSimulator.SimDeviceType.iPhone-15',
4744
runtime: 'com.apple.CoreSimulator.SimRuntime.iOS-18-0',
48-
state: 'Booted',
45+
},
46+
{
47+
name: 'codify-test-ipad',
48+
deviceType: 'com.apple.CoreSimulator.SimDeviceType.iPad-mini-6th-generation',
49+
runtime: 'com.apple.CoreSimulator.SimRuntime.iOS-18-0',
4950
},
5051
],
5152
}],
5253
validateModify: async () => {
5354
const { data } = await testSpawn('xcrun simctl list devices --json');
5455
const parsed = JSON.parse(data);
5556
const allDevices: any[] = Object.values(parsed.devices).flat();
56-
const sim = allDevices.find((d: any) => d.name === 'codify-test-iphone');
57-
expect(sim).toBeDefined();
58-
expect(sim.state).toBe('Booted');
57+
expect(allDevices.find((d: any) => d.name === 'codify-test-iphone')).toBeDefined();
58+
expect(allDevices.find((d: any) => d.name === 'codify-test-ipad')).toBeDefined();
5959
},
6060
},
6161
validateDestroy: async () => {
6262
const { data } = await testSpawn('xcrun simctl list devices --json');
6363
const parsed = JSON.parse(data);
6464
const allDevices: any[] = Object.values(parsed.devices).flat();
65-
const sim = allDevices.find((d: any) => d.name === 'codify-test-iphone');
66-
expect(sim).toBeUndefined();
65+
expect(allDevices.find((d: any) => d.name === 'codify-test-iphone')).toBeUndefined();
66+
expect(allDevices.find((d: any) => d.name === 'codify-test-ipad')).toBeUndefined();
6767
},
6868
});
6969
});

0 commit comments

Comments
 (0)