UNPKG

@manuth/woltlab-compiler

Version:

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

60 lines 2.52 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 { TempDirectory } from "@manuth/temp-files"; import path from "upath"; import { LocalizationSetCompiler } from "../../Globalization/LocalizationSetCompiler.js"; import { InstructionCompiler } from "./InstructionCompiler.js"; const { join, normalize } = path; /** * Provides the functionality to compile {@link ILocalizationInstruction `ILocalizationInstruction`}s. */ export class LocalizationInstructionCompiler extends InstructionCompiler { /** * Initializes a new instance of the {@link LocalizationInstructionCompiler `LocalizationInstructionCompiler`} class. * * @param item * The item to compile. */ constructor(item) { super(item); } /** * @inheritdoc * * @returns * The serialized document. */ Serialize() { let document = super.Serialize(); if (Object.keys(this.Item.GetMessages()).length > 0) { document.documentElement.textContent = normalize(join(this.Item.DestinationRoot, this.Item.TranslationDirectory, "*.xml")); return document; } else { return document.implementation.createDocument(null, null, null); } } /** * @inheritdoc */ Compile() { return __awaiter(this, void 0, void 0, function* () { let messages = this.Item.GetMessages(); if (Object.keys(messages).length > 0) { let tempDir = new TempDirectory(); let compiler = new LocalizationSetCompiler(this.Item.GetMessages()); compiler.DestinationPath = this.MakePackagePath(this.Item.DestinationRoot, this.Item.TranslationDirectory); yield compiler.Execute(); tempDir.Dispose(); } }); } } //# sourceMappingURL=LocalizationInstructionCompiler.js.map