UNPKG

woltlab-compiler

Version:

A compiler for WoltLab-Package Archives and WoltLab-Package Components

108 lines 3.51 kB
"use strict"; 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 MemoryFileStore = require("mem-fs"); const MemoryFileStoreEditor = require("mem-fs-editor"); const Path = require("path"); const Tar = require("tar"); /** * Provides the functionality to compile a component. */ class Compiler { /** * Initializes a new instance of the `Compiler<T>` class. * * @param item * The item to compile. */ constructor(item) { /** * The path to save the compiled item to. */ this.destinationPath = ""; this.item = item; } /** * Gets the item to compile. */ get Item() { return this.item; } /** * Gets or sets the path to save the compiled item to. */ get DestinationPath() { return this.destinationPath; } set DestinationPath(value) { this.destinationPath = value; } /** * Compiles the item. */ Execute() { return __awaiter(this, void 0, void 0, function* () { yield this.Compile(); }); } /** * 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) { return __awaiter(this, void 0, void 0, function* () { let fileStoreEditor = MemoryFileStoreEditor.create(MemoryFileStore.create()); fileStoreEditor.copyTpl(source, destination, context, {}, { globOptions: { dot: true } }); yield new Promise((resolve) => { fileStoreEditor.commit([], () => { resolve(); }); }); }); } /** * 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.DestinationPath, ...path); } /** * Compresses a folder and saves the result to a specified file. * * @param source * The folder that is to be compressed. * * @param destination * The filename to save the compressed file to. */ Compress(source, destination) { return __awaiter(this, void 0, void 0, function* () { yield FileSystem.ensureDir(Path.dirname(destination)); yield Tar.create({ cwd: Path.resolve(source), file: Path.resolve(destination) }, yield FileSystem.readdir(source)); }); } } exports.Compiler = Compiler; //# sourceMappingURL=Compiler.js.map