@manuth/generator-wsc-package
Version:
A Generator for WoltLab Suite Core Packages.
92 lines • 2.77 kB
JavaScript
import { relative } from "node:path";
import { WoltLabComponent } from "./WoltLabComponent.js";
/**
* Provides a component for generating an instruction-file.
*
* @template TSettings
* The type of the settings of the generator.
*
* @template TOptions
* The type of the options of the generator.
*
* @template TComponentOptions
* The type of the options of the component.
*/
export class InstructionComponent extends WoltLabComponent {
/**
* Initializes a new instance of the {@link InstructionComponent `InstructionComponent<TSettings, TOptions, TComponentOptions>`} class.
*
* @param generator
* The generator of the component.
*/
constructor(generator) {
super(generator);
}
/**
* Gets the name of the instruction-class.
*/
get ClassName() {
return this.GetClassName(this.ComponentOptions);
}
/**
* Gets the name of the instruction-variable to export.
*/
get VariableName() {
return this.GetVariableName(this.ComponentOptions);
}
/**
* Gets the default name of the file to write the instruction to.
*/
get InstructionFileName() {
return this.GetInstructionFileName(this.ComponentOptions);
}
/**
* @inheritdoc
*/
get FileMappings() {
return [
...super.FileMappings,
this.InstructionFileMapping
];
}
/**
* A question for asking for the component-path.
*/
get PathQuestion() {
var _a;
let question = super.PathQuestion;
question.rootDir = {
path: this.Generator.sourcePath(),
allowOutside: false
};
(_a = question.default) !== null && _a !== void 0 ? _a : (question.default = (answers) => {
return relative(this.Generator.sourcePath(), this.GetInstructionFileName(answers));
});
return question;
}
/**
* Gets the name of the instruction-variable to export based on the options provided by the user.
*
* @param options
* The options which have been provided by the user.
*
* @returns
* The name of the instruction-variable to export.
*/
GetVariableName(options) {
return `My${this.GetClassName(options)}`;
}
/**
* Gets the default name of the file to write the instruction to based on the options provided by the user.
*
* @param options
* The options which have been provided by the user.
*
* @returns
* The default name of the file to write the instruction to.
*/
GetInstructionFileName(options) {
return this.Generator.componentPath(`${this.GetVariableName(options)}.ts`);
}
}
//# sourceMappingURL=InstructionComponent.js.map