flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
108 lines • 5.12 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 });
const command_1 = require("../command");
const cli_1 = require("../cli");
const cli_helper_1 = require("../cli-helper");
const flagpole_execution_1 = require("../../flagpole-execution");
const prompts = require("prompts");
const fs = require("fs-extra");
class Rm extends command_1.Command {
constructor() {
super(...arguments);
this.commandString = "rm [type]";
this.description = "remove a suite or environment";
}
action(type) {
return __awaiter(this, void 0, void 0, function* () {
if (type == "env") {
yield removeEnv();
}
else {
yield removeSuite();
}
});
}
}
exports.default = Rm;
function removeEnv() {
return __awaiter(this, void 0, void 0, function* () {
cli_1.Cli.subheader("Remove Environment");
const envs = cli_helper_1.stringArrayToPromptChoices(flagpole_execution_1.FlagpoleExecution.global.config.getEnvironmentNames() || []);
if (envs.length == 0) {
cli_1.Cli.log("", "There are no environments defined in this project.", "").exit(1);
}
const response = yield prompts(cli_helper_1.promptSelect("name", "Which environment do you want to remove?", envs));
flagpole_execution_1.FlagpoleExecution.global.config.removeEnvironment(response.name);
yield flagpole_execution_1.FlagpoleExecution.global.config.save();
return cli_1.Cli.log("Removed environment " + response.name)
.list(["Config file updated"])
.log("")
.exit(0);
});
}
function removeSuite() {
return __awaiter(this, void 0, void 0, function* () {
cli_1.Cli.subheader("Remove Suite");
const suites = cli_helper_1.stringArrayToPromptChoices(flagpole_execution_1.FlagpoleExecution.global.config.getSuiteNames().sort() || []);
if (suites.length == 0) {
return cli_1.Cli.fatalError("There are no suites in this project.");
}
const responses = yield prompts([
cli_helper_1.promptSelect("suite", "Which suite do you want to remove?", suites),
cli_helper_1.promptConfirm("delete", "Do you want to delete the files too?", false),
]);
if (responses.suite) {
cli_1.Cli.log(`Removing ${responses.suite}...`, "");
const suite = flagpole_execution_1.FlagpoleExecution.global.config.suites[responses.suite];
const suiteSourcePath = suite.getSourcePath();
const suiteTestPath = suite.getTestPath();
flagpole_execution_1.FlagpoleExecution.global.config.removeSuite(responses.suite);
yield flagpole_execution_1.FlagpoleExecution.global.config.save();
const thingsWeDid = [
`Removed suite ${responses.suite} from config file`,
];
if (responses.delete) {
try {
if (suiteSourcePath) {
if (fs.existsSync(suiteSourcePath)) {
fs.unlinkSync(suiteSourcePath);
thingsWeDid.push(`Deleted source file: ${suiteSourcePath}`);
}
else {
thingsWeDid.push(`Could not delete source file. Not found at: ${suiteSourcePath}`);
}
}
if (suiteTestPath) {
if (fs.existsSync(suiteTestPath)) {
fs.unlinkSync(suiteTestPath);
thingsWeDid.push(`Deleted test file: ${suiteTestPath}`);
}
else {
thingsWeDid.push(`Could not delete test file. Not found at: ${suiteTestPath}`);
}
}
}
catch (ex) {
thingsWeDid.push(`Error. Failed to delete files: ${ex === null || ex === void 0 ? void 0 : ex.message}`);
}
}
else {
thingsWeDid.push("Did not delete suite file (so you can add it back if you need)");
}
cli_1.Cli.list(thingsWeDid).log("").exit(0);
}
else {
cli_1.Cli.log("No suite selected.").exit(1);
}
});
}
//# sourceMappingURL=rm.js.map
;