Skip to content
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
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"typescript.tsdk": "./node_modules/typescript/lib",
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/*.js": { "when": "$(basename).ts"},
"**/*.js.map": true
}
}
13 changes: 3 additions & 10 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
module.exports = function(grunt) {
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
ts: {
options: {
target: 'es5',
module: 'commonjs',
sourceMap: true,
declaration: false,
removeComments: false,
noImplicitAny: true
},
options: grunt.file.readJSON("tsconfig.json").compilerOptions,
devlib: {
src: ["lib/**/*.ts"],
reference: "lib/.d.ts"
Expand Down Expand Up @@ -44,7 +37,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-ts");
grunt.loadNpmTasks('grunt-shell');

grunt.registerTask("remove_prepublish_script", function() {
grunt.registerTask("remove_prepublish_script", function () {
var packageJson = grunt.file.readJSON("package.json");
delete packageJson.scripts.prepublish;
grunt.file.write("package.json", JSON.stringify(packageJson, null, " "));
Expand Down
2 changes: 1 addition & 1 deletion bin/ios-sim-portable.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require("../lib/ios-sim.js");
require("../lib/ios-sim-standalone.js");
79 changes: 33 additions & 46 deletions lib/child-process.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,47 @@
///<reference path="./.d.ts"/>
"use strict";

import * as child_process from "child_process";
import * as errors from "./errors";
import Future = require("fibers/future");
import * as util from "util";

export function exec(command: string, opts?: any): IFuture<any> {
var future = new Future<any>();

child_process.exec(command, (error: Error, stdout: NodeBuffer, stderr: NodeBuffer) => {
if(error) {
if (opts && opts.skipError) {
future.return(error);
} else {
future.throw(new Error(`Error ${error.message} while executing ${command}.`));
}
export function execSync(command: string, opts?: any): any {
try {
return child_process.execSync(command, opts);
} catch (err) {
if (opts && opts.skipError) {
return err;
} else {
future.return(stdout ? stdout.toString() : "");
throw (new Error(`Error ${err.message} while executing ${command}.`));
}
});

return future;
}
}

export function spawn(command: string, args: string[], opts?: any): IFuture<string> {
let future = new Future<string>();
let capturedOut = "";
let capturedErr = "";
export function spawn(command: string, args: string[], opts?: any): Promise<string> {
return new Promise<string>((resolve, reject) => {
let capturedOut = "";
let capturedErr = "";

let childProcess = child_process.spawn(command, args);
let childProcess = child_process.spawn(command, args);

if(childProcess.stdout) {
childProcess.stdout.on("data", (data: string) => {
capturedOut += data;
});
}
if (childProcess.stdout) {
childProcess.stdout.on("data", (data: string) => {
capturedOut += data;
});
}

if(childProcess.stderr) {
childProcess.stderr.on("data", (data: string) => {
capturedErr += data;
});
}
if (childProcess.stderr) {
childProcess.stderr.on("data", (data: string) => {
capturedErr += data;
});
}

childProcess.on("close", (arg: any) => {
var exitCode = typeof arg === 'number' ? arg : arg && arg.code;
if(exitCode === 0) {
future.return(capturedOut ? capturedOut.trim() : null);
} else {
if (opts && opts.skipError) {
future.return(capturedErr);
childProcess.on("close", (arg: any) => {
var exitCode = typeof arg === 'number' ? arg : arg && arg.code;
if (exitCode === 0) {
resolve(capturedOut ? capturedOut.trim() : null);
} else {
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)));
if (opts && opts.skipError) {
resolve(capturedErr);
} else {
reject(new Error(`Command ${command} with arguments ${args.join(" ")} failed with exit code ${exitCode}. Error output:\n ${capturedErr}`));
}
}
}
});
});

return future;
}
49 changes: 0 additions & 49 deletions lib/command-executor.js

This file was deleted.

42 changes: 18 additions & 24 deletions lib/command-executor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
///<reference path="./.d.ts"/>
"use strict";

import Future = require("fibers/future");
import fs = require("fs");
import path = require("path");
import util = require("util");
Expand All @@ -12,39 +8,37 @@ import options = require("./options");

export class CommandExecutor implements ICommandExecutor {

public execute(): IFuture<void> {
public execute(): void {
var commandName = this.getCommandName();
var commandArguments = this.getCommandArguments();

return this.executeCore(commandName, commandArguments);
}

private executeCore(commandName: string, commandArguments: string[]): IFuture<void> {
return (() => {
try {
let filePath = path.join(__dirname, "commands", commandName + ".js");
if(fs.existsSync(filePath)) {
var command: ICommand = new (require(filePath).Command)();
if(!command) {
errors.fail("Unable to resolve commandName %s", commandName);
}

command.execute(commandArguments).wait();
private executeCore(commandName: string, commandArguments: string[]): void {
try {
let filePath = path.join(__dirname, "commands", commandName + ".js");
if (fs.existsSync(filePath)) {
var command: ICommand = new (require(filePath).Command)();
if (!command) {
errors.fail("Unable to resolve commandName %s", commandName);
}

} catch(e) {
if(options.debug) {
throw e;
} else {
console.log( "\x1B[31;1m" + e.message + "\x1B[0m");
}
command.execute(commandArguments);
}

} catch (e) {
if (options.debug) {
throw e;
} else {
console.log("\x1B[31;1m" + e.message + "\x1B[0m");
}
}).future<void>()();
}
}

private getCommandArguments(): string[] {
var remaining = options._;
return remaining.length > 1 ? remaining.slice(1): [];
return remaining.length > 1 ? remaining.slice(1) : [];
}

private getCommandName(): string {
Expand Down
14 changes: 0 additions & 14 deletions lib/commands/device-types.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/commands/device-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import iphoneSimulatorLibPath = require("./../iphone-simulator");

export class Command implements ICommand {
public execute(args: string[]): IFuture<void> {
public execute(args: string[]): void {
var iphoneSimulator = new iphoneSimulatorLibPath.iPhoneSimulator();
return iphoneSimulator.printDeviceTypes();
}
Expand Down
32 changes: 0 additions & 32 deletions lib/commands/help.js

This file was deleted.

28 changes: 13 additions & 15 deletions lib/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@ import path = require("path");
import util = require("util");

export class Command implements ICommand {
public execute(args: string[]): IFuture<void> {
return (() => {
var topic = (args[0] || "").toLowerCase();
if (topic === "help") {
topic = "";
}
public execute(args: string[]): void {
var topic = (args[0] || "").toLowerCase();
if (topic === "help") {
topic = "";
}

var helpContent = fs.readFileSync(path.join(__dirname, "../../resources/help.txt")).toString();
var helpContent = fs.readFileSync(path.join(__dirname, "../../resources/help.txt")).toString();

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

private escape(s: string): string {
Expand Down
6 changes: 1 addition & 5 deletions lib/commands/launch.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
///<reference path=".././.d.ts"/>
"use strict";

import Future = require("fibers/future");
import iphoneSimulatorLibPath = require("./../iphone-simulator");

export class Command implements ICommand {
public execute(args: string[]): IFuture<void> {
public execute(args: string[]): void {
var iphoneSimulator = new iphoneSimulatorLibPath.iPhoneSimulator();
return iphoneSimulator.run(args[0], args[1]);
}
Expand Down
14 changes: 0 additions & 14 deletions lib/commands/notify-post.js

This file was deleted.

6 changes: 1 addition & 5 deletions lib/commands/notify-post.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
///<reference path=".././.d.ts"/>
"use strict";

import Future = require("fibers/future");
import iphoneSimulatorLibPath = require("./../iphone-simulator");

export class Command implements ICommand {
public execute(args: string[]): IFuture<void> {
public execute(args: string[]): void {
var iphoneSimulator = new iphoneSimulatorLibPath.iPhoneSimulator();
return iphoneSimulator.sendNotification(args[0]);
}
Expand Down
Loading