@hkvstore/taco-cli
Version:
taco-cli is a command-line interface for rapid Apache Cordova development (forked from Microsoft taco-cli)
165 lines (163 loc) • 8.5 kB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
/// <reference path="../../typings/tacoUtils.d.ts" />
/// <reference path="../../typings/node.d.ts" />
/// <reference path="../../typings/nopt.d.ts" />
;
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var path = require("path");
var Q = require("q");
var buildTelemetryHelper = require("./utils/buildTelemetryHelper");
var RemoteBuildSettings = require("./remoteBuild/buildSettings");
var PlatformHelper = require("./utils/platformHelper");
var RemoteBuildClientHelper = require("./remoteBuild/remoteBuildClientHelper");
var resources = require("../resources/resourceManager");
var Settings = require("./utils/settings");
var TacoErrorCodes = require("./tacoErrorCodes");
var errorHelper = require("./tacoErrorHelper");
var tacoUtility = require("taco-utils");
var CordovaWrapper = tacoUtility.CordovaWrapper;
var commands = tacoUtility.Commands;
var logger = tacoUtility.Logger;
/**
* Emulate
*
* handles "taco emulate"
*/
var Emulate = (function (_super) {
__extends(Emulate, _super);
function Emulate() {
_super.apply(this, arguments);
this.name = "run";
}
Emulate.generateTelemetryProperties = function (telemetryProperties, commandData) {
return buildTelemetryHelper.addCommandLineBasedPropertiesForBuildAndRun(telemetryProperties, Emulate.KNOWN_OPTIONS, commandData);
};
Emulate.runRemotePlatform = function (platform, commandData, telemetryProperties) {
return Q.all([Settings.loadSettings(), CordovaWrapper.getCordovaVersion()]).spread(function (settings, cordovaVersion) {
var configuration = commandData.options["release"] ? "release" : "debug";
var buildTarget = commandData.options["target"] || "";
var language = settings.language || "en";
var remoteConfig = settings.remotePlatforms && settings.remotePlatforms[platform];
if (!remoteConfig) {
throw errorHelper.get(TacoErrorCodes.CommandRemotePlatformNotKnown, platform);
}
// DeviceSync/LiveReload not compatible with remote
var deviceSync = commandData.options["livereload"] || commandData.options["devicesync"];
if (deviceSync) {
throw errorHelper.get(TacoErrorCodes.ErrorIncompatibleOptions, "--livereload/--devicesync", "--remote");
}
var buildInfoPath = path.resolve(".", "remote", platform, configuration, "buildInfo.json");
var buildInfoPromise;
var buildSettings = new RemoteBuildSettings({
projectSourceDir: path.resolve("."),
buildServerInfo: remoteConfig,
buildCommand: "build",
platform: platform,
configuration: configuration,
buildTarget: buildTarget,
language: language,
cordovaVersion: cordovaVersion
});
// Find the build that we are supposed to run
if (commandData.options["nobuild"]) {
buildInfoPromise = RemoteBuildClientHelper.checkForBuildOnServer(buildSettings, buildInfoPath).then(function (buildInfo) {
if (!buildInfo) {
// No info for the remote build: User must build first
var buildCommandToRun = "taco build" + ([commandData.options["remote"] ? " --remote" : ""].concat(commandData.remain).join(" "));
throw errorHelper.get(TacoErrorCodes.NoRemoteBuildIdFound, buildCommandToRun);
}
else {
return buildInfo;
}
});
}
else {
// Always do a rebuild, but incrementally if possible.
buildInfoPromise = RemoteBuildClientHelper.build(buildSettings, telemetryProperties);
}
return buildInfoPromise.then(function (buildInfo) {
return RemoteBuildClientHelper.emulate(buildInfo, remoteConfig, buildTarget);
}).then(function (buildInfo) {
logger.log(resources.getString("CommandRunRemoteEmulatorSuccess"));
return buildInfo;
}).then(function (buildInfo) {
if (commandData.options["debuginfo"]) {
// enable debugging and report connection information
return RemoteBuildClientHelper.debug(buildInfo, remoteConfig)
.then(function (debugBuildInfo) {
if (debugBuildInfo["webDebugProxyPort"]) {
logger.log(JSON.stringify({ webDebugProxyPort: debugBuildInfo["webDebugProxyPort"] }));
}
return debugBuildInfo;
});
}
else {
return Q(buildInfo);
}
});
});
};
Emulate.prototype.runCommand = function () {
var commandData = this.data;
var telemetryProperties = {};
var self = this;
return Q.all([PlatformHelper.determinePlatform(commandData), Settings.loadSettingsOrReturnEmpty()])
.spread(function (platforms, settings) {
buildTelemetryHelper.storePlatforms(telemetryProperties, "actuallyBuilt", platforms, settings);
return PlatformHelper.operateOnPlatforms(platforms, function (localPlatforms) { return self.runLocalEmulate(localPlatforms); }, function (remotePlatform) { return Emulate.runRemotePlatform(remotePlatform, commandData, telemetryProperties); });
}).then(function () { return Emulate.generateTelemetryProperties(telemetryProperties, commandData); });
};
Emulate.prototype.parseArgs = function (args) {
var parsedOptions = tacoUtility.ArgsHelper.parseArguments(Emulate.KNOWN_OPTIONS, Emulate.SHORT_HANDS, args, 0);
// Raise errors for invalid command line parameters
if (parsedOptions.options["remote"] && parsedOptions.options["local"]) {
throw errorHelper.get(TacoErrorCodes.ErrorIncompatibleOptions, "--remote", "--local");
}
if (parsedOptions.options["device"]) {
throw errorHelper.get(TacoErrorCodes.ErrorIncompatibleOptions, "--device", "--emulate");
}
if (parsedOptions.options["debug"] && parsedOptions.options["release"]) {
throw errorHelper.get(TacoErrorCodes.ErrorIncompatibleOptions, "--debug", "--release");
}
if (parsedOptions.options["livereload"] && parsedOptions.options["remote"]) {
throw errorHelper.get(TacoErrorCodes.ErrorIncompatibleOptions, "--livereload", "--remote");
}
if (parsedOptions.options["devicesync"] && parsedOptions.options["remote"]) {
throw errorHelper.get(TacoErrorCodes.ErrorIncompatibleOptions, "--devicesync", "--remote");
}
if (parsedOptions.options["devicesync"] && parsedOptions.options["livereload"]) {
throw errorHelper.get(TacoErrorCodes.ErrorIncompatibleOptions, "--devicesync", "--livereload");
}
return parsedOptions;
};
Emulate.prototype.runLocalEmulate = function (localPlatforms) {
var self = this;
if (this.data.options["livereload"] || this.data.options["devicesync"]) {
// intentionally delay-requiring it since liveReload fetches whole bunch of stuff
var liveReload = require("./liveReload");
return liveReload.hookLiveReload(this.data.options, localPlatforms)
.then(function () { return CordovaWrapper.emulate(self.data, localPlatforms); });
}
return CordovaWrapper.emulate(this.data, localPlatforms);
};
Emulate.KNOWN_OPTIONS = {
local: Boolean,
remote: Boolean,
debuginfo: Boolean,
nobuild: Boolean,
device: Boolean,
target: String,
// Are these only for when we build as part of running?
debug: Boolean,
release: Boolean
};
Emulate.SHORT_HANDS = {};
return Emulate;
}(commands.TacoCommandBase));
module.exports = Emulate;
//# sourceMappingURL=emulate.js.map