UNPKG

@manuth/woltlab-compiler

Version:

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

62 lines 2.11 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 { XMLSerializer } from "@xmldom/xmldom"; import fs from "fs-extra"; import { XML } from "../Serialization/XML.js"; import { Compiler } from "./Compiler.js"; const { ensureFile, writeFile } = fs; /** * Provides the functionality to compile components to `.xml`-files. * * @template T * The type of the item which can be compiled by this compiler. */ export class XMLFileCompiler extends Compiler { /** * Initializes a new instance of the {@link XMLFileCompiler `XMLFileCompiler<T>`} class. * * @param item * The item to compile. */ constructor(item) { super(item); } /** * @inheritdoc */ Compile() { return __awaiter(this, void 0, void 0, function* () { yield ensureFile(this.DestinationPath); yield writeFile(this.DestinationPath, this.Content); }); } /** * Gets the compiled `xml`-document of the component. */ get Document() { return this.CreateDocument(); } /** * Gets the content of the `xml`-element as a string. */ get Content() { return XML.Format(new XMLSerializer().serializeToString(this.Document)); } /** * Creates the document to compile. * * @returns * The serialized document. */ CreateDocument() { return XML.CreateDocument(this.TagName); } } //# sourceMappingURL=XMLFileCompiler.js.map