UNPKG

@manuth/woltlab-compiler

Version:

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

103 lines 2.72 kB
import { BidirectionalCollection } from "../../Collections/BidirectionalCollection.js"; import { XML } from "../../Serialization/XML.js"; import { XMLEditor } from "../../Serialization/XMLEditor.js"; /** * Represents a collection of instructions. */ export class InstructionSet extends BidirectionalCollection { /** * Initializes a new instance of the {@link InstructionSet `InstructionSet`} class. * * @param extensionPackage * The extension of the instruction-set. */ constructor(extensionPackage) { super(null); /** * The directory to save the set to. */ this.directory = "components"; this.Package = extensionPackage; } /** * @inheritdoc */ get Owner() { return this; } /** * Gets or sets the package the collection belongs to. */ get Package() { return this.package; } /** * @inheritdoc */ set Package(value) { this.package = value; } /** * Gets or sets the directory to save the components of this set. */ get Directory() { return this.directory; } /** * @inheritdoc */ set Directory(value) { this.directory = value; } /** * Serializes the instruction-set to an xml dom-element. * * @returns * An element representing this instruction. */ Serialize() { let document = XML.CreateDocument("instructions"); let editor = new XMLEditor(document.documentElement); editor.SetAttribute("type", "install"); if (this.length > 0) { for (let instruction of this) { if (instruction.Compiler) { let childNodes = instruction.Compiler.Serialize().childNodes; for (let i = 0; i < childNodes.length; i++) { let node = childNodes.item(i); editor.Add(node); } } } } else { editor.Add(editor.CreateElement("void")); } return editor.Element; } /** * @inheritdoc * * @param child * The child whose parent to return. * * @returns * The parent of the {@link child `child`}. */ GetParent(child) { return child === null || child === void 0 ? void 0 : child.Collection; } /** * Sets the parent of a child. * * @param child * The child whose parent is to be set. * * @param parent * The parent to set. */ SetParent(child, parent) { child.Collection = parent; } } //# sourceMappingURL=InstructionSet.js.map