UNPKG

@manuth/generator-wsc-package

Version:

A Generator for WoltLab Suite Core Packages.

90 lines 3.11 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 { URL } from "node:url"; import { QuestionBase, TSProjectSettingKey } from "@manuth/generator-ts-project"; import { WoltLabSettingKey } from "../../Settings/WoltLabSettingKey.js"; /** * Represents a question for asking for the package-identifier. * * @template TSettings * The type of the generator-settings. * * @template TOptions * The type of the generator-options. */ export class WoltLabIdentifierQuestion extends QuestionBase { constructor() { super(...arguments); /** * @inheritdoc */ this.name = WoltLabSettingKey.Identifier; } /** * @inheritdoc * * @param answers * The answers provided by the user. * * @returns * The message to show to the user. */ Message(answers) { return __awaiter(this, void 0, void 0, function* () { return "Please enter an identifier for your package:"; }); } /** * @inheritdoc * * @param answers * The answers provided by the user. * * @returns * The default value. */ Default(answers) { var _a, _b, _c; return __awaiter(this, void 0, void 0, function* () { let reversedUri; try { reversedUri = (_c = (_b = new URL((_a = answers[WoltLabSettingKey.HomePage]) !== null && _a !== void 0 ? _a : "").hostname) === null || _b === void 0 ? void 0 : _b.split(".").reverse().join(".")) !== null && _c !== void 0 ? _c : ""; } catch (_d) { reversedUri = ""; } if (reversedUri.length === 0) { reversedUri = "com.example"; } return `${reversedUri}.${answers[TSProjectSettingKey.Name]}`; }); } /** * @inheritdoc * * @param input * The answer provided by the user. * * @param answers * The answers provided by the user. * * @returns * The choices the user can choose from. */ Validate(input, answers) { const _super = Object.create(null, { Validate: { get: () => super.Validate } }); return __awaiter(this, void 0, void 0, function* () { return (`${input}`.trim().length > 0) ? _super.Validate.call(this, input, answers) : "The identifier must not be empty!"; }); } } //# sourceMappingURL=WoltLabIdentifierQuestion.js.map