Skip to content

Get device by name and sdk #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions lib/iphone-simulator-xcode-simctl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,33 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
return this.deviceLogChildProcess;
}

private getDeviceToRun(): IDevice {
let devices = this.simctl.getDevices(),
sdkVersion = options.sdkVersion || options.sdk;
private getDeviceToRun(device?: any): IDevice {
let devices = _.sortBy(this.simctl.getDevices(), (device) => device.runtimeVersion),
sdkVersion = options.sdkVersion || options.sdk,
deviceIdOrName = options.device;

if (device && (device.sdkVersion || device.sdk)) {
sdkVersion = device.sdkVersion || device.sdk;
}

if (device && device.id) {
deviceIdOrName = device.id;
}

let result = _.find(devices, (device: IDevice) => {
if (sdkVersion && !options.device) {
if (sdkVersion && !deviceIdOrName) {
return device.runtimeVersion === sdkVersion;
}

if (options.device && !sdkVersion) {
return device.name === options.device || device.id === options.device;
if (deviceIdOrName && !sdkVersion) {
return device.name === deviceIdOrName || device.id === deviceIdOrName;
}

if (options.device && sdkVersion) {
return device.runtimeVersion === sdkVersion && (device.name === options.device || device.id === options.device);
if (deviceIdOrName && sdkVersion) {
return device.runtimeVersion === sdkVersion && (device.name === deviceIdOrName || device.id === deviceIdOrName);
}

if (!sdkVersion && !options.device) {
if (!sdkVersion && !deviceIdOrName) {
return this.isDeviceBooted(device);
}
});
Expand All @@ -204,8 +213,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
}

if (!result) {
let sortedDevices = _.sortBy(devices, (device) => device.runtimeVersion);
result = _.last(sortedDevices);
result = _.last(devices);
}

return result;
Expand All @@ -226,7 +234,9 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
}

public startSimulator(device?: IDevice): void {
device = device || this.getDeviceToRun();
if (!device || !device.runtimeVersion || !device.fullId) {
device = this.getDeviceToRun(device);
}

// In case the id is undefined, skip verification - we'll start default simulator.
if (device.id) {
Expand Down Expand Up @@ -273,7 +283,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I

private verifyDevice(device: IDevice): void {
const availableDevices = this.getDevices();
if (!_.find(availableDevices, { id: device.id })) {
if (!_.find(availableDevices, { id: device.id }) && !_.find(availableDevices, { name: device.id })) {
errors.fail(`No simulator image available for device identifier '${device.id}'.`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ios-sim-portable",
"version": "3.3.1",
"version": "3.3.2",
"description": "",
"main": "./lib/ios-sim.js",
"scripts": {
Expand Down