UNPKG

@tobiastengler/create-relay-app

Version:

Easy configuration of Relay for existing projects

58 lines (57 loc) 2 kB
import chalk from "chalk"; import inquirer from "inquirer"; export class ArgumentBase { get cliArg() { var _a; return (_a = this._cliArg) !== null && _a !== void 0 ? _a : "--" + this.name; } set cliArg(value) { this._cliArg = value; } submitWithValue(value) { let val = value; if (val === null || (typeof val === "string" && !val)) { val = chalk.italic("empty"); } else if (typeof value === "boolean") { val = (!!value ? "Yes" : "No"); } console.log(`${chalk.green("?")} ${this.promptMessage} ${chalk.cyan(val)}`); } getInvalidArgError(value, validValues, reason) { let msg = `Received an invalid value for ${this.cliArg}: \"${value}\".`; if (validValues) { const validValueString = validValues instanceof Array ? validValues.join(", ") : typeof validValues === "string" ? validValues : validValues.toString(); msg += " Valid values are: " + validValueString + "."; } else if (reason) { msg += " " + reason; } return new InvalidArgError(msg); } getCliFlags(shorthand, argument) { let flags = ""; if (shorthand) { flags += shorthand + ", "; } flags += this.cliArg; if (argument) { flags += " " + argument; } return flags; } async showInquirerPrompt(options, existingArgs) { const defaultValue = await this.getDefaultValue(existingArgs); const answer = await inquirer.prompt(Object.assign({ name: this.name, message: this.promptMessage, default: defaultValue }, options)); return answer[this.name]; } } export function getNormalizedCliString(input) { return (input === null || input === void 0 ? void 0 : input.toLowerCase().trim()) || ""; } export class InvalidArgError extends Error { }