UNPKG

@manuth/generator-wsc-package

Version:

A Generator for WoltLab Suite Core Packages.

214 lines 7.8 kB
import { join } from "node:path"; import { JSONCCreatorMapping, PathPrompt, TSProjectDisplayNameQuestion } from "@manuth/generator-ts-project"; import pascalcase from "pascalcase"; import { InstructionComponent } from "../../../Components/InstructionComponent.js"; import { ThemeInstructionFileMapping } from "../FileMappings/ThemeInstructionFileMapping.js"; import { PackageComponentType } from "../Settings/PackageComponentType.js"; import { ThemeComponent } from "../Settings/ThemeComponent.js"; /** * Provides a component for generating theme-instructions. * * @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 ThemeInstructionComponent extends InstructionComponent { /** * Initializes a new instance of the {@link ThemeInstructionComponent `ThemeInstructionComponent<TSettings, TOptions, TComponentOptions>`} class. * * @param generator * The generator of the component. */ constructor(generator) { super(generator); } /** * @inheritdoc */ get ID() { return PackageComponentType.Theme; } /** * @inheritdoc */ get DisplayName() { return "Theme"; } /** * @inheritdoc */ get FileMappings() { var _a, _b, _c, _d, _e, _f; let result = super.FileMappings; let blankFiles = []; if ((_b = (_a = this.ComponentOptions) === null || _a === void 0 ? void 0 : _a.Components) === null || _b === void 0 ? void 0 : _b.includes(ThemeComponent.CustomScss)) { blankFiles.push({ Destination: this.ComponentOptions.CustomScssFileName }); } if ((_d = (_c = this.ComponentOptions) === null || _c === void 0 ? void 0 : _c.Components) === null || _d === void 0 ? void 0 : _d.includes(ThemeComponent.ScssOverrides)) { blankFiles.push({ Destination: this.ComponentOptions.ScssOverridesFileName }); } for (let blankFileMapping of blankFiles) { blankFileMapping.Processor = (target, generator) => { generator.fs.write(target.Destination, ""); }; } result.push(...blankFiles); if ((_f = (_e = this.ComponentOptions) === null || _e === void 0 ? void 0 : _e.Components) === null || _f === void 0 ? void 0 : _f.includes(ThemeComponent.Variables)) { result.push(new JSONCCreatorMapping(this.Generator, this.ComponentOptions.VariableFileName, {})); } return result; } /** * @inheritdoc */ get InstructionFileMapping() { return new ThemeInstructionFileMapping(this); } /** * Gets a question for asking for the name of the theme. */ get NameQuestion() { return Object.assign(Object.assign({}, new TSProjectDisplayNameQuestion(this.Generator)), { name: "Name", message: "What's the name of the theme?", default: undefined }); } /** * Gets a question for asking for the human-readable name of the theme. */ get DisplayNameQuestion() { return Object.assign(Object.assign({}, this.NameQuestion), { name: "DisplayName", message: "What's the human-readable name of the theme?", default: (answers) => answers.Name }); } /** * Gets a question for asking for a description for the theme. */ get DescriptionQuestion() { return { name: "Description", message: "Please enter a description for your theme." }; } /** * Gets a question for asking for {@link ThemeComponent `ThemeComponent`}s to use. */ get ComponentQuestion() { return { type: "checkbox", name: "Components", message: "What do you wish to include in your theme?", choices: [ { name: "Custom SCSS Code", value: ThemeComponent.CustomScss }, { name: "SCSS Variable Overrides", value: ThemeComponent.ScssOverrides }, { name: "Custom Theme Variables", value: ThemeComponent.Variables } ] }; } /** * Gets a question for asking for the name of the `.scss`-file containing custom code. */ get ScssFileNameQuestion() { return Object.assign(Object.assign({}, this.GetAssetQuestion()), { name: "CustomScssFileName", message: "Where do you want to store the custom scss-code?", when: (answers) => answers.Components.includes(ThemeComponent.CustomScss), default: () => "theme.scss" }); } /** * Gets a question for asking for the name of the `.scss`-file containing variable overrides. */ get OverridesFileNameQuestion() { return Object.assign(Object.assign({}, this.GetAssetQuestion()), { name: "ScssOverridesFileName", message: "Where do you want to store the scss variable overrides?", when: (answers) => answers.Components.includes(ThemeComponent.ScssOverrides), default: () => "overrides.scss" }); } /** * Gets a question for asking for the name of the `.json`-file containing the variables. */ get VariableFileNameQuestion() { return Object.assign(Object.assign({}, this.GetAssetQuestion()), { name: "VariableFileName", message: "Where do you want to store the variables?", when: (answers) => answers.Components.includes(ThemeComponent.Variables), default: () => "variables.json" }); } /** * @inheritdoc */ get ComponentOptionQuestionCollection() { return [ this.NameQuestion, this.DisplayNameQuestion, this.DescriptionQuestion, ...super.ComponentOptionQuestionCollection, this.ComponentQuestion, this.ScssFileNameQuestion, this.OverridesFileNameQuestion, this.VariableFileNameQuestion ]; } /** * @inheritdoc * * @param options * The options which have been provided by the user. * * @returns * The name of the instruction-class. */ GetClassName(options) { return "ThemeInstruction"; } /** * @inheritdoc * * @param options * The options which have been provided by the user. * * @returns * The name of the instruction-variable to export. */ GetVariableName(options) { var _a; if (((_a = options === null || options === void 0 ? void 0 : options.DisplayName) !== null && _a !== void 0 ? _a : "").length > 0) { return `${pascalcase(options.DisplayName)}`; } else { return super.GetVariableName(options); } } /** * Gets the path to the suggested directory to store theme-assets. * * @param path * The path to join to the theme-directory. * * @returns * The name of the directory containing theme-assets. */ GetThemeDirectory(...path) { return join(this.Generator.assetPath("themes"), ...path); } /** * Gets a question for asking for a path to a theme-asset. * * @returns * A question for asking for a path to a theme-asset. */ GetAssetQuestion() { return { type: PathPrompt.TypeName, rootDir: (answers) => { return { path: this.GetThemeDirectory(answers.DisplayName), allowOutside: true }; } }; } } //# sourceMappingURL=ThemeInstructionComponent.js.map