UNPKG

@manuth/woltlab-compiler

Version:

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

110 lines 3.63 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 { DOMParser } from "@xmldom/xmldom"; import path from "upath"; import { Compiler } from "../../Compiler.js"; const { join } = path; /** * Provides the functionality to compile an instruction. * * @template T * The type of the instruction which can be compiled by this compiler. */ export class InstructionCompiler extends Compiler { /** * Initializes a new instance of the {@link InstructionCompiler `InstructionCompiler<T>`} class. * * @param instruction * The instruction to compile. */ constructor(instruction) { super(instruction); } /** * Gets the name of the file to write the compiled item to. */ get DestinationFileName() { return this.MakePackagePath(this.Item.FullName); } /** * Returns an xml-{@link Document `Document`} which represents the compiled instruction. * * @returns * The serialized document. */ Serialize() { let document = new DOMParser().parseFromString("<instruction />"); document.documentElement.textContent = this.Item.FullName; document.documentElement.setAttribute("type", this.Item.Type); if (this.Item.Standalone) { document.documentElement.setAttribute("run", "standalone"); } return document; } /** * @inheritdoc */ Compile() { return __awaiter(this, void 0, void 0, function* () { }); } /** * Copies files using `ejs`. * * @param source * The source to copy the files from. * * @param destination * The destination to copy the files to. * * @param context * The context to use. * * @param delimiter * The delimiter of the ejs-tags. */ CopyTemplate(source, destination, context, delimiter) { const _super = Object.create(null, { CopyTemplate: { get: () => super.CopyTemplate } }); return __awaiter(this, void 0, void 0, function* () { context = context || {}; Object.assign(context, { $: (id) => this.Item.Collection.Package.GetObjectByID(id), Item: this.Item }); yield _super.CopyTemplate.call(this, source, destination, context, delimiter); }); } /** * Joins the paths and returns the path contained by the package-folder. * * @param path * The path that is to be joined. * * @returns * The joined path relative to the package-folder. */ MakePackagePath(...path) { return super.MakeDestinationPath(...path); } /** * @inheritdoc * * @param path * The path that is to be joined. * * @returns * The joined path relative to the destination-folder. */ MakeDestinationPath(...path) { return join(this.DestinationFileName, ...path); } } //# sourceMappingURL=InstructionCompiler.js.map