Skip to content

Commit fb6df7c

Browse files
Fatme HavaluovaFatme Havaluova
authored andcommitted
Expose sdks command
1 parent 980ab2c commit fb6df7c

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

lib/commands/sdks.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
///<reference path=".././.d.ts"/>
2+
"use strict";
3+
import iphoneSimulatorLibPath = require("./../iphone-simulator");
4+
5+
export class Command implements ICommand {
6+
public execute(args: string[]): IFuture<void> {
7+
var iphoneSimulator = new iphoneSimulatorLibPath.iPhoneSimulator();
8+
return iphoneSimulator.printSDKS();
9+
}
10+
}

lib/declarations.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
interface IiPhoneSimulator {
55
run(appName: string): IFuture<void>;
6-
printDeviceTypes(): void;
6+
printDeviceTypes(): IFuture<void>;
7+
printSDKS(): IFuture<void>;
78
}
89

910
interface ICommand {
@@ -32,4 +33,11 @@ interface ISimulator {
3233
interface IExecuteOptions {
3334
canRunMainLoop: boolean;
3435
appPath?: string;
36+
}
37+
38+
interface ISdk {
39+
displayName: string;
40+
version: string;
41+
rootPath: string;
42+
sdkInfo(): string;
3543
}

lib/iphone-simulator.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import child_process = require("child_process");
55
import fs = require("fs");
66
import Future = require("fibers/future");
7+
import os = require("os");
78
import path = require("path");
89
import util = require("util");
910

@@ -35,7 +36,6 @@ export class iPhoneSimulator implements IiPhoneSimulator {
3536
}
3637

3738
public printDeviceTypes(): IFuture<void> {
38-
3939
var action = () => {
4040
var simulator = this.createSimulator();
4141
_.each(simulator.validDeviceIdentifiers, (identifier: any) => console.log(identifier));
@@ -44,6 +44,30 @@ export class iPhoneSimulator implements IiPhoneSimulator {
4444
return this.execute(action, { canRunMainLoop: false });
4545
}
4646

47+
public printSDKS(): IFuture<void> {
48+
var action = () => {
49+
var systemRootClass = this.getClassByName("DTiPhoneSimulatorSystemRoot");
50+
var roots = systemRootClass("knownRoots");
51+
var count = roots("count");
52+
53+
var sdks: ISdk[] = [];
54+
for(var index=0; index < count; index++) {
55+
var root = roots("objectAtIndex", index);
56+
57+
var displayName = root("sdkDisplayName").toString();
58+
var version = root("sdkVersion").toString();
59+
var rootPath = root("sdkRootPath").toString();
60+
61+
sdks.push(new Sdk(displayName, version, rootPath));
62+
}
63+
64+
sdks = _.sortBy(sdks, (sdk: ISdk) => sdk.version);
65+
_.each(sdks, (sdk: ISdk) => console.log(sdk.sdkInfo() + os.EOL));
66+
};
67+
68+
return this.execute(action, { canRunMainLoop: false });
69+
}
70+
4771
private execute(action: (appPath?: string) => any, opts: IExecuteOptions): IFuture<void> {
4872
return (() => {
4973
$.importFramework(iPhoneSimulator.FOUNDATION_FRAMEWORK_NAME);
@@ -207,4 +231,16 @@ export class iPhoneSimulator implements IiPhoneSimulator {
207231

208232
return simulator;
209233
}
234+
}
235+
236+
class Sdk implements ISdk {
237+
constructor(public displayName: string,
238+
public version: string,
239+
public rootPath: string) { }
240+
241+
public sdkInfo(): string {
242+
return [util.format(" Display Name: %s", this.displayName),
243+
util.format(" Version: %s", this.version),
244+
util.format(" Root path: %s", this.rootPath)].join(os.EOL);
245+
}
210246
}

0 commit comments

Comments
 (0)