UNPKG

@manuth/woltlab-compiler

Version:

A compiler for generating WoltLab-Package `.tar` Archives and other WoltLab-Package Components

85 lines 3.45 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 fs from "fs-extra"; import { Compiler } from "../Compiler.js"; import { ThemeFileCompiler } from "./ThemeFileCompiler.js"; import { ThemeVariableCompiler } from "./ThemeVariableCompiler.js"; const { copy } = fs; /** * Provides the functionality to compile themes. */ export class ThemeCompiler extends Compiler { /** * Initializes a new instance of the {@link ThemeCompiler `ThemeCompiler`} class. * * @param item * The item to compile. * * @param variableFileName * The name of the variable-file. */ constructor(item, variableFileName) { super(item); /** * The name to save the variables to. */ this.variableFileName = "variables.xml"; if (variableFileName) { this.VariableFileName = variableFileName; } } /** * Gets or sets the filename to save variables to. */ get VariableFileName() { return this.variableFileName; } /** * @inheritdoc */ set VariableFileName(value) { this.variableFileName = value; } /** * @inheritdoc */ Compile() { return __awaiter(this, void 0, void 0, function* () { let variables = new Map(this.Item.Variables); if (this.Item.CustomScss) { variables.set("individualScss", this.Item.CustomScss); } if (this.Item.ScssOverride) { variables.set("overrideScss", this.Item.ScssOverride); } let themeFileCompiler = new ThemeFileCompiler(this.Item, this.VariableFileName); themeFileCompiler.DestinationPath = this.MakeDestinationPath("style.xml"); yield themeFileCompiler.Execute(); if (variables.size > 0) { let variableCompiler = new ThemeVariableCompiler(variables); variableCompiler.DestinationPath = this.MakeDestinationPath(this.VariableFileName); yield variableCompiler.Execute(); } if (this.Item.Thumbnail) { yield copy(this.Item.Thumbnail.Source, this.MakeDestinationPath(this.Item.Thumbnail.FileName)); } if (this.Item.HighResThumbnail) { yield copy(this.Item.HighResThumbnail.Source, this.MakeDestinationPath(this.Item.HighResThumbnail.FileName)); } if (this.Item.CoverPhoto) { yield copy(this.Item.CoverPhoto.Source, this.MakeDestinationPath(this.Item.CoverPhoto.FileName)); } if (this.Item.Images) { yield this.Compress(this.Item.Images.Source, this.MakeDestinationPath(this.Item.Images.FileName)); } }); } } //# sourceMappingURL=ThemeCompiler.js.map