woltlab-compiler
Version:
A compiler for WoltLab-Package Archives and WoltLab-Package Components
57 lines • 2.05 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const FileSystem = require("fs-extra");
const xmldom_1 = require("xmldom");
const XML_1 = require("../Serialization/XML");
const Compiler_1 = require("./Compiler");
/**
* Provides the functionality to compile components to `.xml`-files.
*/
class XMLFileCompiler extends Compiler_1.Compiler {
/**
* Initializes a new instance of the `XMLFileCompiler<T>` class.
*
* @param item
* The item to compile.
*/
constructor(item) {
super(item);
}
/**
* @inheritdoc
*/
Compile() {
return __awaiter(this, void 0, void 0, function* () {
yield FileSystem.ensureFile(this.DestinationPath);
yield FileSystem.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_1.XML.Format(new xmldom_1.XMLSerializer().serializeToString(this.Document));
}
/**
* Creates the document to compile.
*/
CreateDocument() {
return XML_1.XML.CreateDocument(this.TagName);
}
}
exports.XMLFileCompiler = XMLFileCompiler;
//# sourceMappingURL=XMLFileCompiler.js.map