Skip to content

Commit 49ed85e

Browse files
author
Mitko-Kerezov
committed
Expose method for getting the name of the simulator
Said name is needed in order to pass it to xcodebuild whenever building for a simulator.
1 parent 154889c commit 49ed85e

7 files changed

+57
-72
lines changed

lib/declarations.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ interface IDictionary<T> {
3939
[key: string]: T;
4040
}
4141

42-
interface IInteropSimulator {
42+
interface IInteropSimulator extends INameGetter {
4343
getDevices(): IFuture<IDevice[]>;
4444
setSimulatedDevice(config: any): void;
4545
}
4646

47-
interface ISimulator {
47+
interface ISimulator extends INameGetter {
4848
getDevices(): IFuture<IDevice[]>;
4949
getSdks(): IFuture<ISdk[]>;
5050
run(applicationPath: string, applicationIdentifier: string): IFuture<void>;
@@ -59,6 +59,10 @@ interface ISimulator {
5959
startSimulator(): IFuture<void>;
6060
}
6161

62+
interface INameGetter {
63+
getSimulatorName(deviceId: string): string;
64+
}
65+
6266
interface IApplication {
6367
guid: string;
6468
appIdentifier: string;

lib/ios-sim.ts

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -66,58 +66,21 @@ Object.defineProperty(global.publicApi, "getInstalledApplications", {
6666
}
6767
});
6868

69-
Object.defineProperty(global.publicApi, "installApplication", {
70-
get: () => {
71-
return (...args: any[]) => {
72-
let simulator = getSimulator().wait();
73-
return simulator.installApplication.apply(simulator, args);
74-
}
75-
}
76-
});
77-
78-
Object.defineProperty(global.publicApi, "uninstallApplication", {
79-
get: () => {
80-
return (...args: any[]) => {
81-
let simulator = getSimulator().wait();
82-
return simulator.uninstallApplication.apply(simulator, args);
83-
}
84-
}
85-
});
86-
87-
Object.defineProperty(global.publicApi, "startApplication", {
88-
get: () => {
89-
return (...args: any[]) => {
90-
let simulator = getSimulator().wait();
91-
return simulator.startApplication.apply(simulator, args);
92-
}
93-
}
94-
});
95-
96-
Object.defineProperty(global.publicApi, "stopApplication", {
97-
get: () => {
98-
return (...args: any[]) => {
99-
let simulator = getSimulator().wait();
100-
return simulator.stopApplication.apply(simulator, args);
101-
}
102-
}
103-
});
104-
105-
Object.defineProperty(global.publicApi, "printDeviceLog", {
106-
get: () => {
107-
return (...args: any[]) => {
108-
let simulator = getSimulator().wait();
109-
return simulator.printDeviceLog.apply(simulator, args);
110-
}
111-
}
112-
});
113-
114-
Object.defineProperty(global.publicApi, "startSimulator", {
115-
get: () => {
116-
return (...args: any[]) => {
117-
let simulator = getSimulator().wait();
118-
return simulator.startSimulator.apply(simulator, args);
69+
["installApplication",
70+
"uninstallApplication",
71+
"startApplication",
72+
"stopApplication",
73+
"printDeviceLog",
74+
"startSimulator",
75+
"getSimulatorName"].forEach(methodName => {
76+
Object.defineProperty(global.publicApi, methodName, {
77+
get: () => {
78+
return (...args: any[]) => {
79+
let simulator: any = getSimulator().wait();
80+
return simulator[methodName].apply(simulator, args);
81+
}
11982
}
120-
}
121-
});
83+
});
84+
})
12285

12386
module.exports = global.publicApi;

lib/iphone-interop-simulator-base.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import * as path from "path";
1111
import * as util from "util";
1212
import * as utils from "./utils";
1313
let $ = require("nodobjc");
14+
import {IPhoneSimulatorNameGetter} from "./iphone-simulator-name-getter";
1415

15-
export class IPhoneInteropSimulatorBase {
16-
constructor(private simulator: IInteropSimulator) { }
16+
export class IPhoneInteropSimulatorBase extends IPhoneSimulatorNameGetter {
17+
constructor(private simulator: IInteropSimulator) {
18+
super();
19+
}
1720

1821
private static FOUNDATION_FRAMEWORK_NAME = "Foundation";
1922
private static APPKIT_FRAMEWORK_NAME = "AppKit";

lib/iphone-simulator-name-getter.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
///<reference path="./.d.ts"/>
2+
"use strict";
3+
import * as options from "./options";
4+
5+
export abstract class IPhoneSimulatorNameGetter implements INameGetter {
6+
private _simulatorName: string;
7+
8+
public defaultDeviceIdentifier: string;
9+
10+
public getSimulatorName(): string {
11+
if (!this._simulatorName) {
12+
this._simulatorName = options.device || this.defaultDeviceIdentifier;
13+
}
14+
15+
return this._simulatorName;
16+
}
17+
}

lib/iphone-simulator-xcode-5.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ var $ = require("nodobjc");
1212
import iPhoneSimulatorBaseLib = require("./iphone-interop-simulator-base");
1313

1414
export class XCode5Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulatorBase implements IInteropSimulator {
15+
public defaultDeviceIdentifier: string;
1516

1617
constructor() {
1718
super(this);
19+
this.defaultDeviceIdentifier = "iPhone"
1820
}
1921

20-
private static DEFAULT_DEVICE_IDENTIFIER = "iPhone";
21-
2222
private static allowedDeviceIdentifiers: IDictionary<string> = {
2323
"iPhone": "iPhone",
2424
"iPhone-Retina-3.5-inch": "iPhone Retina (3.5-inch)",
@@ -90,7 +90,6 @@ export class XCode5Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
9090
}
9191

9292
private get deviceIdentifier(): string {
93-
let identifier = options.device || XCode5Simulator.DEFAULT_DEVICE_IDENTIFIER;
94-
return XCode5Simulator.allowedDeviceIdentifiers[identifier];
93+
return XCode5Simulator.allowedDeviceIdentifiers[this.getSimulatorName()];
9594
}
9695
}

lib/iphone-simulator-xcode-6.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ import iPhoneSimulatorBaseLib = require("./iphone-interop-simulator-base");
1919

2020
export class XCode6Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulatorBase implements IInteropSimulator {
2121

22+
public defaultDeviceIdentifier: string;
23+
2224
private static DEVICE_IDENTIFIER_PREFIX = "com.apple.CoreSimulator.SimDeviceType";
23-
private static DEFAULT_DEVICE_IDENTIFIER = "iPhone-4s";
2425

2526
private cachedDevices: IDevice[];
2627
private simctl: ISimctl;
2728

2829
constructor() {
2930
super(this);
3031

32+
this.defaultDeviceIdentifier = "iPhone-4s";
3133
this.cachedDevices = null;
3234
this.simctl = new Simctl();
3335
}
@@ -155,15 +157,11 @@ export class XCode6Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
155157
return this.execute(action, { canRunMainLoop: false });
156158
}
157159

158-
private get deviceName(): string {
159-
return options.device || XCode6Simulator.DEFAULT_DEVICE_IDENTIFIER;
160-
}
161-
162160
private getDeviceByName(): IDevice {
163161
let devices = this.getDevices().wait();
164-
let device = _.find(devices, (device) => device.name === this.deviceName);
162+
let device = _.find(devices, (device) => device.name === this.getSimulatorName());
165163
if(!device) {
166-
errors.fail("Unable to find device with name ", this.deviceName);
164+
errors.fail("Unable to find device with name ", this.getSimulatorName());
167165
}
168166

169167
return device;

lib/iphone-simulator-xcode-7.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ import { Simctl } from "./simctl";
1111
import util = require("util");
1212
import utils = require("./utils");
1313
import xcode = require("./xcode");
14-
var $ = require("nodobjc");
15-
var osenv = require("osenv");
1614

17-
export class XCode7Simulator implements ISimulator {
15+
import {IPhoneSimulatorNameGetter} from "./iphone-simulator-name-getter";
16+
17+
export class XCode7Simulator extends IPhoneSimulatorNameGetter implements ISimulator {
1818
private static DEVICE_IDENTIFIER_PREFIX = "com.apple.CoreSimulator.SimDeviceType";
19-
private static DEFAULT_DEVICE_NAME = "iPhone 6";
19+
public defaultDeviceIdentifier = "iPhone 6";
2020

2121
private simctl: ISimctl = null;
2222

2323
constructor() {
24+
super();
2425
this.simctl = new Simctl();
2526
}
2627

@@ -123,7 +124,7 @@ export class XCode7Simulator implements ISimulator {
123124
});
124125

125126
if(!result) {
126-
result = _.find(devices, (device: IDevice) => device.name === XCode7Simulator.DEFAULT_DEVICE_NAME);
127+
result = _.find(devices, (device: IDevice) => device.name === this.defaultDeviceIdentifier);
127128
}
128129

129130
if(!result) {

0 commit comments

Comments
 (0)