mobile-cli-lib
Version:
common lib used by different CLI
49 lines (48 loc) • 2.27 kB
JavaScript
"use strict";
var AndroidDebugBridge = (function () {
function AndroidDebugBridge($childProcess, $errors, $logger, $staticConfig, $androidDebugBridgeResultHandler) {
this.$childProcess = $childProcess;
this.$errors = $errors;
this.$logger = $logger;
this.$staticConfig = $staticConfig;
this.$androidDebugBridgeResultHandler = $androidDebugBridgeResultHandler;
}
AndroidDebugBridge.prototype.executeCommand = function (args, options) {
var _this = this;
return (function () {
var event = "close";
var command = _this.composeCommand(args).wait();
var treatErrorsAsWarnings = false;
var childProcessOptions = undefined;
if (options) {
event = options.fromEvent || event;
treatErrorsAsWarnings = options.treatErrorsAsWarnings;
childProcessOptions = options.childProcessOptions;
if (options.returnChildProcess) {
return _this.$childProcess.spawn(command.command, command.args);
}
}
var result = _this.$childProcess.spawnFromEvent(command.command, command.args, event, childProcessOptions, { throwError: false }).wait();
var errors = _this.$androidDebugBridgeResultHandler.checkForErrors(result);
if (errors && errors.length > 0) {
_this.$androidDebugBridgeResultHandler.handleErrors(errors, treatErrorsAsWarnings);
}
return (result.stdout === undefined || result.stdout === null) ? result : result.stdout;
}).future()();
};
AndroidDebugBridge.prototype.composeCommand = function (params, identifier) {
var _this = this;
return (function () {
var command = _this.$staticConfig.getAdbFilePath().wait();
var deviceIdentifier = [];
if (identifier) {
deviceIdentifier = ["-s", ("" + identifier)];
}
var args = deviceIdentifier.concat(params);
return { command: command, args: args };
}).future()();
};
return AndroidDebugBridge;
}());
exports.AndroidDebugBridge = AndroidDebugBridge;
$injector.register("adb", AndroidDebugBridge);