woltlab-compiler
Version:
A compiler for WoltLab-Package Archives and WoltLab-Package Components
79 lines • 3.57 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const FileSystem = require("fs-extra");
const util_1 = require("util");
const Compiler_1 = require("../Compiler");
const ThemeFileCompiler_1 = require("./ThemeFileCompiler");
const ThemeVariableCompiler_1 = require("./ThemeVariableCompiler");
/**
* Provides the functionality to compile themes.
*/
class ThemeCompiler extends Compiler_1.Compiler {
/**
* Initializes a new instance of the `ThemeCompiler<T>` class.
*
* @param item
* The item to compile.
*/
constructor(item, variableFileName) {
super(item);
/**
* The name to save the variables to.
*/
this.variableFileName = "variables.xml";
if (!util_1.isNullOrUndefined(variableFileName)) {
this.VariableFileName = variableFileName;
}
}
/**
* Gets or sets the filename to save variables to.
*/
get VariableFileName() {
return this.variableFileName;
}
set VariableFileName(value) {
this.variableFileName = value;
}
/**
* @inheritdoc
*/
Compile() {
return __awaiter(this, void 0, void 0, function* () {
let variables = {};
Object.assign(variables, this.Item.Variables);
if (!util_1.isNullOrUndefined(this.Item.CustomScss)) {
variables.individualScss = this.Item.CustomScss;
}
if (!util_1.isNullOrUndefined(this.Item.ScssOverride)) {
variables.overrideScss = this.Item.ScssOverride;
}
let themeFileCompiler = new ThemeFileCompiler_1.ThemeFileCompiler(this.Item, this.VariableFileName);
themeFileCompiler.DestinationPath = this.MakeDestinationPath("style.xml");
yield themeFileCompiler.Execute();
if (Object.keys(variables).length > 0) {
let variableCompiler = new ThemeVariableCompiler_1.ThemeVariableCompiler(variables);
variableCompiler.DestinationPath = this.MakeDestinationPath(this.VariableFileName);
yield variableCompiler.Execute();
}
if (!util_1.isNullOrUndefined(this.Item.Thumbnail)) {
yield FileSystem.copy(this.Item.Thumbnail.Source, this.MakeDestinationPath(this.Item.Thumbnail.FileName));
}
if (!util_1.isNullOrUndefined(this.Item.HighResThumbnail)) {
yield FileSystem.copy(this.Item.HighResThumbnail.Source, this.MakeDestinationPath(this.Item.HighResThumbnail.FileName));
}
if (!util_1.isNullOrUndefined(this.Item.CoverPhoto)) {
yield FileSystem.copy(this.Item.CoverPhoto.Source, this.MakeDestinationPath(this.Item.CoverPhoto.FileName));
}
});
}
}
exports.ThemeCompiler = ThemeCompiler;
//# sourceMappingURL=ThemeCompiler.js.map