UNPKG

@manuth/generator-wsc-package

Version:

A Generator for WoltLab Suite Core Packages.

125 lines 4.7 kB
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()); }); }; import { NestedPrompt } from "@manuth/generator-ts-project"; import inquirer from "inquirer"; /** * Provides a prompt for asking for a WoltLab-application. * * @template T * The type of the prompt-options. */ export class ApplicationPrompt extends NestedPrompt { /** * Initializes a new instance of the {@link ApplicationPrompt `ApplicationPrompt<T>`} class. * * @param question * The options for the prompt. * * @param readLine * An object for reading from and writing to the console. * * @param answers * The answer-object. */ constructor(question, readLine, answers) { super(Object.assign({ validate: () => true, filter: (value) => value, when: () => true }, question), readLine, answers); } /** * Gets the applications which are listed as suggestions. */ get SuggestedApplications() { return [ { ID: "wbb", DisplayName: "WoltLab Burning Board" }, { ID: "gallery", DisplayName: "WoltLab Gallery" }, { ID: "filebase", DisplayName: "WoltLab FileBase" } ]; } /** * Gets the default application. */ get DefaultApplication() { return { ID: "wcf", DisplayName: "WoltLab Suite Core" }; } /** * @inheritdoc * * @returns * The value to save to the answer-hash. */ Prompt() { var _a, _b, _c, _d; return __awaiter(this, void 0, void 0, function* () { let suggestions = null; let apps = []; let choices; let questions = []; if (this.opt.suggestions) { if (typeof this.opt.suggestions === "function") { suggestions = yield this.opt.suggestions(this.answers); } else { suggestions = yield this.opt.suggestions; } } if ((_a = suggestions === null || suggestions === void 0 ? void 0 : suggestions.showBuiltinSuggestions) !== null && _a !== void 0 ? _a : true) { apps.push(this.DefaultApplication, ...this.SuggestedApplications); } apps.push(...(_b = suggestions === null || suggestions === void 0 ? void 0 : suggestions.apps) !== null && _b !== void 0 ? _b : []); choices = apps.map((app) => { return { name: app.DisplayName, value: app.ID }; }); if (choices.length > 0) { questions.push({ type: "list", name: "application", message: this.opt.message, default: ((_c = this.opt.default) !== null && _c !== void 0 ? _c : suggestions === null || suggestions === void 0 ? void 0 : suggestions.showBuiltinSuggestions) ? this.DefaultApplication.ID : undefined, choices: [ ...choices, { name: "Custom", value: null } ] }); } questions.push({ name: "customApplication", message: "Please specify the identifier of the custom application.", default: this.opt.default, when: (answers) => answers.application === null || answers.application === undefined }); let result = yield inquirer.prompt(questions); return (_d = result.application) !== null && _d !== void 0 ? _d : result.customApplication; }); } } /** * Gets the name of this prompt-type. */ ApplicationPrompt.TypeName = "wcf-application"; //# sourceMappingURL=ApplicationPrompt.js.map