keycloakify 7.6.3 → 7.6.5

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.
Files changed (54) hide show
  1. package/README.md +2 -0
  2. package/account/kcContext/KcContext.d.ts +1 -0
  3. package/account/kcContext/KcContext.js.map +1 -1
  4. package/account/kcContext/kcContextMocks.js +1 -0
  5. package/account/kcContext/kcContextMocks.js.map +1 -1
  6. package/bin/eject-keycloak-page.js +6 -6
  7. package/bin/eject-keycloak-page.js.map +1 -1
  8. package/bin/keycloakify/BuildOptions.d.ts +1 -1
  9. package/bin/keycloakify/BuildOptions.js +5 -5
  10. package/bin/keycloakify/BuildOptions.js.map +1 -1
  11. package/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +3 -2
  12. package/bin/keycloakify/generateFtl/generateFtl.d.ts +2 -0
  13. package/bin/keycloakify/generateFtl/generateFtl.js +5 -5
  14. package/bin/keycloakify/generateFtl/generateFtl.js.map +1 -1
  15. package/bin/keycloakify/generateJavaStackFiles.d.ts +1 -1
  16. package/bin/keycloakify/generateJavaStackFiles.js +3 -3
  17. package/bin/keycloakify/generateJavaStackFiles.js.map +1 -1
  18. package/bin/keycloakify/generateKeycloakThemeResources.d.ts +2 -0
  19. package/bin/keycloakify/generateKeycloakThemeResources.js +4 -3
  20. package/bin/keycloakify/generateKeycloakThemeResources.js.map +1 -1
  21. package/bin/keycloakify/keycloakify.js +8 -2
  22. package/bin/keycloakify/keycloakify.js.map +1 -1
  23. package/bin/keycloakify/parsedPackageJson.d.ts +89 -2
  24. package/bin/keycloakify/parsedPackageJson.js +4 -4
  25. package/bin/keycloakify/parsedPackageJson.js.map +1 -1
  26. package/bin/tools/jar.d.ts +19 -3
  27. package/bin/tools/jar.js +151 -58
  28. package/bin/tools/jar.js.map +1 -1
  29. package/bin/tools/walk.d.ts +2 -2
  30. package/bin/tools/walk.js +3 -3
  31. package/bin/tools/walk.js.map +1 -1
  32. package/login/kcContext/KcContext.d.ts +1 -0
  33. package/login/kcContext/KcContext.js.map +1 -1
  34. package/login/kcContext/kcContextMocks.js +1 -0
  35. package/login/kcContext/kcContextMocks.js.map +1 -1
  36. package/package.json +5 -6
  37. package/src/account/kcContext/KcContext.ts +1 -0
  38. package/src/account/kcContext/kcContextMocks.ts +1 -0
  39. package/src/bin/eject-keycloak-page.ts +2 -4
  40. package/src/bin/keycloakify/BuildOptions.ts +2 -2
  41. package/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +3 -2
  42. package/src/bin/keycloakify/generateFtl/generateFtl.ts +6 -3
  43. package/src/bin/keycloakify/generateJavaStackFiles.ts +4 -4
  44. package/src/bin/keycloakify/generateKeycloakThemeResources.ts +5 -2
  45. package/src/bin/keycloakify/keycloakify.ts +10 -2
  46. package/src/bin/keycloakify/parsedPackageJson.ts +3 -3
  47. package/src/bin/tools/jar.ts +58 -65
  48. package/src/bin/tools/walk.ts +5 -5
  49. package/src/login/kcContext/KcContext.ts +1 -0
  50. package/src/login/kcContext/kcContextMocks.ts +1 -0
  51. package/bin/tools/zip.d.ts +0 -29
  52. package/bin/tools/zip.js +0 -330
  53. package/bin/tools/zip.js.map +0 -1
  54. package/src/bin/tools/zip.ts +0 -246
@@ -11,6 +11,7 @@ import jar from "../tools/jar";
11
11
  import { assert } from "tsafe/assert";
12
12
  import { Equals } from "tsafe";
13
13
  import { getEmailThemeSrcDirPath } from "../getSrcDirPath";
14
+ import { getProjectRoot } from "../tools/getProjectRoot";
14
15
 
15
16
  export async function main() {
16
17
  const { isSilent, hasExternalAssets } = getCliOptions(process.argv.slice(2));
@@ -38,7 +39,14 @@ export async function main() {
38
39
  })(),
39
40
  "reactAppBuildDirPath": buildOptions.reactAppBuildDirPath,
40
41
  buildOptions,
41
- "keycloakVersion": buildOptions.keycloakVersionDefaultAssets
42
+ "keycloakVersion": buildOptions.keycloakVersionDefaultAssets,
43
+ "keycloakifyVersion": (() => {
44
+ const version = JSON.parse(fs.readFileSync(pathJoin(getProjectRoot(), "package.json")).toString("utf8"))["version"];
45
+
46
+ assert(typeof version === "string");
47
+
48
+ return version;
49
+ })()
42
50
  });
43
51
 
44
52
  const { jarFilePath } = generateJavaStackFiles({
@@ -55,7 +63,7 @@ export async function main() {
55
63
  logger.log("🫶 Let keycloakify do its thang");
56
64
  await jar({
57
65
  "rootPath": pathJoin(buildOptions.keycloakifyBuildDirPath, "src", "main", "resources"),
58
- "version": buildOptions.version,
66
+ "version": buildOptions.themeVersion,
59
67
  "groupId": buildOptions.groupId,
60
68
  "artifactId": buildOptions.artifactId,
61
69
  "targetPath": jarFilePath
@@ -8,7 +8,7 @@ export const bundlers = ["mvn", "keycloakify", "none"] as const;
8
8
  export type Bundler = (typeof bundlers)[number];
9
9
  export type ParsedPackageJson = {
10
10
  name: string;
11
- version: string;
11
+ version?: string;
12
12
  homepage?: string;
13
13
  keycloakify?: {
14
14
  /** @deprecated: use extraLoginPages instead */
@@ -28,9 +28,9 @@ export type ParsedPackageJson = {
28
28
  };
29
29
  };
30
30
 
31
- const zParsedPackageJson = z.object({
31
+ export const zParsedPackageJson = z.object({
32
32
  "name": z.string(),
33
- "version": z.string(),
33
+ "version": z.string().optional(),
34
34
  "homepage": z.string().optional(),
35
35
  "keycloakify": z
36
36
  .object({
@@ -1,94 +1,87 @@
1
- import { Readable, Transform } from "stream";
2
1
  import { dirname, relative, sep } from "path";
3
2
  import { createWriteStream } from "fs";
4
3
 
5
4
  import walk from "./walk";
6
- import zip, { type ZipSource } from "./zip";
5
+ import { ZipFile } from "yazl";
7
6
  import { mkdir } from "fs/promises";
8
7
  import trimIndent from "./trimIndent";
9
8
 
10
- type JarArgs = {
11
- rootPath: string;
12
- targetPath: string;
9
+ export type ZipEntry = { zipPath: string } & ({ fsPath: string } | { buffer: Buffer });
10
+ export type ZipEntryGenerator = AsyncGenerator<ZipEntry, void, unknown>;
11
+
12
+ type CommonJarArgs = {
13
13
  groupId: string;
14
14
  artifactId: string;
15
15
  version: string;
16
16
  };
17
17
 
18
- /**
19
- * Create a jar archive, using the resources found at `rootPath` (a directory) and write the
20
- * archive to `targetPath` (a file). Use `groupId`, `artifactId` and `version` to define
21
- * the contents of the pom.properties file which is going to be added to the archive.
22
- */
23
- export default async function jar({ groupId, artifactId, version, rootPath, targetPath }: JarArgs) {
24
- const manifest: ZipSource = {
25
- path: "META-INF/MANIFEST.MF",
26
- data: Buffer.from(trimIndent`
18
+ export type JarStreamArgs = CommonJarArgs & {
19
+ asyncPathGeneratorFn(): ZipEntryGenerator;
20
+ };
21
+
22
+ export type JarArgs = CommonJarArgs & {
23
+ targetPath: string;
24
+ rootPath: string;
25
+ };
26
+
27
+ export async function jarStream({ groupId, artifactId, version, asyncPathGeneratorFn }: JarStreamArgs) {
28
+ const manifestPath = "META-INF/MANIFEST.MF";
29
+ const manifestData = Buffer.from(trimIndent`
27
30
  Manifest-Version: 1.0
28
31
  Archiver-Version: Plexus Archiver
29
32
  Created-By: Keycloakify
30
33
  Built-By: unknown
31
34
  Build-Jdk: 19.0.0
32
- `)
33
- };
35
+ `);
34
36
 
35
- const pomProps: ZipSource = {
36
- path: `META-INF/maven/${groupId}/${artifactId}/pom.properties`,
37
- data: Buffer.from(trimIndent`# Generated by keycloakify
38
- # ${new Date().toString()}
37
+ const pomPropsPath = `META-INF/maven/${groupId}/${artifactId}/pom.properties`;
38
+ const pomPropsData = Buffer.from(trimIndent`
39
+ # Generated by keycloakify
40
+ # ${new Date()}
39
41
  artifactId=${artifactId}
40
42
  groupId=${groupId}
41
43
  version=${version}
42
- `)
43
- };
44
+ `);
44
45
 
45
- /**
46
- * Convert every path entry to a ZipSource record, and when all records are
47
- * processed, append records for MANIFEST.mf and pom.properties
48
- */
49
- const pathToRecord = () =>
50
- new Transform({
51
- objectMode: true,
52
- transform: function (fsPath, _, cb) {
53
- const path = relative(rootPath, fsPath).split(sep).join("/");
54
- this.push({ path, fsPath });
55
- cb();
56
- },
57
- final: function () {
58
- this.push(manifest);
59
- this.push(pomProps);
60
- this.push(null);
61
- }
62
- });
46
+ const zipFile = new ZipFile();
63
47
 
64
- await mkdir(dirname(targetPath), { recursive: true });
48
+ for await (const entry of asyncPathGeneratorFn()) {
49
+ if ("buffer" in entry) {
50
+ zipFile.addBuffer(entry.buffer, entry.zipPath);
51
+ } else if ("fsPath" in entry && !entry.fsPath.endsWith(sep)) {
52
+ zipFile.addFile(entry.fsPath, entry.zipPath);
53
+ }
54
+ }
65
55
 
66
- // Create an async pipeline, wait until everything is fully processed
67
- await new Promise<void>((resolve, reject) => {
68
- // walk all files in `rootPath` recursively
69
- Readable.from(walk(rootPath))
70
- // transform every path into a ZipSource object
71
- .pipe(pathToRecord())
72
- // let the zip lib convert all ZipSource objects into a byte stream
73
- .pipe(zip())
74
- // write that byte stream to targetPath
75
- .pipe(createWriteStream(targetPath, { encoding: "binary" }))
76
- .on("finish", () => resolve())
77
- .on("error", e => reject(e));
78
- });
56
+ zipFile.addBuffer(manifestData, manifestPath);
57
+ zipFile.addBuffer(pomPropsData, pomPropsPath);
58
+
59
+ zipFile.end();
60
+
61
+ return zipFile;
79
62
  }
80
63
 
81
64
  /**
82
- * Standalone usage, call e.g. `ts-node jar.ts dirWithSources some-jar.jar`
65
+ * Create a jar archive, using the resources found at `rootPath` (a directory) and write the
66
+ * archive to `targetPath` (a file). Use `groupId`, `artifactId` and `version` to define
67
+ * the contents of the pom.properties file which is going to be added to the archive.
83
68
  */
84
- if (require.main === module) {
85
- const main = () =>
86
- jar({
87
- rootPath: process.argv[2],
88
- targetPath: process.argv[3],
89
- artifactId: process.env.ARTIFACT_ID ?? "artifact",
90
- groupId: process.env.GROUP_ID ?? "group",
91
- version: process.env.VERSION ?? "1.0.0"
92
- });
93
- main();
69
+ export default async function jar({ groupId, artifactId, version, rootPath, targetPath }: JarArgs) {
70
+ await mkdir(dirname(targetPath), { recursive: true });
71
+
72
+ const asyncPathGeneratorFn = async function* (): ZipEntryGenerator {
73
+ for await (const fsPath of walk(rootPath)) {
74
+ const zipPath = relative(rootPath, fsPath).split(sep).join("/");
75
+ yield { fsPath, zipPath };
76
+ }
77
+ };
78
+
79
+ const zipFile = await jarStream({ groupId, artifactId, version, asyncPathGeneratorFn });
80
+
81
+ await new Promise<void>(async (resolve, reject) => {
82
+ zipFile.outputStream
83
+ .pipe(createWriteStream(targetPath, { encoding: "binary" }))
84
+ .on("close", () => resolve())
85
+ .on("error", e => reject(e));
86
+ });
94
87
  }
@@ -1,19 +1,19 @@
1
1
  import { readdir } from "fs/promises";
2
- import { resolve } from "path";
2
+ import { resolve, sep } from "path";
3
3
 
4
4
  /**
5
5
  * Asynchronously and recursively walk a directory tree, yielding every file and directory
6
- * found
6
+ * found. Directory paths will _always_ end with a path separator.
7
7
  *
8
8
  * @param root the starting directory
9
9
  * @returns AsyncGenerator
10
10
  */
11
- export default async function* walk(root: string): AsyncGenerator<string, void, void> {
11
+ export default async function* walk(root: string): AsyncGenerator<string, void, unknown> {
12
12
  for (const entry of await readdir(root, { withFileTypes: true })) {
13
13
  const absolutePath = resolve(root, entry.name);
14
14
  if (entry.isDirectory()) {
15
- yield absolutePath;
15
+ yield absolutePath.endsWith(sep) ? absolutePath : absolutePath + sep;
16
16
  yield* walk(absolutePath);
17
- } else yield absolutePath;
17
+ } else yield absolutePath.endsWith(sep) ? absolutePath.substring(0, absolutePath.length - 1) : absolutePath;
18
18
  }
19
19
  }
@@ -36,6 +36,7 @@ export type KcContext =
36
36
 
37
37
  export declare namespace KcContext {
38
38
  export type Common = {
39
+ keycloakifyVersion: string;
39
40
  url: {
40
41
  loginAction: string;
41
42
  resourcesPath: string;
@@ -101,6 +101,7 @@ const attributes: Attribute[] = [
101
101
  const attributesByName = Object.fromEntries(attributes.map(attribute => [attribute.name, attribute])) as any;
102
102
 
103
103
  export const kcContextCommonMock: KcContext.Common = {
104
+ "keycloakifyVersion": "0.0.0",
104
105
  "url": {
105
106
  "loginAction": "#",
106
107
  "resourcesPath": pathJoin(PUBLIC_URL, mockTestingResourcesPath),
@@ -1,29 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { Transform } from "stream";
4
- /**
5
- * Zip source
6
- * @property filename the name of the entry in the archie
7
- * @property path of the source file, if the source is an actual file
8
- * @property data the actual data buffer, if the source is constructed in-memory
9
- */
10
- export type ZipSource = {
11
- path: string;
12
- } & ({
13
- fsPath: string;
14
- } | {
15
- data: Buffer;
16
- });
17
- export type ZipRecord = {
18
- path: string;
19
- compression: "deflate" | undefined;
20
- uncompressedSize: number;
21
- compressedSize?: number;
22
- crc32?: number;
23
- offset?: number;
24
- };
25
- /**
26
- * @returns a stream Transform, which reads a stream of ZipRecords and
27
- * writes a bytestream
28
- */
29
- export default function zip(): Transform;
package/bin/tools/zip.js DELETED
@@ -1,330 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __values = (this && this.__values) || function(o) {
39
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
- if (m) return m.call(o);
41
- if (o && typeof o.length === "number") return {
42
- next: function () {
43
- if (o && i >= o.length) o = void 0;
44
- return { value: o && o[i++], done: !o };
45
- }
46
- };
47
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- var stream_1 = require("stream");
51
- var fs_1 = require("fs");
52
- var promises_1 = require("fs/promises");
53
- var buffer_1 = require("buffer");
54
- var deflate_1 = require("./deflate");
55
- /**
56
- * @returns the actual byte size of an string
57
- */
58
- function utf8size(s) {
59
- return new buffer_1.Blob([s]).size;
60
- }
61
- /**
62
- * @param record
63
- * @returns a buffer representing a Zip local header
64
- * @link https://en.wikipedia.org/wiki/ZIP_(file_format)#Local_file_header
65
- */
66
- function localHeader(record) {
67
- var path = record.path, compression = record.compression, uncompressedSize = record.uncompressedSize;
68
- var filenameSize = utf8size(path);
69
- var buf = Buffer.alloc(30 + filenameSize);
70
- buf.writeUInt32LE(67324752, 0); // local header signature
71
- buf.writeUInt16LE(10, 4); // min version
72
- // we write 0x08 because crc and compressed size are unknown at
73
- buf.writeUInt16LE(0x08, 6); // general purpose bit flag
74
- buf.writeUInt16LE(compression ? { "deflate": 8 }[compression] : 0, 8);
75
- buf.writeUInt16LE(0, 10); // modified time
76
- buf.writeUInt16LE(0, 12); // modified date
77
- buf.writeUInt32LE(0, 14); // crc unknown
78
- buf.writeUInt32LE(0, 18); // compressed size unknown
79
- buf.writeUInt32LE(uncompressedSize, 22);
80
- buf.writeUInt16LE(filenameSize, 26);
81
- buf.writeUInt16LE(0, 28); // extra field length
82
- buf.write(path, 30, "utf-8");
83
- return buf;
84
- }
85
- /**
86
- * @param record
87
- * @returns a buffer representing a Zip central header
88
- * @link https://en.wikipedia.org/wiki/ZIP_(file_format)#Central_directory_file_header
89
- */
90
- function centralHeader(record) {
91
- var path = record.path, compression = record.compression, crc32 = record.crc32, compressedSize = record.compressedSize, uncompressedSize = record.uncompressedSize, offset = record.offset;
92
- var filenameSize = utf8size(path);
93
- var buf = Buffer.alloc(46 + filenameSize);
94
- var isFile = !path.endsWith("/");
95
- if (typeof offset === "undefined")
96
- throw new Error("Illegal argument");
97
- // we don't want to deal with possibly messed up file or directory
98
- // permissions, so we ignore the original permissions
99
- var externalAttr = isFile ? 0x81a40000 : 0x41ed0000;
100
- buf.writeUInt32LE(33639248, 0); // central header signature
101
- buf.writeUInt16LE(10, 4); // version
102
- buf.writeUInt16LE(10, 6); // min version
103
- buf.writeUInt16LE(0, 8); // general purpose bit flag
104
- buf.writeUInt16LE(compression ? { "deflate": 8 }[compression] : 0, 10);
105
- buf.writeUInt16LE(0, 12); // modified time
106
- buf.writeUInt16LE(0, 14); // modified date
107
- buf.writeUInt32LE(crc32 || 0, 16);
108
- buf.writeUInt32LE(compressedSize || 0, 20);
109
- buf.writeUInt32LE(uncompressedSize, 24);
110
- buf.writeUInt16LE(filenameSize, 28);
111
- buf.writeUInt16LE(0, 30); // extra field length
112
- buf.writeUInt16LE(0, 32); // comment field length
113
- buf.writeUInt16LE(0, 34); // disk number
114
- buf.writeUInt16LE(0, 36); // internal
115
- buf.writeUInt32LE(externalAttr, 38); // external
116
- buf.writeUInt32LE(offset, 42); // offset where file starts
117
- buf.write(path, 46, "utf-8");
118
- return buf;
119
- }
120
- /**
121
- * @returns a buffer representing an Zip End-Of-Central-Directory block
122
- * @link https://en.wikipedia.org/wiki/ZIP_(file_format)#End_of_central_directory_record_(EOCD)
123
- */
124
- function eocd(_a) {
125
- var offset = _a.offset, cdSize = _a.cdSize, nRecords = _a.nRecords;
126
- var buf = Buffer.alloc(22);
127
- buf.writeUint32LE(0x06054b50, 0); // eocd signature
128
- buf.writeUInt16LE(0, 4); // disc number
129
- buf.writeUint16LE(0, 6); // disc where central directory starts
130
- buf.writeUint16LE(nRecords, 8); // records on this disc
131
- buf.writeUInt16LE(nRecords, 10); // records total
132
- buf.writeUInt32LE(cdSize, 12); // byte size of cd
133
- buf.writeUInt32LE(offset, 16); // cd offset
134
- buf.writeUint16LE(0, 20); // comment length
135
- return buf;
136
- }
137
- /**
138
- * @returns a stream Transform, which reads a stream of ZipRecords and
139
- * writes a bytestream
140
- */
141
- function zip() {
142
- var _this = this;
143
- /**
144
- * This is called when the input stream of ZipSource items is finished.
145
- * Will write central directory and end-of-central-direcotry blocks.
146
- */
147
- var final = function () {
148
- var e_1, _a;
149
- // write central directory
150
- var cdSize = 0;
151
- try {
152
- for (var records_1 = __values(records), records_1_1 = records_1.next(); !records_1_1.done; records_1_1 = records_1.next()) {
153
- var record = records_1_1.value;
154
- var head = centralHeader(record);
155
- zipTransform.push(head);
156
- cdSize += head.length;
157
- }
158
- }
159
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
160
- finally {
161
- try {
162
- if (records_1_1 && !records_1_1.done && (_a = records_1.return)) _a.call(records_1);
163
- }
164
- finally { if (e_1) throw e_1.error; }
165
- }
166
- // write end-of-central-directory
167
- zipTransform.push(eocd({ offset: offset, cdSize: cdSize, nRecords: records.length }));
168
- // signal stream end
169
- zipTransform.push(null);
170
- };
171
- /**
172
- * Write a directory entry to the archive
173
- * @param path
174
- */
175
- var writeDir = function (path) { return __awaiter(_this, void 0, void 0, function () {
176
- var record, head;
177
- return __generator(this, function (_a) {
178
- record = {
179
- path: path + "/",
180
- offset: offset,
181
- compression: undefined,
182
- uncompressedSize: 0
183
- };
184
- head = localHeader(record);
185
- zipTransform.push(head);
186
- records.push(record);
187
- offset += head.length;
188
- return [2 /*return*/];
189
- });
190
- }); };
191
- /**
192
- * Write a file entry to the archive
193
- * @param archivePath path of the file in archive
194
- * @param fsPath path to file on filesystem
195
- * @param size of the actual, uncompressed, file
196
- */
197
- var writeFile = function (archivePath, fsPath, size) { return __awaiter(_this, void 0, void 0, function () {
198
- var record, head, _a, crc32, compressedSize;
199
- return __generator(this, function (_b) {
200
- switch (_b.label) {
201
- case 0:
202
- record = {
203
- path: archivePath,
204
- offset: offset,
205
- compression: "deflate",
206
- uncompressedSize: size
207
- };
208
- head = localHeader(record);
209
- zipTransform.push(head);
210
- return [4 /*yield*/, (0, deflate_1.deflateStream)((0, fs_1.createReadStream)(fsPath), function (chunk) { return zipTransform.push(chunk); })];
211
- case 1:
212
- _a = _b.sent(), crc32 = _a.crc32, compressedSize = _a.compressedSize;
213
- record.crc32 = crc32;
214
- record.compressedSize = compressedSize;
215
- records.push(record);
216
- offset += head.length + compressedSize;
217
- return [2 /*return*/];
218
- }
219
- });
220
- }); };
221
- /**
222
- * Write archive record based on filesystem file or directory
223
- * @param archivePath path of item in archive
224
- * @param fsPath path to item on filesystem
225
- */
226
- var writeFromPath = function (archivePath, fsPath) { return __awaiter(_this, void 0, void 0, function () {
227
- var fileStats, _a;
228
- return __generator(this, function (_b) {
229
- switch (_b.label) {
230
- case 0: return [4 /*yield*/, (0, promises_1.stat)(fsPath)];
231
- case 1:
232
- fileStats = _b.sent();
233
- if (!fileStats.isDirectory()) return [3 /*break*/, 3];
234
- return [4 /*yield*/, writeDir(archivePath)]; /**/
235
- case 2:
236
- _a = _b.sent(); /**/
237
- return [3 /*break*/, 5];
238
- case 3: return [4 /*yield*/, writeFile(archivePath, fsPath, fileStats.size)]; /**/
239
- case 4:
240
- _a = _b.sent(); /**/
241
- _b.label = 5;
242
- case 5:
243
- _a;
244
- return [2 /*return*/];
245
- }
246
- });
247
- }); };
248
- /**
249
- * Write archive record based on data in a buffer
250
- * @param path
251
- * @param data
252
- */
253
- var writeFromBuffer = function (path, data) { return __awaiter(_this, void 0, void 0, function () {
254
- var _a, deflated, crc32, record, head;
255
- return __generator(this, function (_b) {
256
- switch (_b.label) {
257
- case 0: return [4 /*yield*/, (0, deflate_1.deflateBuffer)(data)];
258
- case 1:
259
- _a = _b.sent(), deflated = _a.deflated, crc32 = _a.crc32;
260
- record = {
261
- path: path,
262
- compression: "deflate",
263
- crc32: crc32,
264
- uncompressedSize: data.length,
265
- compressedSize: deflated.length,
266
- offset: offset
267
- };
268
- head = localHeader(record);
269
- zipTransform.push(head);
270
- zipTransform.push(deflated);
271
- records.push(record);
272
- offset += head.length + deflated.length;
273
- return [2 /*return*/];
274
- }
275
- });
276
- }); };
277
- /**
278
- * Write an archive record
279
- * @param source
280
- */
281
- var writeRecord = function (source) { return __awaiter(_this, void 0, void 0, function () {
282
- return __generator(this, function (_a) {
283
- switch (_a.label) {
284
- case 0:
285
- if (!("fsPath" in source)) return [3 /*break*/, 2];
286
- return [4 /*yield*/, writeFromPath(source.path, source.fsPath)];
287
- case 1:
288
- _a.sent();
289
- return [3 /*break*/, 5];
290
- case 2:
291
- if (!("data" in source)) return [3 /*break*/, 4];
292
- return [4 /*yield*/, writeFromBuffer(source.path, source.data)];
293
- case 3:
294
- _a.sent();
295
- return [3 /*break*/, 5];
296
- case 4: throw new Error("Illegal argument " + typeof source + " " + JSON.stringify(source));
297
- case 5: return [2 /*return*/];
298
- }
299
- });
300
- }); };
301
- /**
302
- * The actual stream transform function
303
- * @param source
304
- * @param _ encoding, ignored
305
- * @param cb
306
- */
307
- var transform = function (source, _, cb) { return __awaiter(_this, void 0, void 0, function () {
308
- return __generator(this, function (_a) {
309
- switch (_a.label) {
310
- case 0: return [4 /*yield*/, writeRecord(source)];
311
- case 1:
312
- _a.sent();
313
- cb();
314
- return [2 /*return*/];
315
- }
316
- });
317
- }); };
318
- /** offset and records keep local state during processing */
319
- var offset = 0;
320
- var records = [];
321
- var zipTransform = new stream_1.Transform({
322
- readableObjectMode: false,
323
- writableObjectMode: true,
324
- transform: transform,
325
- final: final
326
- });
327
- return zipTransform;
328
- }
329
- exports.default = zip;
330
- //# sourceMappingURL=zip.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zip.js","sourceRoot":"","sources":["../../src/bin/tools/zip.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAqD;AACrD,yBAAsC;AACtC,wCAAmC;AACnC,iCAA8B;AAE9B,qCAAyD;AAmBzD;;GAEG;AACH,SAAS,QAAQ,CAAC,CAAS;IACvB,OAAO,IAAI,aAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,MAAiB;IAC1B,IAAA,IAAI,GAAoC,MAAM,KAA1C,EAAE,WAAW,GAAuB,MAAM,YAA7B,EAAE,gBAAgB,GAAK,MAAM,iBAAX,CAAY;IACvD,IAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IACpC,IAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC;IAE5C,GAAG,CAAC,aAAa,CAAC,QAAa,EAAE,CAAC,CAAC,CAAC,CAAC,yBAAyB;IAC9D,GAAG,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAA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