UNPKG

@manuth/woltlab-compiler

Version:

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

182 lines 6.19 kB
import path from "upath"; import { Component } from "./Component.js"; import { ConflictingPackageDescriptor } from "./ConflictingPackageDescriptor.js"; import { FileDescriptor } from "./FileDescriptor.js"; import { InstructionSet } from "./Instructions/InstructionSet.js"; import { UpdateInstructionSet } from "./Instructions/UpdateInstructionSet.js"; import { OptionalPackageDescriptor } from "./OptionalPackageDescriptor.js"; import { Person } from "./Person.js"; import { RequiredPackageDescriptor } from "./RequiredPackageDescriptor.js"; const { join } = path; /** * Represents an extension-package. */ export class Package extends Component { /** * Initializes a new instance of the {@link Package `Package`} class. * * @param options * The options of the package. */ constructor(options) { var _a, _b; super({ DisplayName: options.DisplayName, Version: options.Version, Author: options.Author || new Person({ Name: null }), CreationDate: options.CreationDate, Description: options.Description, License: options.License }); /** * A set of files which will be added to the package. */ this.additionalFiles = []; /** * A set of packages which are required by this package. */ this.requiredPackages = []; /** * A set of packages which cause a conflict with this package. */ this.conflictingPackages = []; /** * A set of packages which can be installed additionally. */ this.optionalPackages = []; /** * A set of instructions for installing the package. */ this.installSet = new InstructionSet(this); /** * A set of instructions to execute when updating from a specific version. */ this.updateSets = []; this.Identifier = options.Identifier; // eslint-disable-next-line @delagen/deprecation/deprecation this.apiVersion = (_a = options.APIVersion) !== null && _a !== void 0 ? _a : null; if ((options.AdditionalFiles !== null) && (options.AdditionalFiles !== undefined)) { for (let additionalFile of options.AdditionalFiles) { this.AdditionalFiles.push(new FileDescriptor(additionalFile)); } } if ((options.RequiredPackages !== null) && (options.RequiredPackages !== undefined)) { for (let requiredPackage of options.RequiredPackages) { this.RequiredPackages.push(new RequiredPackageDescriptor(requiredPackage)); } } if ((options.ConflictingPackages !== null) && (options.ConflictingPackages !== undefined)) { for (let conflictingPackage of options.ConflictingPackages) { this.ConflictingPackages.push(new ConflictingPackageDescriptor(conflictingPackage)); } } if ((options.OptionalPackages !== null) && (options.OptionalPackages !== undefined)) { for (let optionalPackage of options.OptionalPackages) { this.OptionalPackages.push(new OptionalPackageDescriptor(optionalPackage)); } } this.InstallSet.push(...options.InstallSet.Instructions); if ((options.InstallSet.Directory !== null) && (options.InstallSet.Directory !== undefined)) { this.InstallSet.Directory = options.InstallSet.Directory; } if ((options.UpdateSets !== null) && (options.UpdateSets !== undefined)) { for (let updateSet of options.UpdateSets) { let updateInstructionSet = new UpdateInstructionSet(this, updateSet.FromVersion); updateInstructionSet.Directory = (_b = updateSet.Directory) !== null && _b !== void 0 ? _b : join("update", updateSet.FromVersion); updateInstructionSet.push(...updateSet.Instructions); this.UpdateSets.push(updateInstructionSet); } } } /** * Gets or sets the identifier of the package. */ get Identifier() { return this.identifier; } /** * @inheritdoc */ set Identifier(value) { this.identifier = value; } /** * Gets or sets the API-Version required by the package. * * @deprecated */ get APIVersion() { // eslint-disable-next-line @delagen/deprecation/deprecation return this.apiVersion; } /** * @inheritdoc * @deprecated */ set APIVersion(value) { // eslint-disable-next-line @delagen/deprecation/deprecation this.apiVersion = value; } /** * Gets a set of files which will be added to the package. */ get AdditionalFiles() { return this.additionalFiles; } /** * Gets a set of packages which are required by this package. */ get RequiredPackages() { return this.requiredPackages; } /** * Gets a set of packages which cause a conflict with this package. */ get ConflictingPackages() { return this.conflictingPackages; } /** * Gets a set of packages which can be installed additionally. */ get OptionalPackages() { return this.optionalPackages; } /** * Gets a set of instructions for installing the package. */ get InstallSet() { return this.installSet; } /** * Gets a set of instructions to execute when updating from a specific version. */ get UpdateSets() { return this.updateSets; } /** * Looks for an object with the specified id. * * @param id * The id of the object to get. * * @returns * The object with the specified id. */ GetObjectByID(id) { for (let instruction of this.InstallSet) { let objects = instruction.ObjectsByID; if (id in objects) { return objects[id]; } } } } //# sourceMappingURL=Package.js.map