@flowscripter/flowscripter-io-cli 1.3.1 → 2.0.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/bun.lock +8 -8
- package/package.json +3 -3
- package/src/byteScale.ts +16 -1
- package/src/commands/copy.ts +6 -5
- package/src/commands/hash.ts +6 -5
- package/src/commands/move.ts +6 -5
- package/tests/byteScale_test.ts +21 -0
package/bun.lock
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "@flowscripter/flowscripter-io-cli",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@flowscripter/dynamic-cli-framework": "^
|
|
9
|
-
"@flowscripter/dynamic-cli-framework-api": "^
|
|
8
|
+
"@flowscripter/dynamic-cli-framework": "^6.0.0",
|
|
9
|
+
"@flowscripter/dynamic-cli-framework-api": "^3.0.0",
|
|
10
10
|
"@flowscripter/dynamic-plugin-framework": "^2.2.8",
|
|
11
11
|
"@flowscripter/flowscripter-io-cli-hash-native": "^1.0.6",
|
|
12
12
|
"@flowscripter/pluggable-io-framework": "^1.2.1",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
"packages": {
|
|
28
|
-
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@
|
|
28
|
+
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@6.0.0", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^3.0.0", "@flowscripter/dynamic-plugin-framework": "^2.2.8", "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-kaJs2XifprU6gHP+dVSLwvPRD7F5Y3BxnfZWVtRa3lxSzq8sVBxR/YJ5okrTMEncnaGkIFHScabwbSLFVAmJ0g=="],
|
|
29
29
|
|
|
30
|
-
"@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@
|
|
30
|
+
"@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@3.0.0", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-KFJaC9wLlZGYCw4c4doJ2IUukul55bPWHyRiGSHbrp/pEEHmPncdCmcovL3Hmd7Le+6iUm+YjvInrA0kwEBxgw=="],
|
|
31
31
|
|
|
32
|
-
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.2.
|
|
32
|
+
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.2.9", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-CxmVatloVWLSv87ZTk9Ly8QGI4al4ONNgrR4C4AbdHSpQSB3NljGKKF9J9EKQK87wGcNEU9XbyxeYKLNkHLHvQ=="],
|
|
33
33
|
|
|
34
34
|
"@flowscripter/flowscripter-io-cli-hash-native": ["@flowscripter/flowscripter-io-cli-hash-native@1.0.6", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-MSmIPWHzvJlU4V/kPuSVKV5aULBxtv68ep/VtWSdr3QCtyFJHH5qcEDD4iYPhl/+XdeDEfONQ6TLNyHuLPebqA=="],
|
|
35
35
|
|
|
36
|
-
"@flowscripter/io-plugin-filesystem": ["@flowscripter/io-plugin-filesystem@1.1.
|
|
36
|
+
"@flowscripter/io-plugin-filesystem": ["@flowscripter/io-plugin-filesystem@1.1.1", "", { "dependencies": { "@flowscripter/pluggable-io-framework-api": "^1.1.1", "zod": "^4.6.5" }, "peerDependencies": { "@flowscripter/dynamic-plugin-framework": "*", "typescript": "^7.0.2" } }, "sha512-G95TkV33uN35mqsczdbF3jsNLAxhqVxy22jfX7gXL5jTqyt3NxLtMdop+0KbdXOiDBDC2csydz0gUtzIalsmnw=="],
|
|
37
37
|
|
|
38
38
|
"@flowscripter/pluggable-io-framework": ["@flowscripter/pluggable-io-framework@1.2.1", "", { "dependencies": { "@flowscripter/dynamic-plugin-framework": "^2.2.8", "@flowscripter/pluggable-io-framework-api": "^1.1.1" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-nN2vHtj4/fmGtIrmCUqqj2KNGpXsWl/kytf4LWztYonromaDMAxQhhi6OkDzOjBsRs/Z8YK1S3LAm2Y5PxN/7g=="],
|
|
39
39
|
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
|
|
120
120
|
"@types/hast": ["@types/hast@3.0.5", "", { "dependencies": { "@types/unist": "*" } }, "sha512-rp/ezSWaD1m44dPKICGhiskI13nVr7qTloFwDa/IYkhhf5nzwP+zIQcIJh3WIFSBOy/H1PzB40jPjMDksN4F+g=="],
|
|
121
121
|
|
|
122
|
-
"@types/node": ["@types/node@26.
|
|
122
|
+
"@types/node": ["@types/node@26.6.1", "", { "dependencies": { "undici-types": "~8.9.0" } }, "sha512-VqGJBMCtdhqkBUCcBLvywI0NJ+KLuVzgNnlBUNFOQjqVxzo2lxLUNg1DSey8+u2u6ktswSAxg+s68QLzWHNOuA=="],
|
|
123
123
|
|
|
124
124
|
"@types/unist": ["@types/unist@3.0.3", "", {}, "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q=="],
|
|
125
125
|
|
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
|
|
188
188
|
"oxlint": ["oxlint@1.82.0", "", { "optionalDependencies": { "@oxlint/binding-android-arm-eabi": "1.82.0", "@oxlint/binding-android-arm64": "1.82.0", "@oxlint/binding-darwin-arm64": "1.82.0", "@oxlint/binding-darwin-x64": "1.82.0", "@oxlint/binding-freebsd-x64": "1.82.0", "@oxlint/binding-linux-arm-gnueabihf": "1.82.0", "@oxlint/binding-linux-arm-musleabihf": "1.82.0", "@oxlint/binding-linux-arm64-gnu": "1.82.0", "@oxlint/binding-linux-arm64-musl": "1.82.0", "@oxlint/binding-linux-ppc64-gnu": "1.82.0", "@oxlint/binding-linux-riscv64-gnu": "1.82.0", "@oxlint/binding-linux-riscv64-musl": "1.82.0", "@oxlint/binding-linux-s390x-gnu": "1.82.0", "@oxlint/binding-linux-x64-gnu": "1.82.0", "@oxlint/binding-linux-x64-musl": "1.82.0", "@oxlint/binding-openharmony-arm64": "1.82.0", "@oxlint/binding-win32-arm64-msvc": "1.82.0", "@oxlint/binding-win32-ia32-msvc": "1.82.0", "@oxlint/binding-win32-x64-msvc": "1.82.0" }, "peerDependencies": { "oxlint-tsgolint": ">=7.0.2001", "vite-plus": "*" }, "optionalPeers": ["oxlint-tsgolint", "vite-plus"], "bin": { "oxlint": "bin/oxlint" } }, "sha512-+iFM1BGw1ntYJt3QngbJmjbrGxPaKMUADOXOijpWGnYcBPq8YZnQftSS1C+pVcDYy9YxqDVJKQqQkTazTQMboQ=="],
|
|
189
189
|
|
|
190
|
-
"prettier": ["prettier@3.9.
|
|
190
|
+
"prettier": ["prettier@3.9.7", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-T3mF5P7HFzZVLDQuCUNtJj6WK1pcpLMweMNUVwGb01bLNkH9AkKxtZvmInw8K6bnn2O3d6/5RHl6zSHiBAD0Og=="],
|
|
191
191
|
|
|
192
192
|
"semver": ["semver@7.8.5", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA=="],
|
|
193
193
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/flowscripter-io-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Example CLI using https://github.com/flowscripter/pluggable-io-framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@flowscripter/dynamic-cli-framework": "^
|
|
25
|
-
"@flowscripter/dynamic-cli-framework-api": "^
|
|
24
|
+
"@flowscripter/dynamic-cli-framework": "^6.0.0",
|
|
25
|
+
"@flowscripter/dynamic-cli-framework-api": "^3.0.0",
|
|
26
26
|
"@flowscripter/dynamic-plugin-framework": "^2.2.8",
|
|
27
27
|
"@flowscripter/flowscripter-io-cli-hash-native": "^1.0.6",
|
|
28
28
|
"@flowscripter/pluggable-io-framework": "^1.2.1",
|
package/src/byteScale.ts
CHANGED
|
@@ -16,11 +16,26 @@ export interface ByteScale {
|
|
|
16
16
|
readonly unit: string;
|
|
17
17
|
readonly total: number;
|
|
18
18
|
scale(bytes: number): number;
|
|
19
|
+
/** Formats an already-scaled current/total value, e.g. `5.00GB`. */
|
|
20
|
+
format(value: number): string;
|
|
21
|
+
/**
|
|
22
|
+
* Formats a rate (in this scale's unit per second) independently of {@link format} - converts
|
|
23
|
+
* back to raw bytes/s and re-picks the best-fitting unit, so a rate too small to show
|
|
24
|
+
* meaningfully in the total's unit (e.g. a stalled GB-scale transfer) renders in a smaller one
|
|
25
|
+
* instead of rounding to zero.
|
|
26
|
+
*/
|
|
27
|
+
formatRate(rate: number): string;
|
|
19
28
|
}
|
|
20
29
|
|
|
21
30
|
/** Scales byte counts against a fixed total into the largest sensible unit (bytes/KB/MB/GB). */
|
|
22
31
|
export function createByteScale(totalBytes: number): ByteScale {
|
|
23
32
|
const { unit, divisor } = pickByteUnit(totalBytes);
|
|
24
33
|
const scale = (bytes: number): number => Math.round((bytes / divisor) * 100) / 100;
|
|
25
|
-
|
|
34
|
+
const format = (value: number): string => `${value.toFixed(2)}${unit}`;
|
|
35
|
+
const formatRate = (rate: number): string => {
|
|
36
|
+
const bytesPerSecond = rate * divisor;
|
|
37
|
+
const rateUnit = pickByteUnit(bytesPerSecond);
|
|
38
|
+
return `${(bytesPerSecond / rateUnit.divisor).toFixed(2)}${rateUnit.unit}/s`;
|
|
39
|
+
};
|
|
40
|
+
return { unit, total: scale(totalBytes), scale, format, formatRate };
|
|
26
41
|
}
|
package/src/commands/copy.ts
CHANGED
|
@@ -36,11 +36,12 @@ const copy: SubCommand = {
|
|
|
36
36
|
try {
|
|
37
37
|
const { size } = await provider.getProperties(source);
|
|
38
38
|
const byteScale = createByteScale(size ?? 100);
|
|
39
|
-
const handle = await printerService.showProgressBar(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
byteScale.
|
|
43
|
-
|
|
39
|
+
const handle = await printerService.showProgressBar({
|
|
40
|
+
message: `Copying ${source}`,
|
|
41
|
+
total: byteScale.total,
|
|
42
|
+
format: byteScale.format,
|
|
43
|
+
formatRate: byteScale.formatRate,
|
|
44
|
+
});
|
|
44
45
|
try {
|
|
45
46
|
await copyProvider(provider, source, provider, destination, {
|
|
46
47
|
telemetry: {
|
package/src/commands/hash.ts
CHANGED
|
@@ -41,11 +41,12 @@ const hash: SubCommand = {
|
|
|
41
41
|
try {
|
|
42
42
|
const { size } = await provider.getProperties(path);
|
|
43
43
|
const byteScale = createByteScale(size ?? 100);
|
|
44
|
-
const progressHandle = await printerService.showProgressBar(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
byteScale.
|
|
48
|
-
|
|
44
|
+
const progressHandle = await printerService.showProgressBar({
|
|
45
|
+
message: `Hashing ${path}`,
|
|
46
|
+
total: byteScale.total,
|
|
47
|
+
format: byteScale.format,
|
|
48
|
+
formatRate: byteScale.formatRate,
|
|
49
|
+
});
|
|
49
50
|
let bytesProcessed = 0;
|
|
50
51
|
const onChunk = (chunkLength: number): void => {
|
|
51
52
|
bytesProcessed += chunkLength;
|
package/src/commands/move.ts
CHANGED
|
@@ -36,11 +36,12 @@ const move: SubCommand = {
|
|
|
36
36
|
try {
|
|
37
37
|
const { size } = await provider.getProperties(source);
|
|
38
38
|
const byteScale = createByteScale(size ?? 100);
|
|
39
|
-
const handle = await printerService.showProgressBar(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
byteScale.
|
|
43
|
-
|
|
39
|
+
const handle = await printerService.showProgressBar({
|
|
40
|
+
message: `Moving ${source}`,
|
|
41
|
+
total: byteScale.total,
|
|
42
|
+
format: byteScale.format,
|
|
43
|
+
formatRate: byteScale.formatRate,
|
|
44
|
+
});
|
|
44
45
|
try {
|
|
45
46
|
await moveProvider(provider, source, provider, destination, {
|
|
46
47
|
telemetry: {
|
package/tests/byteScale_test.ts
CHANGED
|
@@ -26,4 +26,25 @@ describe("createByteScale", () => {
|
|
|
26
26
|
expect(byteScale.total).toBe(500);
|
|
27
27
|
expect(byteScale.scale(250)).toBe(250);
|
|
28
28
|
});
|
|
29
|
+
|
|
30
|
+
test("format() appends the total's unit to an already-scaled value", () => {
|
|
31
|
+
const byteScale = createByteScale(20_641_497_116);
|
|
32
|
+
|
|
33
|
+
expect(byteScale.format(byteScale.total)).toBe("19.22GB");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("formatRate() re-scales to a smaller unit when the rate is too small for the total's unit", () => {
|
|
37
|
+
const byteScale = createByteScale(20_641_497_116);
|
|
38
|
+
|
|
39
|
+
// 512KB/s expressed in GB/s (524288 / 1024^3) is real throughput, but would round to
|
|
40
|
+
// "0.00GB/s" if formatted in the total's unit - formatRate() converts back to raw bytes/s
|
|
41
|
+
// and re-picks a unit for that value.
|
|
42
|
+
expect(byteScale.formatRate(524_288 / 1024 ** 3)).toBe("512.00KB/s");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("formatRate() stays in the total's unit when the rate is large enough for it", () => {
|
|
46
|
+
const byteScale = createByteScale(20_641_497_116);
|
|
47
|
+
|
|
48
|
+
expect(byteScale.formatRate(1.5)).toBe("1.50GB/s");
|
|
49
|
+
});
|
|
29
50
|
});
|