Skip to content

Commit 41a34ce

Browse files
Fatme HavaluovaFatme Havaluova
authored andcommitted
Validate device and sdkVersion options
Remove unneeded code Don't handle watch devices and sdks Polish sdk list
1 parent 0249e57 commit 41a34ce

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

lib/iphone-simulator-xcode-7.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ export class XCode7Simulator implements ISimulator {
2929
public getSdks(): IFuture<ISdk[]> {
3030
return (() => {
3131
let devices = this.simctl.getDevices().wait();
32-
return _.map(devices, device => device.runtimeVersion);
32+
return _.map(devices, device => {
33+
return {
34+
displayName: `iOS ${device.runtimeVersion}`,
35+
version: device.runtimeVersion
36+
};
37+
});
3338
}).future<ISdk[]>()();
3439
}
3540

lib/iphone-simulator.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,25 @@ export class iPhoneSimulator implements IiPhoneSimulator {
2525
this.simulator = this.createSimulator().wait();
2626
}
2727

28-
public get validDeviceIdentifiers(): string[] {
29-
var devices = this.simulator.getDevices().wait();
30-
return _.map(devices, device => device.id);
31-
}
32-
3328
public run(applicationPath: string, applicationIdentifier: string): IFuture<void> {
3429
if(!fs.existsSync(applicationPath)) {
3530
errors.fail("Path does not exist ", applicationPath);
3631
}
3732

33+
if(options.device) {
34+
let deviceNames = _.unique(_.map(this.simulator.getDevices().wait(), (device: IDevice) => device.name));
35+
if(!_.contains(deviceNames, options.device)) {
36+
errors.fail(`Unable to find device ${options.device}. The valid device names are ${deviceNames.join(", ")}`);
37+
}
38+
}
39+
40+
if(options.sdkVersion) {
41+
let runtimeVersions = _.unique(_.map(this.simulator.getDevices().wait(), (device: IDevice) => device.runtimeVersion));
42+
if(!_.contains(runtimeVersions, options.sdkVersion)) {
43+
errors.fail(`Unable to find sdk ${options.sdkVersion}. The valid runtime versions are ${runtimeVersions.join(", ")}`);
44+
}
45+
}
46+
3847
return this.simulator.run(applicationPath, applicationIdentifier);
3948
}
4049

@@ -48,9 +57,13 @@ export class iPhoneSimulator implements IiPhoneSimulator {
4857
public printSDKS(): IFuture<void> {
4958
return (() => {
5059
let sdks = this.simulator.getSdks().wait();
51-
_.each(sdks, (sdk) => console.log([util.format(" Display Name: %s", sdk.displayName),
52-
util.format(" Version: %s", sdk.version),
53-
util.format(" Root path: %s", sdk.rootPath)].join(os.EOL)) );
60+
_.each(sdks, (sdk) => {
61+
let output = ` Display Name: ${sdk.displayName} ${os.EOL} Version: ${sdk.version} ${os.EOL}`;
62+
if(sdk.rootPath) {
63+
output += ` Root path: ${sdk.rootPath} ${os.EOL}`;
64+
}
65+
console.log(output);
66+
});
5467
}).future<void>()();
5568
}
5669

lib/simctl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class Simctl implements ISimctl {
6161
// so, get the `-- iOS X.X --` line to find the sdk (X.X)
6262
// and the rest of the listing in order to later find the devices
6363

64-
let deviceSectionRegex = /-- (iOS|watchOS) (.+) --(\n .+)*/mg;
64+
let deviceSectionRegex = /-- (iOS) (.+) --(\n .+)*/mg;
6565
let match = deviceSectionRegex.exec(rawDevices);
6666

6767
let matches: any[] = [];

0 commit comments

Comments
 (0)