UNPKG

4.38 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const cli_helper_1 = require("./cli-helper");
13const cli_1 = require("./cli");
14const prompts = require("prompts");
15const fs = require("fs");
16const canAdd = ["env", "suite"];
17function removeEnv() {
18 return __awaiter(this, void 0, void 0, function* () {
19 cli_helper_1.printHeader();
20 cli_helper_1.printSubheader("Remove Environment");
21 const envs = cli_helper_1.stringArrayToPromptChoices(cli_1.Cli.config.getEnvironmentNames());
22 if (envs.length == 0) {
23 cli_1.Cli.log("");
24 cli_1.Cli.log("There are no environments defined in this project.");
25 cli_1.Cli.log("");
26 cli_1.Cli.exit(1);
27 }
28 const response = yield prompts({
29 type: "select",
30 name: "name",
31 message: "Which environment do you want to remove?",
32 initial: cli_1.Cli.commandArg2 || "",
33 choices: envs,
34 validate: function (input) {
35 return /^[a-z0-9]{1,12}$/i.test(input);
36 }
37 });
38 cli_1.Cli.config.removeEnvironment(response.name);
39 fs.writeFile(cli_1.Cli.config.getConfigPath(), cli_1.Cli.config.toString(), function (err) {
40 if (err) {
41 cli_1.Cli.log("Error removing environment!");
42 cli_1.Cli.log("Failed updating config: " + cli_1.Cli.config.getConfigPath());
43 cli_1.Cli.log("Got Error: " + err);
44 cli_1.Cli.log("");
45 cli_1.Cli.exit(1);
46 }
47 cli_1.Cli.log("Removed environment " + response.name);
48 cli_1.Cli.list(["Config file updated"]);
49 cli_1.Cli.log("");
50 cli_1.Cli.exit(0);
51 });
52 });
53}
54function removeSuite() {
55 return __awaiter(this, void 0, void 0, function* () {
56 cli_helper_1.printHeader();
57 cli_helper_1.printSubheader("Remove Suite");
58 const suites = cli_helper_1.stringArrayToPromptChoices(cli_1.Cli.config.getSuiteNames());
59 if (suites.length == 0) {
60 cli_1.Cli.log("");
61 cli_1.Cli.log("There are no suites in this project.");
62 cli_1.Cli.log("");
63 cli_1.Cli.exit(1);
64 }
65 const response = yield prompts({
66 type: "select",
67 name: "name",
68 message: "Which suite do you want to remove?",
69 choices: suites,
70 initial: cli_1.Cli.commandArg2 || "",
71 validate: function (input) {
72 return /^[a-z0-9]{1,12}$/i.test(input);
73 }
74 });
75 cli_1.Cli.config.removeSuite(response.name);
76 fs.writeFile(cli_1.Cli.config.getConfigPath(), cli_1.Cli.config.toString(), function (err) {
77 if (err) {
78 cli_1.Cli.log("Error removing suite!");
79 cli_1.Cli.log("Failed updating config: " + cli_1.Cli.config.getConfigPath());
80 cli_1.Cli.log("Got Error: " + err);
81 cli_1.Cli.log("");
82 cli_1.Cli.exit(1);
83 }
84 cli_1.Cli.log("Removed suite " + response.name);
85 cli_1.Cli.list([
86 "Config file updated",
87 "Did not delete suite file (so you can add it back if you need)"
88 ]);
89 cli_1.Cli.log("");
90 cli_1.Cli.exit(0);
91 });
92 });
93}
94function rm() {
95 return __awaiter(this, void 0, void 0, function* () {
96 cli_1.Cli.hideBanner = true;
97 if (cli_1.Cli.commandArg == "env") {
98 yield removeEnv();
99 }
100 else {
101 yield removeSuite();
102 }
103 });
104}
105exports.rm = rm;
106//# sourceMappingURL=rm.js.map
\No newline at end of file