@flowscripter/flowscripter-io-cli 1.2.0 → 1.2.2

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/bun.lock CHANGED
@@ -5,16 +5,16 @@
5
5
  "": {
6
6
  "name": "@flowscripter/flowscripter-io-cli",
7
7
  "dependencies": {
8
- "@flowscripter/dynamic-cli-framework": "^5.4.2",
9
- "@flowscripter/dynamic-cli-framework-api": "^2.3.3",
10
- "@flowscripter/dynamic-plugin-framework": "^2.2.4",
11
- "@flowscripter/flowscripter-io-cli-hash-native": "^1.0.0",
12
- "@flowscripter/pluggable-io-framework": "^1.1.3",
13
- "@flowscripter/pluggable-io-framework-api": "^1.0.7",
8
+ "@flowscripter/dynamic-cli-framework": "^5.4.3",
9
+ "@flowscripter/dynamic-cli-framework-api": "^2.3.4",
10
+ "@flowscripter/dynamic-plugin-framework": "^2.2.5",
11
+ "@flowscripter/flowscripter-io-cli-hash-native": "^1.0.2",
12
+ "@flowscripter/pluggable-io-framework": "^1.1.4",
13
+ "@flowscripter/pluggable-io-framework-api": "^1.0.8",
14
14
  },
15
15
  "devDependencies": {
16
- "@flowscripter/io-plugin-filesystem": "^1.0.4",
17
- "@types/bun": "^1.4.0",
16
+ "@flowscripter/io-plugin-filesystem": "^1.0.5",
17
+ "@types/bun": "^1.4.1",
18
18
  "@types/node": "^26.4.1",
19
19
  "oxfmt": "0.66.0",
20
20
  "oxlint": "1.81.0",
@@ -25,19 +25,19 @@
25
25
  },
26
26
  },
27
27
  "packages": {
28
- "@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@5.4.2", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^2.3.3", "@flowscripter/dynamic-plugin-framework": "^2.2.4", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.11.4", "highlight.js": "^11.12.0", "prettier": "^3.9.6", "semver": "^7.8.5", "supports-color": "^11.0.0", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-gM4l7hHfIDivQfk0pR8Zx7BGZCQBIEqM2aJMGM7RA/oAaZkgs6SCFEwdwnBKO8/JhYsRA3YgDs5nAhZHIpWixg=="],
28
+ "@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@5.4.3", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^2.3.4", "@flowscripter/dynamic-plugin-framework": "^2.2.5", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.11.4", "highlight.js": "^11.12.0", "prettier": "^3.9.6", "semver": "^7.8.5", "supports-color": "^11.0.0", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-eAOFJkHIKTHupUJXg+ooC+79AMkbPamsAykVGBeqIc+CbqvOvG4sOZ7YYNn0s9Bl9j9Bi0Z0e0py31Q8nBnXQA=="],
29
29
 
30
- "@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@2.3.3", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-1MI95fd8ifiqnAxh1tmswdo2Ql6O66BRsevsScoAEdnPjMqmeTTzinwDEiHMFwqLhQH2SZ/16TrdRvOQTWaWEw=="],
30
+ "@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@2.3.4", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-IisiSF13BYxvnISWM4Y9OaKiTMulPJO/Q6Ahx1yzZdfnradCSwcZJVE3QeiMuP9mkiVF4/8LpJcn1DEm4UOqLA=="],
31
31
 
32
- "@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.2.4", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-OZ2a4j6OBzU8QiP3aQ8zeUmb5c9JJdRXXTGRmzlhhZEanpDcHsUxYa8mDUJABO3ThG2JoKjzmD8/K2b0xT5RSQ=="],
32
+ "@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.2.5", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-ERH7Rqb9H5n2Klupf6V7Mo/Ae/CQXKwaqTJq+QQQLY+mlcHBJ2LfAY0Wgc/BRSHpCGXgYQcnRpi/fQ36v6RAMw=="],
33
33
 
34
- "@flowscripter/flowscripter-io-cli-hash-native": ["@flowscripter/flowscripter-io-cli-hash-native@1.0.0", "", { "peerDependencies": { "typescript": "^6.0.3" } }, "sha512-Tx5zaGnqQDHKo209qmaqPGIjXA0pcY7I3o4JnheMoKFF894Gtq0l1nqA8sEQ70lFwIoQN+oD40mGFrtUSwv1wg=="],
34
+ "@flowscripter/flowscripter-io-cli-hash-native": ["@flowscripter/flowscripter-io-cli-hash-native@1.0.2", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-5OKAKwwopy/3WS5/MfVUAwyzCi3jOlh6rbb4OssB5M5Fp4Cl0KW7Rq5FBZIZtH9E/JVRSZhb5ideP6cRuVtxVQ=="],
35
35
 
36
- "@flowscripter/io-plugin-filesystem": ["@flowscripter/io-plugin-filesystem@1.0.4", "", { "dependencies": { "@flowscripter/pluggable-io-framework-api": "^1.0.6", "zod": "^4.5.4" }, "peerDependencies": { "@flowscripter/dynamic-plugin-framework": "*", "typescript": "^7.0.2" } }, "sha512-6ZrTZB3nwZPV/x9At/zC47P1cO/fHx6Rw4sLzqvyoNfXrCx9jFdwwqc0ZA/HaCpuWUS2lZ48rcX65cEDJeO9yg=="],
36
+ "@flowscripter/io-plugin-filesystem": ["@flowscripter/io-plugin-filesystem@1.0.5", "", { "dependencies": { "@flowscripter/pluggable-io-framework-api": "^1.0.7", "zod": "^4.5.4" }, "peerDependencies": { "@flowscripter/dynamic-plugin-framework": "*", "typescript": "^7.0.2" } }, "sha512-TJypyr66DkVQoHx1c+AAioCh3pvWEQSPtAuWJFVAlj9YqW37BFNg914K6dcu95ssqsaoK9JmWud6JdBIwXeE7Q=="],
37
37
 
38
- "@flowscripter/pluggable-io-framework": ["@flowscripter/pluggable-io-framework@1.1.3", "", { "dependencies": { "@flowscripter/dynamic-plugin-framework": "^2.2.4", "@flowscripter/pluggable-io-framework-api": "^1.0.7" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-L2tDVt18rSVPCcvH357I4Td9EcWh+nS7S54Gpr/xgmeFpAEDn3jrtzMWFaGhW50TdgVUnFy/wFPC7H3SOUQL7w=="],
38
+ "@flowscripter/pluggable-io-framework": ["@flowscripter/pluggable-io-framework@1.1.4", "", { "dependencies": { "@flowscripter/dynamic-plugin-framework": "^2.2.5", "@flowscripter/pluggable-io-framework-api": "^1.0.8" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-WRSqUmWL4EY5sYFfyJDn4wJ8FzqdphbfR5MKmXYI+H4Wd24bV5ycL4v++9daU3zf+bnIxq64yvzu6XVvRKuSmg=="],
39
39
 
40
- "@flowscripter/pluggable-io-framework-api": ["@flowscripter/pluggable-io-framework-api@1.0.7", "", { "dependencies": { "zod": "^4.5.4", "zod-to-json-schema": "^3.25.2" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-Mz+8Px8iSxHwBiKjIuxoEHMHEQX0bxBjDNT1O8SWASgkfc7aO1uEvGjMvg4wKifCmp104KisJ355ztJnD5ujvQ=="],
40
+ "@flowscripter/pluggable-io-framework-api": ["@flowscripter/pluggable-io-framework-api@1.0.8", "", { "dependencies": { "zod": "^4.5.4", "zod-to-json-schema": "^3.25.2" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-7Orem6KGWCjn+kLhdI0AiGBXrxaahModxdkzgkDPC33d6rU5AraNkJMfD1hYPbqp19ipy9y95xzV2amA2/13FQ=="],
41
41
 
42
42
  "@oxfmt/binding-android-arm-eabi": ["@oxfmt/binding-android-arm-eabi@0.66.0", "", { "os": "android", "cpu": "arm" }, "sha512-2Me9eoptv6ERdEuI2P8AOlYdHHraXebJaM6SC0kc2Dfb+mLrep2db+fedBPKaYn673h/vBgvP4tkOdAbaudX6w=="],
43
43
 
@@ -115,7 +115,7 @@
115
115
 
116
116
  "@oxlint/binding-win32-x64-msvc": ["@oxlint/binding-win32-x64-msvc@1.81.0", "", { "os": "win32", "cpu": "x64" }, "sha512-IZuUCwGw9emG5JtCp+fYGB+Z4OWEoeEcM8R5BA1pYw63/ieYFVdcU2ylxTpHbVHSenZnsYE+ZZ20uHAJszQ4cA=="],
117
117
 
118
- "@types/bun": ["@types/bun@1.4.0", "", { "dependencies": { "bun-types": "1.4.0" } }, "sha512-K+lZULY23vRgK/CfTjFIV+tyifaNdSMlPh9j+6mQ/cLfpOznLyAuzgV/JQysyECpkBQLVMSyvjlr2fBUSA9wFQ=="],
118
+ "@types/bun": ["@types/bun@1.4.1", "", { "dependencies": { "bun-types": "1.4.1" } }, "sha512-0AVGiTXGajf1rgKom3N+c5L7CBxuoyyv1i44M0nX4UDK0G/fnRAMiri93nHuVPIb429KKtAgj7HatVmmOjeQLA=="],
119
119
 
120
120
  "@types/hast": ["@types/hast@3.0.5", "", { "dependencies": { "@types/unist": "*" } }, "sha512-rp/ezSWaD1m44dPKICGhiskI13nVr7qTloFwDa/IYkhhf5nzwP+zIQcIJh3WIFSBOy/H1PzB40jPjMDksN4F+g=="],
121
121
 
@@ -163,7 +163,7 @@
163
163
 
164
164
  "@typescript/typescript-win32-x64": ["@typescript/typescript-win32-x64@7.0.2", "", { "os": "win32", "cpu": "x64" }, "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g=="],
165
165
 
166
- "bun-types": ["bun-types@1.4.0", "", { "dependencies": { "@types/node": "*" } }, "sha512-iIKw23BspnQQYd3prITOBxeUsxBHnwzX6YJfGMuNOZzeNcMmVqzIIVGRm1l69ogaPQmb4wB6BN8mA5bE9YuC5Q=="],
166
+ "bun-types": ["bun-types@1.4.1", "", { "dependencies": { "@types/node": "*" } }, "sha512-loKuVrAFZKfEv+JvWkHRS9GW5IqLuLRjVXN9p+vZvBN86O5hf/pBZQ5hSoyipsrMmWObZBDvWnlmKvjKTM0PdA=="],
167
167
 
168
168
  "chalk": ["chalk@5.6.2", "", {}, "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA=="],
169
169
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowscripter/flowscripter-io-cli",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Example CLI using https://github.com/flowscripter/pluggable-io-framework",
5
5
  "keywords": [
6
6
  "bun",
@@ -21,16 +21,16 @@
21
21
  "access": "public"
22
22
  },
23
23
  "dependencies": {
24
- "@flowscripter/dynamic-cli-framework": "^5.4.2",
25
- "@flowscripter/dynamic-cli-framework-api": "^2.3.3",
26
- "@flowscripter/dynamic-plugin-framework": "^2.2.4",
27
- "@flowscripter/flowscripter-io-cli-hash-native": "^1.0.0",
28
- "@flowscripter/pluggable-io-framework": "^1.1.3",
29
- "@flowscripter/pluggable-io-framework-api": "^1.0.7"
24
+ "@flowscripter/dynamic-cli-framework": "^5.4.3",
25
+ "@flowscripter/dynamic-cli-framework-api": "^2.3.4",
26
+ "@flowscripter/dynamic-plugin-framework": "^2.2.5",
27
+ "@flowscripter/flowscripter-io-cli-hash-native": "^1.0.2",
28
+ "@flowscripter/pluggable-io-framework": "^1.1.4",
29
+ "@flowscripter/pluggable-io-framework-api": "^1.0.8"
30
30
  },
31
31
  "devDependencies": {
32
- "@flowscripter/io-plugin-filesystem": "^1.0.4",
33
- "@types/bun": "^1.4.0",
32
+ "@flowscripter/io-plugin-filesystem": "^1.0.5",
33
+ "@types/bun": "^1.4.1",
34
34
  "@types/node": "^26.4.1",
35
35
  "oxfmt": "0.66.0",
36
36
  "oxlint": "1.81.0"
@@ -0,0 +1,26 @@
1
+ const BYTE_UNITS: ReadonlyArray<{ unit: string; divisor: number }> = [
2
+ { unit: "GB", divisor: 1024 ** 3 },
3
+ { unit: "MB", divisor: 1024 ** 2 },
4
+ { unit: "KB", divisor: 1024 },
5
+ { unit: "bytes", divisor: 1 },
6
+ ];
7
+
8
+ /** Picks the largest unit that keeps `totalBytes` at 1 or more, so the scaled total isn't < 1. */
9
+ export function pickByteUnit(totalBytes: number): { unit: string; divisor: number } {
10
+ return (
11
+ BYTE_UNITS.find(({ divisor }) => totalBytes >= divisor) ?? BYTE_UNITS[BYTE_UNITS.length - 1]!
12
+ );
13
+ }
14
+
15
+ export interface ByteScale {
16
+ readonly unit: string;
17
+ readonly total: number;
18
+ scale(bytes: number): number;
19
+ }
20
+
21
+ /** Scales byte counts against a fixed total into the largest sensible unit (bytes/KB/MB/GB). */
22
+ export function createByteScale(totalBytes: number): ByteScale {
23
+ const { unit, divisor } = pickByteUnit(totalBytes);
24
+ const scale = (bytes: number): number => Math.round((bytes / divisor) * 100) / 100;
25
+ return { unit, total: scale(totalBytes), scale };
26
+ }
@@ -8,6 +8,7 @@ import {
8
8
  } from "@flowscripter/dynamic-cli-framework";
9
9
  import { copy as copyProvider } from "@flowscripter/pluggable-io-framework";
10
10
  import { getFilesystemProvider } from "../filesystemProvider.ts";
11
+ import { createByteScale } from "../byteScale.ts";
11
12
 
12
13
  const copy: SubCommand = {
13
14
  name: "copy",
@@ -33,16 +34,17 @@ const copy: SubCommand = {
33
34
  const provider = await getFilesystemProvider("");
34
35
  try {
35
36
  const { size } = await provider.getProperties(source);
37
+ const byteScale = createByteScale(size ?? 100);
36
38
  const handle = await printerService.showProgressBar(
37
- "bytes",
39
+ byteScale.unit,
38
40
  `Copying ${source}`,
39
- size ?? 100,
41
+ byteScale.total,
40
42
  );
41
43
  try {
42
44
  await copyProvider(provider, source, provider, destination, {
43
45
  telemetry: {
44
46
  onProgress: (event) => {
45
- printerService.updateProgressBar(handle, event.bytesProcessed);
47
+ printerService.updateProgressBar(handle, byteScale.scale(event.bytesProcessed));
46
48
  },
47
49
  },
48
50
  });
@@ -9,6 +9,7 @@ import {
9
9
  import { ChunkKind, type ChunkRef } from "@flowscripter/pluggable-io-framework-api";
10
10
  import { Sha256Hasher } from "@flowscripter/flowscripter-io-cli-hash-native";
11
11
  import { getFilesystemProvider } from "../filesystemProvider.ts";
12
+ import { createByteScale } from "../byteScale.ts";
12
13
 
13
14
  const hash: SubCommand = {
14
15
  name: "hash",
@@ -38,15 +39,16 @@ const hash: SubCommand = {
38
39
  const provider = await getFilesystemProvider("");
39
40
  try {
40
41
  const { size } = await provider.getProperties(path);
42
+ const byteScale = createByteScale(size ?? 100);
41
43
  const progressHandle = await printerService.showProgressBar(
42
- "bytes",
44
+ byteScale.unit,
43
45
  `Hashing ${path}`,
44
- size ?? 100,
46
+ byteScale.total,
45
47
  );
46
48
  let bytesProcessed = 0;
47
49
  const onChunk = (chunkLength: number): void => {
48
50
  bytesProcessed += chunkLength;
49
- printerService.updateProgressBar(progressHandle, bytesProcessed);
51
+ printerService.updateProgressBar(progressHandle, byteScale.scale(bytesProcessed));
50
52
  };
51
53
  try {
52
54
  const handle = await provider.getReadableStream(path);
@@ -8,6 +8,7 @@ import {
8
8
  } from "@flowscripter/dynamic-cli-framework";
9
9
  import { move as moveProvider } from "@flowscripter/pluggable-io-framework";
10
10
  import { getFilesystemProvider } from "../filesystemProvider.ts";
11
+ import { createByteScale } from "../byteScale.ts";
11
12
 
12
13
  const move: SubCommand = {
13
14
  name: "move",
@@ -33,12 +34,17 @@ const move: SubCommand = {
33
34
  const provider = await getFilesystemProvider("");
34
35
  try {
35
36
  const { size } = await provider.getProperties(source);
36
- const handle = await printerService.showProgressBar("bytes", `Moving ${source}`, size ?? 100);
37
+ const byteScale = createByteScale(size ?? 100);
38
+ const handle = await printerService.showProgressBar(
39
+ byteScale.unit,
40
+ `Moving ${source}`,
41
+ byteScale.total,
42
+ );
37
43
  try {
38
44
  await moveProvider(provider, source, provider, destination, {
39
45
  telemetry: {
40
46
  onProgress: (event) => {
41
- printerService.updateProgressBar(handle, event.bytesProcessed);
47
+ printerService.updateProgressBar(handle, byteScale.scale(event.bytesProcessed));
42
48
  },
43
49
  },
44
50
  });
@@ -0,0 +1,29 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { createByteScale, pickByteUnit } from "../src/byteScale.ts";
3
+
4
+ describe("pickByteUnit", () => {
5
+ test("scales to the largest unit that keeps the total at 1 or more", () => {
6
+ expect(pickByteUnit(500)).toEqual({ unit: "bytes", divisor: 1 });
7
+ expect(pickByteUnit(1024)).toEqual({ unit: "KB", divisor: 1024 });
8
+ expect(pickByteUnit(1024 ** 2)).toEqual({ unit: "MB", divisor: 1024 ** 2 });
9
+ expect(pickByteUnit(20_641_497_116)).toEqual({ unit: "GB", divisor: 1024 ** 3 });
10
+ });
11
+ });
12
+
13
+ describe("createByteScale", () => {
14
+ test("scales the total and subsequent values into the picked unit", () => {
15
+ const byteScale = createByteScale(20_641_497_116);
16
+
17
+ expect(byteScale.unit).toBe("GB");
18
+ expect(byteScale.total).toBeCloseTo(19.22, 2);
19
+ expect(byteScale.scale(13_817_151_488)).toBeCloseTo(12.87, 2);
20
+ });
21
+
22
+ test("keeps small totals in bytes", () => {
23
+ const byteScale = createByteScale(500);
24
+
25
+ expect(byteScale.unit).toBe("bytes");
26
+ expect(byteScale.total).toBe(500);
27
+ expect(byteScale.scale(250)).toBe(250);
28
+ });
29
+ });