@plugjs/zip 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ Zip File Plugin for the PlugJS Build System
2
+ ===========================================
3
+
4
+ Prototype build system from [Juit GmbH](https://www.juit.com/)
5
+
6
+ * [Copyright Notice](https://github.com/plugjs/plug/blob/main/NOTICE.md)
7
+ * [License](https://github.com/plugjs/plug/blob/main/LICENSE.md)
package/dist/index.cjs ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ // index.ts
4
+ var import_fork = require("@plugjs/plug/fork");
5
+ var import_paths = require("@plugjs/plug/paths");
6
+ (0, import_fork.installForking)("zip", (0, import_paths.requireResolve)(__filename, "./zip"), "Zip");
7
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "mappings": ";;;AAAA,kBAA+B;AAC/B,mBAA+B;AAAA,IAa/B,4BAAe,WAAO,6BAAe,YAAW,OAAO,GAAG,KAAK;",
5
+ "names": []
6
+ }
@@ -0,0 +1,11 @@
1
+ declare module '@plugjs/plug' {
2
+ interface Pipe {
3
+ /**
4
+ * Archive all input {@link Files} into a _Zip_.
5
+ *
6
+ * @param filename The output zip file name.
7
+ */
8
+ zip(filename: string): Pipe;
9
+ }
10
+ }
11
+ export {};
package/dist/index.mjs ADDED
@@ -0,0 +1,15 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
5
+
6
+ // index.ts
7
+ import { installForking } from "@plugjs/plug/fork";
8
+ import { requireResolve } from "@plugjs/plug/paths";
9
+ var require_src = __commonJS({
10
+ "index.ts"() {
11
+ installForking("zip", requireResolve(import.meta.url, "./zip"), "Zip");
12
+ }
13
+ });
14
+ export default require_src();
15
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "mappings": ";;;;;;AAAA,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAD/B;AAAA;AAcA,mBAAe,OAAO,eAAe,iBAAW,OAAO,GAAG,KAAK;AAAA;AAAA;",
5
+ "names": []
6
+ }
package/dist/zip.cjs ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // zip.ts
21
+ var zip_exports = {};
22
+ __export(zip_exports, {
23
+ Zip: () => Zip
24
+ });
25
+ module.exports = __toCommonJS(zip_exports);
26
+ var import_node_fs = require("node:fs");
27
+ var import_plug = require("@plugjs/plug");
28
+ var import_paths = require("@plugjs/plug/paths");
29
+ var import_yazl = require("yazl");
30
+ var Zip = class {
31
+ constructor(_filename) {
32
+ this._filename = _filename;
33
+ (0, import_plug.assert)(_filename, "No filename specified for ZIP file");
34
+ }
35
+ pipe(files, context) {
36
+ const filename = context.resolve(this._filename);
37
+ const zipfile = new import_yazl.ZipFile();
38
+ const zipstream = (0, import_node_fs.createWriteStream)(filename);
39
+ zipfile.outputStream.pipe(zipstream);
40
+ context.log.info(`Packaging ${(0, import_plug.$ylw)(files.length)} files`);
41
+ for (const [relative, absolute] of files.pathMappings()) {
42
+ context.log.debug(`Adding file ${(0, import_plug.$p)(absolute)}`);
43
+ zipfile.addFile(absolute, relative);
44
+ }
45
+ const directory = (0, import_paths.getAbsoluteParent)(filename);
46
+ const output = import_plug.Files.builder(directory).add(filename).build();
47
+ zipfile.end();
48
+ return new Promise((resolve, reject) => {
49
+ zipstream.on("close", () => resolve(output));
50
+ zipfile.on("error", (error) => reject(error));
51
+ zipstream.on("error", (error) => reject(error));
52
+ });
53
+ }
54
+ };
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ Zip
58
+ });
59
+ //# sourceMappingURL=zip.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/zip.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAkC;AAElC,kBAAwC;AACxC,mBAAkC;AAClC,kBAAwB;AAcjB,IAAM,MAAN,MAAiC;AAAA,EAEtC,YAA6B,WAAmB;AAAnB;AAC3B,4BAAO,WAAW,oCAAoC;AAAA,EACxD;AAAA,EAEA,KAAK,OAAc,SAAkC;AACnD,UAAM,WAAW,QAAQ,QAAQ,KAAK,SAAS;AAG/C,UAAM,UAAU,IAAI,oBAAQ;AAC5B,UAAM,gBAAY,kCAAkB,QAAQ;AAC5C,YAAQ,aAAa,KAAK,SAAS;AAGnC,YAAQ,IAAI,KAAK,iBAAa,kBAAK,MAAM,MAAM,SAAS;AACxD,eAAW,CAAE,UAAU,QAAS,KAAK,MAAM,aAAa,GAAG;AACzD,cAAQ,IAAI,MAAM,mBAAe,gBAAG,QAAQ,GAAG;AAC/C,cAAQ,QAAQ,UAAU,QAAQ;AAAA,IACpC;AAGA,UAAM,gBAAY,gCAAkB,QAAQ;AAC5C,UAAM,SAAS,kBAAM,QAAQ,SAAS,EAAE,IAAI,QAAQ,EAAE,MAAM;AAC5D,YAAQ,IAAI;AAGZ,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,gBAAU,GAAG,SAAS,MAAM,QAAQ,MAAM,CAAC;AAE3C,cAAQ,GAAG,SAAS,CAAC,UAAU,OAAO,KAAK,CAAC;AAE5C,gBAAU,GAAG,SAAS,CAAC,UAAU,OAAO,KAAK,CAAC;AAAA,IAChD,CAAC;AAAA,EACH;AACF;",
5
+ "names": []
6
+ }
package/dist/zip.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /// <reference path="index.d.ts" />
2
+ /// <reference types="node" />
3
+ import { Files } from '@plugjs/plug';
4
+ import type { Context, PipeParameters, Plug } from '@plugjs/plug/pipe';
5
+ import type EventEmitter from 'node:events';
6
+ declare module 'yazl' {
7
+ interface ZipFile extends EventEmitter {
8
+ on(event: 'error', listener: (err: Error) => void): this;
9
+ }
10
+ }
11
+ /** Writes some info about the current {@link Files} being passed around. */
12
+ export declare class Zip implements Plug<Files> {
13
+ private readonly _filename;
14
+ constructor(...args: PipeParameters<'zip'>);
15
+ pipe(files: Files, context: Context): Promise<Files>;
16
+ }
package/dist/zip.mjs ADDED
@@ -0,0 +1,34 @@
1
+ // zip.ts
2
+ import { createWriteStream } from "node:fs";
3
+ import { $p, $ylw, assert, Files } from "@plugjs/plug";
4
+ import { getAbsoluteParent } from "@plugjs/plug/paths";
5
+ import { ZipFile } from "yazl";
6
+ var Zip = class {
7
+ constructor(_filename) {
8
+ this._filename = _filename;
9
+ assert(_filename, "No filename specified for ZIP file");
10
+ }
11
+ pipe(files, context) {
12
+ const filename = context.resolve(this._filename);
13
+ const zipfile = new ZipFile();
14
+ const zipstream = createWriteStream(filename);
15
+ zipfile.outputStream.pipe(zipstream);
16
+ context.log.info(`Packaging ${$ylw(files.length)} files`);
17
+ for (const [relative, absolute] of files.pathMappings()) {
18
+ context.log.debug(`Adding file ${$p(absolute)}`);
19
+ zipfile.addFile(absolute, relative);
20
+ }
21
+ const directory = getAbsoluteParent(filename);
22
+ const output = Files.builder(directory).add(filename).build();
23
+ zipfile.end();
24
+ return new Promise((resolve, reject) => {
25
+ zipstream.on("close", () => resolve(output));
26
+ zipfile.on("error", (error) => reject(error));
27
+ zipstream.on("error", (error) => reject(error));
28
+ });
29
+ }
30
+ };
31
+ export {
32
+ Zip
33
+ };
34
+ //# sourceMappingURL=zip.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/zip.ts"],
4
+ "mappings": ";AAGA,SAAS,yBAAyB;AAElC,SAAS,IAAI,MAAM,QAAQ,aAAa;AACxC,SAAS,yBAAyB;AAClC,SAAS,eAAe;AAcjB,IAAM,MAAN,MAAiC;AAAA,EAEtC,YAA6B,WAAmB;AAAnB;AAC3B,WAAO,WAAW,oCAAoC;AAAA,EACxD;AAAA,EAEA,KAAK,OAAc,SAAkC;AACnD,UAAM,WAAW,QAAQ,QAAQ,KAAK,SAAS;AAG/C,UAAM,UAAU,IAAI,QAAQ;AAC5B,UAAM,YAAY,kBAAkB,QAAQ;AAC5C,YAAQ,aAAa,KAAK,SAAS;AAGnC,YAAQ,IAAI,KAAK,aAAa,KAAK,MAAM,MAAM,SAAS;AACxD,eAAW,CAAE,UAAU,QAAS,KAAK,MAAM,aAAa,GAAG;AACzD,cAAQ,IAAI,MAAM,eAAe,GAAG,QAAQ,GAAG;AAC/C,cAAQ,QAAQ,UAAU,QAAQ;AAAA,IACpC;AAGA,UAAM,YAAY,kBAAkB,QAAQ;AAC5C,UAAM,SAAS,MAAM,QAAQ,SAAS,EAAE,IAAI,QAAQ,EAAE,MAAM;AAC5D,YAAQ,IAAI;AAGZ,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,gBAAU,GAAG,SAAS,MAAM,QAAQ,MAAM,CAAC;AAE3C,cAAQ,GAAG,SAAS,CAAC,UAAU,OAAO,KAAK,CAAC;AAE5C,gBAAU,GAAG,SAAS,CAAC,UAAU,OAAO,KAAK,CAAC;AAAA,IAChD,CAAC;AAAA,EACH;AACF;",
5
+ "names": []
6
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@plugjs/zip",
3
+ "version": "0.2.0",
4
+ "type": "commonjs",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.cjs"
13
+ },
14
+ "import": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.mjs"
17
+ }
18
+ },
19
+ "./zip": {
20
+ "require": {
21
+ "types": "./dist/zip.d.ts",
22
+ "default": "./dist/zip.cjs"
23
+ },
24
+ "import": {
25
+ "types": "./dist/zip.d.ts",
26
+ "default": "./dist/zip.mjs"
27
+ }
28
+ }
29
+ },
30
+ "author": "Juit Developers <developers@juit.com>",
31
+ "license": "Apache-2.0",
32
+ "dependencies": {
33
+ "yazl": "^2.5.1"
34
+ },
35
+ "devDependencies": {
36
+ "@types/yauzl": "^2.10.0",
37
+ "@types/yazl": "^2.4.2",
38
+ "yauzl": "^2.10.0"
39
+ },
40
+ "peerDependencies": {
41
+ "@plugjs/plug": "0.2.0"
42
+ },
43
+ "files": [
44
+ "*.md",
45
+ "dist/",
46
+ "src/"
47
+ ]
48
+ }
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { installForking } from '@plugjs/plug/fork'
2
+ import { requireResolve } from '@plugjs/plug/paths'
3
+
4
+ declare module '@plugjs/plug' {
5
+ export interface Pipe {
6
+ /**
7
+ * Archive all input {@link Files} into a _Zip_.
8
+ *
9
+ * @param filename The output zip file name.
10
+ */
11
+ zip(filename: string): Pipe
12
+ }
13
+ }
14
+
15
+ installForking('zip', requireResolve(__fileurl, './zip'), 'Zip')
package/src/zip.ts ADDED
@@ -0,0 +1,57 @@
1
+ // Reference ourselves, so that the constructor's parameters are correct
2
+ /// <reference path="./index.ts" />
3
+
4
+ import { createWriteStream } from 'node:fs'
5
+
6
+ import { $p, $ylw, assert, Files } from '@plugjs/plug'
7
+ import { getAbsoluteParent } from '@plugjs/plug/paths'
8
+ import { ZipFile } from 'yazl'
9
+
10
+ import type { Context, PipeParameters, Plug } from '@plugjs/plug/pipe'
11
+ import type EventEmitter from 'node:events'
12
+
13
+
14
+ // The "yazl" types don't define "ZipFile" as an "EventEmitter"
15
+ declare module 'yazl' {
16
+ interface ZipFile extends EventEmitter {
17
+ on(event: 'error', listener: (err: Error) => void): this;
18
+ }
19
+ }
20
+
21
+ /** Writes some info about the current {@link Files} being passed around. */
22
+ export class Zip implements Plug<Files> {
23
+ constructor(...args: PipeParameters<'zip'>)
24
+ constructor(private readonly _filename: string) {
25
+ assert(_filename, 'No filename specified for ZIP file')
26
+ }
27
+
28
+ pipe(files: Files, context: Context): Promise<Files> {
29
+ const filename = context.resolve(this._filename)
30
+
31
+ /* Create a new ZipFile piping to a WriteStream */
32
+ const zipfile = new ZipFile()
33
+ const zipstream = createWriteStream(filename)
34
+ zipfile.outputStream.pipe(zipstream)
35
+
36
+ /* Add all unique files to the zip */
37
+ context.log.info(`Packaging ${$ylw(files.length)} files`)
38
+ for (const [ relative, absolute ] of files.pathMappings()) {
39
+ context.log.debug(`Adding file ${$p(absolute)}`)
40
+ zipfile.addFile(absolute, relative)
41
+ }
42
+
43
+ /* All files are added, just compute our return */
44
+ const directory = getAbsoluteParent(filename)
45
+ const output = Files.builder(directory).add(filename).build()
46
+ zipfile.end()
47
+
48
+ /* When done, resolve or reject! */
49
+ return new Promise((resolve, reject) => {
50
+ zipstream.on('close', () => resolve(output))
51
+ /* coverage ignore next */
52
+ zipfile.on('error', (error) => reject(error))
53
+ /* coverage ignore next */
54
+ zipstream.on('error', (error) => reject(error))
55
+ })
56
+ }
57
+ }