@manuth/generator-wsc-package
Version:
A Generator for WoltLab Suite Core Packages.
134 lines • 4.23 kB
JavaScript
import { fileURLToPath } from "node:url";
import { Generator } from "@manuth/extended-yo-generator";
import { QuestionSetPrompt, TSProjectGenerator } from "@manuth/generator-ts-project";
import { dependencyPath } from "dependency-package-path";
import path from "upath";
import { ApplicationPrompt } from "./Components/Inquiry/Prompts/ApplicationPrompt.js";
import { WoltLabIdentifierQuestion } from "./Components/Inquiry/WoltLabIdentifierQuestion.js";
import { WoltLabSettingKey } from "./Settings/WoltLabSettingKey.js";
const { join } = path;
const basePath = dependencyPath("@manuth/generator-ts-project", fileURLToPath(new URL(".", import.meta.url)));
/**
* Represents a generator for WoltLab-components.
*
* @template TSettings
* The type of the generator-settings.
*
* @template TOptions
* The type of the generator-options.
*/
export class WoltLabGenerator extends Generator.ComposeWith(TSProjectGenerator, basePath) {
/**
* Initializes a new instance of the {@link WoltLabGenerator `WoltLabGenerator<TSettings, TOptions>`} class.
*
* @param args
* A set of arguments for the generator.
*
* @param options
* A set of options for the generator.
*/
constructor(args, options) {
super(args, options);
this.env.adapter.promptModule.registerPrompt(ApplicationPrompt.TypeName, ApplicationPrompt);
this.env.adapter.promptModule.registerPrompt(QuestionSetPrompt.TypeName, QuestionSetPrompt);
}
/**
* @inheritdoc
*/
get Questions() {
return [
...super.Questions,
this.AuthorQuestion,
this.HomePageQuestion,
new WoltLabIdentifierQuestion(this)
];
}
/**
* Gets the name of the variable to save the package-metadata to.
*/
get PackageVariableName() {
return `My${"Package"}`;
}
/**
* Gets a question for asking for the author.
*/
get AuthorQuestion() {
return {
name: WoltLabSettingKey.Author,
message: "What's the name of the author?",
default: () => this.user.git.name()
};
}
/**
* Gets a question for asking for the homepage.
*/
get HomePageQuestion() {
return {
name: WoltLabSettingKey.HomePage,
message: "What's the homepage of the author",
default: "https://example.com",
validate: (input) => {
if (!input) {
return true;
}
else {
try {
new URL(input);
return true;
}
catch (exception) {
if (exception instanceof Error) {
return exception.message;
}
else {
return `${exception}`;
}
}
}
}
};
}
/**
* Gets a question for asking for the component-identifier.
*/
get IdentifierQuestion() {
return new WoltLabIdentifierQuestion(this);
}
/**
* Joins the arguments together and returns the resulting path relative to the assets-directory.
*
* @param path
* The path that is to be joined.
*
* @returns
* The path relative to the assets.
*/
assetPath(...path) {
return join("assets", ...path);
}
/**
* Joins the arguments together and returns the resulting path relative to the source-directory.
*
* @param path
* The path that is to be joined.
*
* @returns
* The path relative to the source-directory.
*/
sourcePath(...path) {
return join("src", ...path);
}
/**
* Joins the arguments together and returns the resulting path relative to the component-directory.
*
* @param path
* The path that is to be joined.
*
* @returns
* The path relative to the component-directory.
*/
componentPath(...path) {
return this.sourcePath("Components", ...path);
}
}
//# sourceMappingURL=WoltLabGenerator.js.map