@flowscripter/flowscripter-io-cli 1.2.3 → 1.3.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 +9 -1
- package/package.json +1 -1
- package/src/cli.ts +1 -0
- package/src/commands/copy.ts +2 -1
- package/src/commands/delete.ts +2 -1
- package/src/commands/hash.ts +1 -0
- package/src/commands/move.ts +2 -1
- package/src/commands/set-properties.ts +2 -1
- package/tests/commands_test.ts +16 -4
- package/tests/testContext.ts +6 -2
package/README.md
CHANGED
|
@@ -51,7 +51,15 @@ You can download and extract the binary zip files from the
|
|
|
51
51
|
behaviour as `copy`
|
|
52
52
|
- `hash <path> [--algorithm]` - hash a file by piping its readable stream
|
|
53
53
|
through a `Bun.CryptoHasher` (default `sha256`) - demonstrates consuming a
|
|
54
|
-
`pluggable-io-framework` stream directly, outside the framework itself
|
|
54
|
+
`pluggable-io-framework` stream directly, outside the framework itself.
|
|
55
|
+
`--algorithm` is restricted to a curated set (`sha1`, `sha256`, `sha384`,
|
|
56
|
+
`sha512`, `md5`)
|
|
57
|
+
|
|
58
|
+
Any argument omitted on the command line (e.g. running `copy` with no
|
|
59
|
+
`source`/`destination`) is interactively prompted for instead of failing,
|
|
60
|
+
via [dynamic-cli-framework](https://github.com/flowscripter/dynamic-cli-framework)'s
|
|
61
|
+
`ArgumentPrompterService`. Confirmation messages (`copy`, `move`, `delete`,
|
|
62
|
+
`set-properties`) are prefixed with a success icon.
|
|
55
63
|
|
|
56
64
|
All commands operate against a filesystem source/sink provider - rooted at
|
|
57
65
|
`/`, so any absolute or cwd-relative path works, the same as any normal file
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -24,6 +24,7 @@ export async function cli(): Promise<void> {
|
|
|
24
24
|
packageJson.version,
|
|
25
25
|
[new PrettyPrinterServiceProvider(40), new SyntaxHighlighterServiceProvider(35)],
|
|
26
26
|
{
|
|
27
|
+
argumentPrompterServiceEnabled: true,
|
|
27
28
|
pluginServiceEnabled: true,
|
|
28
29
|
pluginServiceRemoteConfig: {
|
|
29
30
|
name: "npmjs",
|
package/src/commands/copy.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Icon,
|
|
2
3
|
PRINTER_SERVICE_ID,
|
|
3
4
|
type Context,
|
|
4
5
|
type PrinterService,
|
|
@@ -51,7 +52,7 @@ const copy: SubCommand = {
|
|
|
51
52
|
} finally {
|
|
52
53
|
await printerService.hideProgressBar(handle);
|
|
53
54
|
}
|
|
54
|
-
await printerService.print(`Copied ${source} to ${destination}\n
|
|
55
|
+
await printerService.print(`Copied ${source} to ${destination}\n`, Icon.SUCCESS);
|
|
55
56
|
} finally {
|
|
56
57
|
await provider[Symbol.asyncDispose]();
|
|
57
58
|
}
|
package/src/commands/delete.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Icon,
|
|
2
3
|
PRINTER_SERVICE_ID,
|
|
3
4
|
type Context,
|
|
4
5
|
type PrinterService,
|
|
@@ -31,7 +32,7 @@ const deleteCommand: SubCommand = {
|
|
|
31
32
|
} finally {
|
|
32
33
|
await printerService.hideSpinner();
|
|
33
34
|
}
|
|
34
|
-
await printerService.print(`Deleted ${path}\n
|
|
35
|
+
await printerService.print(`Deleted ${path}\n`, Icon.SUCCESS);
|
|
35
36
|
} finally {
|
|
36
37
|
await provider[Symbol.asyncDispose]();
|
|
37
38
|
}
|
package/src/commands/hash.ts
CHANGED
package/src/commands/move.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Icon,
|
|
2
3
|
PRINTER_SERVICE_ID,
|
|
3
4
|
type Context,
|
|
4
5
|
type PrinterService,
|
|
@@ -51,7 +52,7 @@ const move: SubCommand = {
|
|
|
51
52
|
} finally {
|
|
52
53
|
await printerService.hideProgressBar(handle);
|
|
53
54
|
}
|
|
54
|
-
await printerService.print(`Moved ${source} to ${destination}\n
|
|
55
|
+
await printerService.print(`Moved ${source} to ${destination}\n`, Icon.SUCCESS);
|
|
55
56
|
} finally {
|
|
56
57
|
await provider[Symbol.asyncDispose]();
|
|
57
58
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Icon,
|
|
2
3
|
PRINTER_SERVICE_ID,
|
|
3
4
|
type Context,
|
|
4
5
|
type PrinterService,
|
|
@@ -40,7 +41,7 @@ const setProperties: SubCommand = {
|
|
|
40
41
|
} finally {
|
|
41
42
|
await printerService.hideSpinner();
|
|
42
43
|
}
|
|
43
|
-
await printerService.print(`Updated properties for ${path}\n
|
|
44
|
+
await printerService.print(`Updated properties for ${path}\n`, Icon.SUCCESS);
|
|
44
45
|
} finally {
|
|
45
46
|
await provider[Symbol.asyncDispose]();
|
|
46
47
|
}
|
package/tests/commands_test.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } fr
|
|
|
2
2
|
import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join, resolve } from "node:path";
|
|
5
|
+
import { Icon } from "@flowscripter/dynamic-cli-framework";
|
|
5
6
|
import copy from "../src/commands/copy.ts";
|
|
6
7
|
import deleteCommand from "../src/commands/delete.ts";
|
|
7
8
|
import getProperties from "../src/commands/get-properties.ts";
|
|
@@ -69,7 +70,7 @@ describe("get-properties", () => {
|
|
|
69
70
|
describe("set-properties", () => {
|
|
70
71
|
test("applies mode", async () => {
|
|
71
72
|
await writeFile(join(root, "a.txt"), "hello");
|
|
72
|
-
const { context } = createStubContext();
|
|
73
|
+
const { context, icons } = createStubContext();
|
|
73
74
|
|
|
74
75
|
await setProperties.execute(context, { path: join(root, "a.txt"), mode: 0o600 });
|
|
75
76
|
|
|
@@ -79,6 +80,7 @@ describe("set-properties", () => {
|
|
|
79
80
|
if (process.platform !== "win32") {
|
|
80
81
|
expect(properties.properties.mode & 0o777).toBe(0o600);
|
|
81
82
|
}
|
|
83
|
+
expect(icons).toEqual([Icon.SUCCESS]);
|
|
82
84
|
});
|
|
83
85
|
|
|
84
86
|
test("shows a spinner while applying properties", async () => {
|
|
@@ -94,13 +96,14 @@ describe("set-properties", () => {
|
|
|
94
96
|
describe("delete", () => {
|
|
95
97
|
test("removes a file", async () => {
|
|
96
98
|
await writeFile(join(root, "a.txt"), "hello");
|
|
97
|
-
const { context } = createStubContext();
|
|
99
|
+
const { context, icons } = createStubContext();
|
|
98
100
|
|
|
99
101
|
await deleteCommand.execute(context, { path: join(root, "a.txt") });
|
|
100
102
|
|
|
101
103
|
const { lines, context: listContext } = createStubContext();
|
|
102
104
|
await list.execute(listContext, { path: root });
|
|
103
105
|
expect(lines.length).toBe(0);
|
|
106
|
+
expect(icons).toEqual([Icon.SUCCESS]);
|
|
104
107
|
});
|
|
105
108
|
|
|
106
109
|
test("shows a spinner while deleting", async () => {
|
|
@@ -116,7 +119,7 @@ describe("delete", () => {
|
|
|
116
119
|
describe("copy", () => {
|
|
117
120
|
test("copies a file", async () => {
|
|
118
121
|
await writeFile(join(root, "a.txt"), "hello");
|
|
119
|
-
const { context } = createStubContext();
|
|
122
|
+
const { context, icons } = createStubContext();
|
|
120
123
|
|
|
121
124
|
await copy.execute(context, { source: join(root, "a.txt"), destination: join(root, "b.txt") });
|
|
122
125
|
|
|
@@ -125,23 +128,32 @@ describe("copy", () => {
|
|
|
125
128
|
await getProperties.execute(getPropsContext, { path: join(root, "b.txt") });
|
|
126
129
|
expect(JSON.parse(getPropsLines[0]!).size).toBe(5);
|
|
127
130
|
expect(lines).toEqual([]);
|
|
131
|
+
expect(icons).toEqual([Icon.SUCCESS]);
|
|
128
132
|
});
|
|
129
133
|
});
|
|
130
134
|
|
|
131
135
|
describe("move", () => {
|
|
132
136
|
test("moves a file", async () => {
|
|
133
137
|
await writeFile(join(root, "a.txt"), "hello");
|
|
134
|
-
const { context } = createStubContext();
|
|
138
|
+
const { context, icons } = createStubContext();
|
|
135
139
|
|
|
136
140
|
await move.execute(context, { source: join(root, "a.txt"), destination: join(root, "b.txt") });
|
|
137
141
|
|
|
138
142
|
const { lines, context: listContext } = createStubContext();
|
|
139
143
|
await list.execute(listContext, { path: root });
|
|
140
144
|
expect(lines.map((line) => JSON.parse(line).path)).toEqual(["b.txt"]);
|
|
145
|
+
expect(icons).toEqual([Icon.SUCCESS]);
|
|
141
146
|
});
|
|
142
147
|
});
|
|
143
148
|
|
|
144
149
|
describe("hash", () => {
|
|
150
|
+
test("algorithm option has a curated set of allowable values", () => {
|
|
151
|
+
const algorithmOption = hash.options.find((option) => option.name === "algorithm") as
|
|
152
|
+
| { allowableValues?: readonly unknown[] }
|
|
153
|
+
| undefined;
|
|
154
|
+
expect(algorithmOption?.allowableValues).toEqual(["sha1", "sha256", "sha384", "sha512", "md5"]);
|
|
155
|
+
});
|
|
156
|
+
|
|
145
157
|
test("hashes a file with the default algorithm using the native hasher", async () => {
|
|
146
158
|
await writeFile(join(root, "a.txt"), "hello");
|
|
147
159
|
const { lines, context } = createStubContext();
|
package/tests/testContext.ts
CHANGED
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
PRINTER_SERVICE_ID,
|
|
6
6
|
SYNTAX_HIGHLIGHTER_SERVICE_ID,
|
|
7
7
|
type Context,
|
|
8
|
+
type Icon,
|
|
8
9
|
type PrinterService,
|
|
9
10
|
} from "@flowscripter/dynamic-cli-framework";
|
|
10
11
|
|
|
11
12
|
export interface StubPrinter {
|
|
12
13
|
lines: string[];
|
|
14
|
+
icons: (Icon | undefined)[];
|
|
13
15
|
spinnerMessages: string[];
|
|
14
16
|
progressUpdates: number[];
|
|
15
17
|
context: Context;
|
|
@@ -26,11 +28,13 @@ export interface StubPrinter {
|
|
|
26
28
|
*/
|
|
27
29
|
export function createStubContext(): StubPrinter {
|
|
28
30
|
const lines: string[] = [];
|
|
31
|
+
const icons: (Icon | undefined)[] = [];
|
|
29
32
|
const spinnerMessages: string[] = [];
|
|
30
33
|
const progressUpdates: number[] = [];
|
|
31
34
|
const printerService = {
|
|
32
|
-
print: async (message: string) => {
|
|
35
|
+
print: async (message: string, icon?: Icon) => {
|
|
33
36
|
lines.push(message);
|
|
37
|
+
icons.push(icon);
|
|
34
38
|
},
|
|
35
39
|
showProgressBar: async () => 0,
|
|
36
40
|
updateProgressBar: (_handle: number, current: number) => {
|
|
@@ -59,5 +63,5 @@ export function createStubContext(): StubPrinter {
|
|
|
59
63
|
doesServiceExist: (id: string) => id in services,
|
|
60
64
|
};
|
|
61
65
|
|
|
62
|
-
return { lines, spinnerMessages, progressUpdates, context };
|
|
66
|
+
return { lines, icons, spinnerMessages, progressUpdates, context };
|
|
63
67
|
}
|