woltlab-compiler
Version:
A compiler for WoltLab-Package Archives and WoltLab-Package Components
109 lines • 4.49 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("util");
const XMLEditor_1 = require("../../Serialization/XMLEditor");
const WoltLabXMLCompiler_1 = require("../WoltLabXMLCompiler");
/**
* Provides the functionality to compile theme-files.
*/
class ThemeFileCompiler extends WoltLabXMLCompiler_1.WoltLabXMLCompiler {
/**
* Initializes a new instance of the `ThemeFileCompiler<T>` class.
*
* @param item
* The item to compile.
*/
constructor(item, variableFileName) {
super(item);
this.VariableFileName = variableFileName;
}
/**
* @inheritdoc
*/
get TagName() {
return "style";
}
/**
* @inheritdoc
*/
get SchemaLocation() {
return "https://www.woltlab.com/XSD/vortex/style.xsd";
}
/**
* @inheritdoc
*/
CreateDocument() {
let document = super.CreateDocument();
let editor = new XMLEditor_1.XMLEditor(document.documentElement);
editor.AddElement("general", (general) => {
for (let locale of this.Item.DisplayName.GetLocales()) {
general.AddTextElement("stylename", this.Item.DisplayName.Data[locale], (name) => {
if (locale !== "inv") {
name.SetAttribute("language", locale);
}
});
}
general.AddTextElement("version", this.Item.Version);
general.AddTextElement("date", this.Item.CreationDate.getFullYear().toString() + "-" +
(this.Item.CreationDate.getMonth() + 1).toString().padStart(2, "0") + "-" +
this.Item.CreationDate.getDate().toString().padStart(2, "0"));
for (let locale of this.Item.Description.GetLocales()) {
general.AddTextElement("description", this.Item.Description.Data[locale], (description) => {
if (locale !== "inv") {
description.SetAttribute("language", locale);
}
});
}
if (!util_1.isNullOrUndefined(this.Item.License)) {
general.AddTextElement("license", this.Item.License);
}
general.AddTextElement("packageName", this.Item.Instruction.Collection.Package.Identifier);
general.AddTextElement("apiVersion", "3.1");
if (!util_1.isNullOrUndefined(this.Item.Thumbnail)) {
general.AddTextElement("image", this.Item.Thumbnail.FileName);
}
if (!util_1.isNullOrUndefined(this.Item.HighResThumbnail)) {
general.AddTextElement("image2x", this.Item.HighResThumbnail.FileName);
}
if (!util_1.isNullOrUndefined(this.Item.CoverPhoto)) {
general.AddTextElement("coverPhoto", this.Item.CoverPhoto.FileName);
}
});
editor.AddElement("author", (author) => {
if (!util_1.isNullOrUndefined(this.Item.Author.Name)) {
author.AddTextElement("authorname", this.Item.Author.Name);
}
if (!util_1.isNullOrUndefined(this.Item.Author.URL)) {
author.AddTextElement("authorurl", this.Item.Author.URL);
}
});
let files = new XMLEditor_1.XMLEditor(document.createElement("files"));
{
if (Object.keys(this.Item.Variables).length > 0 ||
!util_1.isNullOrUndefined(this.Item.CustomScss) ||
!util_1.isNullOrUndefined(this.Item.ScssOverride)) {
files.AddTextElement("variables", this.VariableFileName);
}
if (!util_1.isNullOrUndefined(this.Item.Images)) {
files.AddTextElement("images", this.Item.Images.FileName, (images) => {
images.SetAttribute("path", this.Item.Images.DestinationRoot);
});
}
}
if (files.ChildNodes.length > 0) {
editor.Add(files.Element);
}
return document;
}
/**
* Gets or sets the filename to save variables to.
*/
get VariableFileName() {
return this.variableFileName;
}
set VariableFileName(value) {
this.variableFileName = value;
}
}
exports.ThemeFileCompiler = ThemeFileCompiler;
//# sourceMappingURL=ThemeFileCompiler.js.map