@manuth/generator-wsc-package
Version:
A Generator for WoltLab Suite Core Packages.
138 lines • 5.64 kB
JavaScript
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 { join } from "node:path";
import { printNode, SyntaxKind, ts } from "ts-morph";
import { InstructionFileMapping } from "../../../FileMappings/InstructionFileMapping.js";
import { ThemeComponent } from "../Settings/ThemeComponent.js";
/**
* Provides the functionality to generate 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 ThemeInstructionFileMapping extends InstructionFileMapping {
/**
* Initializes a new instance of the {@link ThemeInstructionFileMapping `ThemeInstructionFileMapping<TSettings, TOptions, TComponentOptions>`} class.
*
* @param component
* The component to create an instruction-file for.
*/
constructor(component) {
super(component);
}
/**
* @inheritdoc
*/
get InstructionOptions() {
var _a;
let result = super.InstructionOptions;
let themeObject = this.GetObjectLiteral();
let displayNameObject = this.GetObjectLiteral();
let invariantAccessor = ts.factory.createComputedPropertyName(ts.factory.createIdentifier("InvariantCultureName"));
displayNameObject.addPropertyAssignment({
name: printNode(invariantAccessor),
initializer: printNode(ts.factory.createStringLiteral(this.Component.ComponentOptions.DisplayName))
});
let properties = [
{
name: "Name",
initializer: printNode(ts.factory.createStringLiteral(this.Component.ComponentOptions.Name))
},
{
name: "DisplayName",
initializer: displayNameObject.getFullText()
}
];
if (((_a = this.Component.ComponentOptions.Description) !== null && _a !== void 0 ? _a : "").trim().length > 0) {
let descriptionObject = this.GetObjectLiteral();
descriptionObject.addPropertyAssignment({
name: printNode(invariantAccessor),
initializer: printNode(ts.factory.createStringLiteral(this.Component.ComponentOptions.Description))
});
properties.push({
name: "Description",
initializer: descriptionObject.getFullText()
});
}
if (this.Component.ComponentOptions.Components.includes(ThemeComponent.CustomScss)) {
properties.push({
name: "CustomScssFileName",
initializer: this.GetPathJoin(this.Component.ComponentOptions.CustomScssFileName).getFullText()
});
}
if (this.Component.ComponentOptions.Components.includes(ThemeComponent.ScssOverrides)) {
properties.push({
name: "ScssOverrideFileName",
initializer: this.GetPathJoin(this.Component.ComponentOptions.ScssOverridesFileName).getFullText()
});
}
if (this.Component.ComponentOptions.Components.includes(ThemeComponent.Variables)) {
properties.push({
name: "VariableFileName",
initializer: this.GetPathJoin(this.Component.ComponentOptions.VariableFileName).getFullText()
});
}
themeObject.addPropertyAssignments(properties);
result.addPropertyAssignment({
name: "Theme",
initializer: themeObject.getFullText()
});
return result;
}
/**
* @inheritdoc
*
* @param file
* The {@link SourceFile `SourceFile`} to transform.
*
* @returns
* The transformed file.
*/
Transform(file) {
const _super = Object.create(null, {
Transform: { get: () => super.Transform }
});
return __awaiter(this, void 0, void 0, function* () {
file = yield _super.Transform.call(this, file);
this.ApplyDirname(file);
file.addImportDeclarations([
{
moduleSpecifier: "path",
namedImports: [
"join"
]
},
{
moduleSpecifier: "@manuth/woltlab-compiler",
namedImports: [
"InvariantCultureName"
]
}
]);
return file;
});
}
/**
* Gets an {@link ObjectLiteralExpression `ObjectLiteralExpression`}-node.
*
* @returns
* The newly created {@link ObjectLiteralExpression `ObjectLiteralExpression`}.
*/
GetObjectLiteral() {
return this.WrapNode(ts.factory.createParenthesizedExpression(ts.factory.createObjectLiteralExpression())).getExpressionIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
}
}
//# sourceMappingURL=ThemeInstructionFileMapping.js.map