UNPKG

@plugjs/zip

Version:

Zip File Plugin for the PlugJS Build System ===========================================

61 lines (59 loc) 2.33 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // zip.ts var zip_exports = {}; __export(zip_exports, { Zip: () => Zip }); module.exports = __toCommonJS(zip_exports); var import_node_fs = require("node:fs"); var import_plug = require("@plugjs/plug"); var import_paths = require("@plugjs/plug/paths"); var import_yazl = require("yazl"); var Zip = class { constructor(_filename, _options = {}) { this._filename = _filename; this._options = _options; (0, import_plug.assert)(_filename, "No filename specified for ZIP file"); } pipe(files, context) { const filename = context.resolve(this._filename); const zipfile = new import_yazl.ZipFile(); const zipstream = (0, import_node_fs.createWriteStream)(filename); zipfile.outputStream.pipe(zipstream); context.log.info(`Packaging ${(0, import_plug.$ylw)(files.length)} files`); for (const [relative, absolute] of files.pathMappings()) { context.log.debug(`Adding file ${(0, import_plug.$p)(absolute)}`); zipfile.addFile(absolute, relative, this._options); } const directory = (0, import_paths.getAbsoluteParent)(filename); const output = import_plug.Files.builder(directory).add(filename).build(); zipfile.end(); return new Promise((resolve, reject) => { zipstream.on("close", () => resolve(output)); zipfile.on("error", (error) => reject(error)); zipstream.on("error", (error) => reject(error)); }); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Zip }); //# sourceMappingURL=zip.cjs.map