Skip to content

Commit 10893ba

Browse files
Remove fibers
* Remove fibers * Use sync API everywhere * Use forked version of bplist-parser in order to use sync call. * Remove support for Xcode 6 * Update node.d.ts * Remove NodObjC dependency * Update sleep function
1 parent 6ad4678 commit 10893ba

23 files changed

+3986
-1880
lines changed

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"typescript.tsdk": "./node_modules/typescript/lib"
2+
"typescript.tsdk": "./node_modules/typescript/lib",
3+
"files.exclude": {
4+
"**/.git": true,
5+
"**/.DS_Store": true,
6+
"**/*.js": { "when": "$(basename).ts"},
7+
"**/*.js.map": true
8+
}
39
}

lib/child-process.ts

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,47 @@
1-
///<reference path="./.d.ts"/>
2-
"use strict";
3-
41
import * as child_process from "child_process";
5-
import * as errors from "./errors";
6-
import Future = require("fibers/future");
7-
import * as util from "util";
8-
9-
export function exec(command: string, opts?: any): IFuture<any> {
10-
var future = new Future<any>();
112

12-
child_process.exec(command, (error: Error, stdout: NodeBuffer, stderr: NodeBuffer) => {
13-
if(error) {
14-
if (opts && opts.skipError) {
15-
future.return(error);
16-
} else {
17-
future.throw(new Error(`Error ${error.message} while executing ${command}.`));
18-
}
3+
export function execSync(command: string, opts?: any): any {
4+
try {
5+
return child_process.execSync(command, opts);
6+
} catch (err) {
7+
if (opts && opts.skipError) {
8+
return err;
199
} else {
20-
future.return(stdout ? stdout.toString() : "");
10+
throw (new Error(`Error ${err.message} while executing ${command}.`));
2111
}
22-
});
23-
24-
return future;
12+
}
2513
}
2614

27-
export function spawn(command: string, args: string[], opts?: any): IFuture<string> {
28-
let future = new Future<string>();
29-
let capturedOut = "";
30-
let capturedErr = "";
15+
export function spawn(command: string, args: string[], opts?: any): Promise<string> {
16+
return new Promise<string>((resolve, reject) => {
17+
let capturedOut = "";
18+
let capturedErr = "";
3119

32-
let childProcess = child_process.spawn(command, args);
20+
let childProcess = child_process.spawn(command, args);
3321

34-
if(childProcess.stdout) {
35-
childProcess.stdout.on("data", (data: string) => {
36-
capturedOut += data;
37-
});
38-
}
22+
if (childProcess.stdout) {
23+
childProcess.stdout.on("data", (data: string) => {
24+
capturedOut += data;
25+
});
26+
}
3927

40-
if(childProcess.stderr) {
41-
childProcess.stderr.on("data", (data: string) => {
42-
capturedErr += data;
43-
});
44-
}
28+
if (childProcess.stderr) {
29+
childProcess.stderr.on("data", (data: string) => {
30+
capturedErr += data;
31+
});
32+
}
4533

46-
childProcess.on("close", (arg: any) => {
47-
var exitCode = typeof arg === 'number' ? arg : arg && arg.code;
48-
if(exitCode === 0) {
49-
future.return(capturedOut ? capturedOut.trim() : null);
50-
} else {
51-
if (opts && opts.skipError) {
52-
future.return(capturedErr);
34+
childProcess.on("close", (arg: any) => {
35+
var exitCode = typeof arg === 'number' ? arg : arg && arg.code;
36+
if (exitCode === 0) {
37+
resolve(capturedOut ? capturedOut.trim() : null);
5338
} else {
54-
future.throw(new Error(util.format("Command %s with arguments %s failed with exit code %s. Error output:\n %s", command, args.join(" "), exitCode, capturedErr)));
39+
if (opts && opts.skipError) {
40+
resolve(capturedErr);
41+
} else {
42+
reject(new Error(`Command ${command} with arguments ${args.join(" ")} failed with exit code ${exitCode}. Error output:\n ${capturedErr}`));
43+
}
5544
}
56-
}
45+
});
5746
});
58-
59-
return future;
6047
}

lib/command-executor.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
///<reference path="./.d.ts"/>
2-
"use strict";
3-
4-
import Future = require("fibers/future");
51
import fs = require("fs");
62
import path = require("path");
73
import util = require("util");
@@ -12,39 +8,37 @@ import options = require("./options");
128

139
export class CommandExecutor implements ICommandExecutor {
1410

15-
public execute(): IFuture<void> {
11+
public execute(): void {
1612
var commandName = this.getCommandName();
1713
var commandArguments = this.getCommandArguments();
1814

1915
return this.executeCore(commandName, commandArguments);
2016
}
2117

22-
private executeCore(commandName: string, commandArguments: string[]): IFuture<void> {
23-
return (() => {
24-
try {
25-
let filePath = path.join(__dirname, "commands", commandName + ".js");
26-
if(fs.existsSync(filePath)) {
27-
var command: ICommand = new (require(filePath).Command)();
28-
if(!command) {
29-
errors.fail("Unable to resolve commandName %s", commandName);
30-
}
31-
32-
command.execute(commandArguments).wait();
18+
private executeCore(commandName: string, commandArguments: string[]): void {
19+
try {
20+
let filePath = path.join(__dirname, "commands", commandName + ".js");
21+
if (fs.existsSync(filePath)) {
22+
var command: ICommand = new (require(filePath).Command)();
23+
if (!command) {
24+
errors.fail("Unable to resolve commandName %s", commandName);
3325
}
3426

35-
} catch(e) {
36-
if(options.debug) {
37-
throw e;
38-
} else {
39-
console.log( "\x1B[31;1m" + e.message + "\x1B[0m");
40-
}
27+
command.execute(commandArguments);
28+
}
29+
30+
} catch (e) {
31+
if (options.debug) {
32+
throw e;
33+
} else {
34+
console.log("\x1B[31;1m" + e.message + "\x1B[0m");
4135
}
42-
}).future<void>()();
36+
}
4337
}
4438

4539
private getCommandArguments(): string[] {
4640
var remaining = options._;
47-
return remaining.length > 1 ? remaining.slice(1): [];
41+
return remaining.length > 1 ? remaining.slice(1) : [];
4842
}
4943

5044
private getCommandName(): string {

lib/commands/device-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import iphoneSimulatorLibPath = require("./../iphone-simulator");
44

55
export class Command implements ICommand {
6-
public execute(args: string[]): IFuture<void> {
6+
public execute(args: string[]): void {
77
var iphoneSimulator = new iphoneSimulatorLibPath.iPhoneSimulator();
88
return iphoneSimulator.printDeviceTypes();
99
}

lib/commands/help.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ import path = require("path");
66
import util = require("util");
77

88
export class Command implements ICommand {
9-
public execute(args: string[]): IFuture<void> {
10-
return (() => {
11-
var topic = (args[0] || "").toLowerCase();
12-
if (topic === "help") {
13-
topic = "";
14-
}
9+
public execute(args: string[]): void {
10+
var topic = (args[0] || "").toLowerCase();
11+
if (topic === "help") {
12+
topic = "";
13+
}
1514

16-
var helpContent = fs.readFileSync(path.join(__dirname, "../../resources/help.txt")).toString();
15+
var helpContent = fs.readFileSync(path.join(__dirname, "../../resources/help.txt")).toString();
1716

18-
var pattern = util.format("--\\[%s\\]--((.|[\\r\\n])+?)--\\[/\\]--", this.escape(topic));
19-
var regex = new RegExp(pattern);
20-
var match = regex.exec(helpContent);
21-
if (match) {
22-
var helpText = match[1].trim();
23-
console.log(helpText);
24-
}
25-
}).future<void>()();
17+
var pattern = util.format("--\\[%s\\]--((.|[\\r\\n])+?)--\\[/\\]--", this.escape(topic));
18+
var regex = new RegExp(pattern);
19+
var match = regex.exec(helpContent);
20+
if (match) {
21+
var helpText = match[1].trim();
22+
console.log(helpText);
23+
}
2624
}
2725

2826
private escape(s: string): string {

lib/commands/launch.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
///<reference path=".././.d.ts"/>
2-
"use strict";
3-
4-
import Future = require("fibers/future");
51
import iphoneSimulatorLibPath = require("./../iphone-simulator");
62

73
export class Command implements ICommand {
8-
public execute(args: string[]): IFuture<void> {
4+
public execute(args: string[]): void {
95
var iphoneSimulator = new iphoneSimulatorLibPath.iPhoneSimulator();
106
return iphoneSimulator.run(args[0], args[1]);
117
}

lib/commands/notify-post.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
///<reference path=".././.d.ts"/>
2-
"use strict";
3-
4-
import Future = require("fibers/future");
51
import iphoneSimulatorLibPath = require("./../iphone-simulator");
62

73
export class Command implements ICommand {
8-
public execute(args: string[]): IFuture<void> {
4+
public execute(args: string[]): void {
95
var iphoneSimulator = new iphoneSimulatorLibPath.iPhoneSimulator();
106
return iphoneSimulator.sendNotification(args[0]);
117
}

lib/commands/sdks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import iphoneSimulatorLibPath = require("./../iphone-simulator");
44

55
export class Command implements ICommand {
6-
public execute(args: string[]): IFuture<void> {
6+
public execute(args: string[]): void {
77
var iphoneSimulator = new iphoneSimulatorLibPath.iPhoneSimulator();
88
return iphoneSimulator.printSDKS();
99
}

lib/declarations.ts

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
"use strict";
33

44
interface IiPhoneSimulator {
5-
run(applicationPath: string, applicationIdentifier: string): IFuture<void>;
6-
printDeviceTypes(): IFuture<void>;
7-
printSDKS(): IFuture<void>;
8-
sendNotification(notification: string): IFuture<void>;
9-
createSimulator(): IFuture<ISimulator>;
5+
run(applicationPath: string, applicationIdentifier: string): void;
6+
printDeviceTypes(): void;
7+
printSDKS(): void;
8+
sendNotification(notification: string): void;
9+
createSimulator(): ISimulator;
1010
}
1111

1212
interface ICommand {
13-
execute(args: string[]): IFuture<void>;
13+
execute(args: string[]): void;
1414
}
1515

1616
interface ICommandExecutor {
17-
execute(): IFuture<void>;
17+
execute(): void;
1818
}
1919

2020
interface IDevice {
@@ -27,37 +27,32 @@ interface IDevice {
2727
}
2828

2929
interface ISimctl {
30-
launch(deviceId: string, applicationIdentifier: string): IFuture<string>;
31-
install(deviceId: string, applicationPath: string): IFuture<void>;
32-
uninstall(deviceId: string, applicationIdentifier: string, opts?: any): IFuture<void>;
33-
notifyPost(deviceId: string, notification: string): IFuture<void>;
34-
getDevices(): IFuture<IDevice[]>;
35-
getAppContainer(deviceId: string, applicationIdentifier: string): IFuture<string>;
30+
launch(deviceId: string, applicationIdentifier: string): string;
31+
install(deviceId: string, applicationPath: string): void;
32+
uninstall(deviceId: string, applicationIdentifier: string, opts?: any): void;
33+
notifyPost(deviceId: string, notification: string): void;
34+
getDevices(): IDevice[];
35+
getAppContainer(deviceId: string, applicationIdentifier: string): string;
3636
}
3737

3838
interface IDictionary<T> {
3939
[key: string]: T;
4040
}
4141

42-
interface IInteropSimulator extends INameGetter {
43-
getDevices(): IFuture<IDevice[]>;
44-
setSimulatedDevice(config: any): void;
45-
}
46-
4742
interface ISimulator extends INameGetter {
48-
getDevices(): IFuture<IDevice[]>;
49-
getSdks(): IFuture<ISdk[]>;
50-
run(applicationPath: string, applicationIdentifier: string): IFuture<void>;
51-
sendNotification(notification: string): IFuture<void>;
52-
getApplicationPath(deviceId: string, applicationIdentifier: string): IFuture<string>;
53-
getInstalledApplications(deviceId: string): IFuture<IApplication[]>;
54-
installApplication(deviceId: string, applicationPath: string): IFuture<void>;
55-
uninstallApplication(deviceId: string, appIdentifier: string): IFuture<void>;
56-
startApplication(deviceId: string, appIdentifier: string): IFuture<string>;
57-
stopApplication(deviceId: string, appIdentifier: string): IFuture<string>;
43+
getDevices(): IDevice[];
44+
getSdks(): ISdk[];
45+
run(applicationPath: string, applicationIdentifier: string): void;
46+
sendNotification(notification: string): void;
47+
getApplicationPath(deviceId: string, applicationIdentifier: string): string;
48+
getInstalledApplications(deviceId: string): IApplication[];
49+
installApplication(deviceId: string, applicationPath: string): void;
50+
uninstallApplication(deviceId: string, appIdentifier: string): void;
51+
startApplication(deviceId: string, appIdentifier: string): string;
52+
stopApplication(deviceId: string, appIdentifier: string): string;
5853
printDeviceLog(deviceId: string, launchResult?: string): any;
5954
getDeviceLogProcess(deviceId: string): any;
60-
startSimulator(): IFuture<void>;
55+
startSimulator(): void;
6156
}
6257

6358
interface INameGetter {
@@ -79,7 +74,7 @@ interface IExecuteOptions {
7974
interface ISdk {
8075
displayName: string;
8176
version: string;
82-
rootPath: string;
77+
rootPath?: string;
8378
}
8479

8580
interface IXcodeVersionData {

lib/definitions/NodObjC.d.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)