UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

106 lines 4.38 kB
"use strict"; 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 cli_helper_1 = require("./cli-helper"); const cli_1 = require("./cli"); const prompts = require("prompts"); const fs = require("fs"); const canAdd = ["env", "suite"]; function removeEnv() { return __awaiter(this, void 0, void 0, function* () { cli_helper_1.printHeader(); cli_helper_1.printSubheader("Remove Environment"); const envs = cli_helper_1.stringArrayToPromptChoices(cli_1.Cli.config.getEnvironmentNames()); if (envs.length == 0) { cli_1.Cli.log(""); cli_1.Cli.log("There are no environments defined in this project."); cli_1.Cli.log(""); cli_1.Cli.exit(1); } const response = yield prompts({ type: "select", name: "name", message: "Which environment do you want to remove?", initial: cli_1.Cli.commandArg2 || "", choices: envs, validate: function (input) { return /^[a-z0-9]{1,12}$/i.test(input); } }); cli_1.Cli.config.removeEnvironment(response.name); fs.writeFile(cli_1.Cli.config.getConfigPath(), cli_1.Cli.config.toString(), function (err) { if (err) { cli_1.Cli.log("Error removing environment!"); cli_1.Cli.log("Failed updating config: " + cli_1.Cli.config.getConfigPath()); cli_1.Cli.log("Got Error: " + err); cli_1.Cli.log(""); cli_1.Cli.exit(1); } cli_1.Cli.log("Removed environment " + response.name); cli_1.Cli.list(["Config file updated"]); cli_1.Cli.log(""); cli_1.Cli.exit(0); }); }); } function removeSuite() { return __awaiter(this, void 0, void 0, function* () { cli_helper_1.printHeader(); cli_helper_1.printSubheader("Remove Suite"); const suites = cli_helper_1.stringArrayToPromptChoices(cli_1.Cli.config.getSuiteNames()); if (suites.length == 0) { cli_1.Cli.log(""); cli_1.Cli.log("There are no suites in this project."); cli_1.Cli.log(""); cli_1.Cli.exit(1); } const response = yield prompts({ type: "select", name: "name", message: "Which suite do you want to remove?", choices: suites, initial: cli_1.Cli.commandArg2 || "", validate: function (input) { return /^[a-z0-9]{1,12}$/i.test(input); } }); cli_1.Cli.config.removeSuite(response.name); fs.writeFile(cli_1.Cli.config.getConfigPath(), cli_1.Cli.config.toString(), function (err) { if (err) { cli_1.Cli.log("Error removing suite!"); cli_1.Cli.log("Failed updating config: " + cli_1.Cli.config.getConfigPath()); cli_1.Cli.log("Got Error: " + err); cli_1.Cli.log(""); cli_1.Cli.exit(1); } cli_1.Cli.log("Removed suite " + response.name); cli_1.Cli.list([ "Config file updated", "Did not delete suite file (so you can add it back if you need)" ]); cli_1.Cli.log(""); cli_1.Cli.exit(0); }); }); } function rm() { return __awaiter(this, void 0, void 0, function* () { cli_1.Cli.hideBanner = true; if (cli_1.Cli.commandArg == "env") { yield removeEnv(); } else { yield removeSuite(); } }); } exports.rm = rm; //# sourceMappingURL=rm.js.map