woltlab-compiler
Version:
A compiler for WoltLab-Package Archives and WoltLab-Package Components
97 lines • 3.37 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 Path = require("path");
const xmldom_1 = require("xmldom");
const Compiler_1 = require("../../Compiler");
/**
* Provides the functionality to compile an instruction.
*/
class InstructionCompiler extends Compiler_1.Compiler {
/**
* Initializes a new instance of the `InstructionCompiler<T>` class.
*
* @param item
* The item to compile.
*/
constructor(item) {
super(item);
}
/**
* Gets the name of the file to write the compiled item to.
*/
get DestinationFileName() {
return this.MakePackagePath(this.Item.FullName);
}
/**
* Returns an XML `Document` which represents the compiled instruction.
*/
Serialize() {
let document = new xmldom_1.DOMParser().parseFromString("<instruction />");
document.documentElement.textContent = this.Item.FullName;
document.documentElement.setAttribute("type", this.Item.Type);
if (this.Item.Standalone) {
document.documentElement.setAttribute("run", "standalone");
}
return document;
}
/**
* @inheritdoc
*/
Compile() {
return __awaiter(this, void 0, void 0, function* () {
});
}
/**
* Copies files using `EJS`.
*
* @param source
* The source to copy the files from.
*
* @param destination
* The destination to copy the files to.
*
* @param context
* The context to use.
*/
CopyTemplate(source, destination, context) {
const _super = Object.create(null, {
CopyTemplate: { get: () => super.CopyTemplate }
});
return __awaiter(this, void 0, void 0, function* () {
context = context || {};
Object.assign(context, {
$: (id) => this.Item.Collection.Package.GetObjectByID(id),
Item: this.Item
});
yield _super.CopyTemplate.call(this, source, destination, context);
});
}
/**
* Joins the paths and returns the path contained by the package-folder.
*
* @param path
* The path that is to be joined.
*/
MakePackagePath(...path) {
return super.MakeDestinationPath(...path);
}
/**
* Joins the paths and returns the path contained by the destination-folder.
*
* @param path
* The path that is to be joined.
*/
MakeDestinationPath(...path) {
return Path.join(this.DestinationFileName, ...path);
}
}
exports.InstructionCompiler = InstructionCompiler;
//# sourceMappingURL=InstructionCompiler.js.map