appcenter-cli
Version:
Command line tool for Visual Studio App Center
92 lines (88 loc) • 4.22 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalabashPreparer = void 0;
const test_cloud_error_1 = require("./test-cloud-error");
const parameters_parser_1 = require("./parameters-parser");
const path = require("path");
const process = require("../../../util/misc/process-helper");
const interaction_1 = require("../../../util/interaction");
const debug = require("debug")("appcenter-cli:commands:test:lib:calabash-preparer");
class CalabashPreparer {
constructor(artifactsDir, projectDir, appPath, testParameters) {
if (!artifactsDir) {
throw new Error("Argument --artifacts-dir is required");
}
if (!projectDir) {
throw new Error("Argument --project-dir is required");
}
if (!appPath) {
throw new Error("Argument --app-path is required");
}
this.artifactsDir = artifactsDir;
this.projectDir = projectDir;
this.appPath = appPath;
this.testParameters = testParameters;
}
prepare() {
return __awaiter(this, void 0, void 0, function* () {
const command = this.getPrepareCommand();
debug(`Executing command ${command}`);
const exitCode = yield process.execAndWait(command, this.outMessage, this.outMessage);
if (exitCode !== 0) {
throw new test_cloud_error_1.TestCloudError(`Cannot prepare Calabash artifacts. Returning exit code ${exitCode}.`, exitCode);
}
return path.join(this.artifactsDir, "manifest.json");
});
}
getPrepareCommand() {
let command = `test-cloud prepare ${this.appPath} --artifacts-dir ${this.artifactsDir}`;
command += ` --workspace "${this.projectDir}"`;
if (this.config) {
command += ` --config "${this.config}"`;
}
if (this.profile) {
command += ` --profile "${this.profile}"`;
}
if (this.skipConfigCheck) {
command += " --skip-config-check";
}
if (this.signInfo) {
command += ` --sign-info "${this.signInfo}"`;
}
if (this.testParameters && this.testParameters.length > 0) {
command += ` --test-parameters ${this.generateTestParameterArgs()}`;
}
return command;
}
generateTestParameterArgs() {
return this.testParameters
.map(parameters_parser_1.parseTestParameter)
.map((p) => `"${p.key}:${p.value}"`)
.join(" ");
}
/*
The Calabash `test-cloud prepare` command uses different argument names than the AooCenter CLI.
We cannot easily change that: the `test-cloud prepare` uses argument names that are consistent with other
`test-cloud` commands, while the `appcenter test run calabash` uses argument names that are consistent with
other AppCenter CLI commands.
As a result, user who uses AppCenter CLI will see misleading error messages, such as:
`The --profile option was set without a --config option.`
However, when user tries again with the --config option, he will see another error message, since the correct name
for AppCenter CLI is `--config-path`.
The easiest way to make the experience better is to translate the messages.
*/
outMessage(line) {
const translatedCalabashMessage = line.replace("--config ", "--config-path ");
interaction_1.out.text(translatedCalabashMessage);
}
}
exports.CalabashPreparer = CalabashPreparer;