@flowscripter/example-cli 2.0.1 → 3.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 +4 -4
- package/package.json +3 -3
- package/src/cli.ts +2 -2
- package/tests/banner_upgrade_hint_test.ts +35 -31
package/bun.lock
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "@flowscripter/example-cli",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@flowscripter/dynamic-cli-framework": "^
|
|
9
|
-
"@flowscripter/dynamic-cli-framework-api": "^
|
|
8
|
+
"@flowscripter/dynamic-cli-framework": "^7.0.1",
|
|
9
|
+
"@flowscripter/dynamic-cli-framework-api": "^4.0.1",
|
|
10
10
|
"@flowscripter/dynamic-plugin-framework": "2.2.9",
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
"packages": {
|
|
24
|
-
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@
|
|
24
|
+
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@7.0.1", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^4.0.1", "@flowscripter/dynamic-plugin-framework": "^2.2.9", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.11.4", "highlight.js": "^11.12.0", "prettier": "^3.9.7", "semver": "^7.8.5", "supports-color": "^11.0.0", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-dWEO8tBBjC1VmKrwFucpZdXoHxg9H2k8esR7xeRkzn4yt3J0fME4W3Skf6H9D05SX7AxQyAmBpgMaQuoRuBLog=="],
|
|
25
25
|
|
|
26
|
-
"@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@
|
|
26
|
+
"@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@4.0.1", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-L1vaJLJiznPQ5szdkNi+5AZ7mHZtGQs1Dt5ZgesE4RK7xkStAOw6iTxXtgM3iZK2jXEhZ0poI5D0GpZpNILwMQ=="],
|
|
27
27
|
|
|
28
28
|
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.2.9", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-CxmVatloVWLSv87ZTk9Ly8QGI4al4ONNgrR4C4AbdHSpQSB3NljGKKF9J9EKQK87wGcNEU9XbyxeYKLNkHLHvQ=="],
|
|
29
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/example-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Simple example CLI using https://github.com/flowscripter/dynamic-cli-framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@flowscripter/dynamic-cli-framework": "^
|
|
28
|
-
"@flowscripter/dynamic-cli-framework-api": "^
|
|
27
|
+
"@flowscripter/dynamic-cli-framework": "^7.0.1",
|
|
28
|
+
"@flowscripter/dynamic-cli-framework-api": "^4.0.1",
|
|
29
29
|
"@flowscripter/dynamic-plugin-framework": "2.2.9"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
package/src/cli.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AsciiBannerGeneratorServiceProvider,
|
|
3
|
-
|
|
3
|
+
createBannerStartupTask,
|
|
4
4
|
DataDumpGeneratorServiceProvider,
|
|
5
5
|
launchMultiCommandCLI,
|
|
6
6
|
SyntaxHighlighterServiceProvider,
|
|
@@ -21,7 +21,6 @@ export async function cli(): Promise<void> {
|
|
|
21
21
|
"example-cli",
|
|
22
22
|
packageJson.version,
|
|
23
23
|
[
|
|
24
|
-
new BannerServiceProvider(50),
|
|
25
24
|
new AsciiBannerGeneratorServiceProvider(45),
|
|
26
25
|
new SyntaxHighlighterServiceProvider(40),
|
|
27
26
|
new TreePrinterServiceProvider(35),
|
|
@@ -74,5 +73,6 @@ export async function cli(): Promise<void> {
|
|
|
74
73
|
},
|
|
75
74
|
},
|
|
76
75
|
},
|
|
76
|
+
[createBannerStartupTask(50)],
|
|
77
77
|
);
|
|
78
78
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import {
|
|
2
|
+
import { createBannerStartupTask } from "@flowscripter/dynamic-cli-framework";
|
|
3
3
|
import {
|
|
4
4
|
ASCII_BANNER_GENERATOR_SERVICE_ID,
|
|
5
|
+
KEY_VALUE_SERVICE_ID,
|
|
5
6
|
PRINTER_SERVICE_ID,
|
|
6
|
-
UPGRADE_SERVICE_ID,
|
|
7
7
|
} from "@flowscripter/dynamic-cli-framework-api";
|
|
8
8
|
import type { Context } from "@flowscripter/dynamic-cli-framework-api";
|
|
9
9
|
|
|
@@ -11,21 +11,21 @@ import type { Context } from "@flowscripter/dynamic-cli-framework-api";
|
|
|
11
11
|
// upgrade-availability hint "(X.Y.Z available, run 'app upgrade')" on the SAME line as
|
|
12
12
|
// "version: X.Y.Z", rather than as a separate line (the pre-fix behaviour).
|
|
13
13
|
//
|
|
14
|
-
// This drives the real, installed
|
|
15
|
-
// src/cli.ts
|
|
16
|
-
//
|
|
14
|
+
// This drives the real, installed banner StartupTask (from createBannerStartupTask(50), the
|
|
15
|
+
// factory example-cli's src/cli.ts now calls following the dynamic-cli-framework
|
|
16
|
+
// service-lifecycle redesign) with a stub KeyValueService reporting a cached "upgrade available"
|
|
17
|
+
// result.
|
|
17
18
|
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// framework's
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
// the actual formatting fix.
|
|
19
|
+
// Following that redesign, the banner no longer calls a live UpgradeService at all - it does a
|
|
20
|
+
// cheap KeyValueService read of the previous run's cached upgrade-check result (see
|
|
21
|
+
// dynamic-cli-framework's bannerStartupTask.ts / UPGRADE_CHECK_CACHE_KEY - an internal cache key,
|
|
22
|
+
// not part of the public API surface, hardcoded below as "upgrade-check-result"; if the
|
|
23
|
+
// framework's internal key ever changes this test needs updating to match). This also removes the
|
|
24
|
+
// original #141 test's race entirely - the opportunistic upgrade check used to run concurrently
|
|
25
|
+
// with, and often lose to, the banner's own priority band - so there's no longer a reason this
|
|
26
|
+
// couldn't also be exercised as a full black-box run; kept as a direct unit test here for speed
|
|
27
|
+
// and because it isolates the formatting fix precisely.
|
|
28
|
+
const UPGRADE_CHECK_CACHE_KEY = "upgrade-check-result";
|
|
29
29
|
|
|
30
30
|
function createStubPrinterService(lines: string[]) {
|
|
31
31
|
const identity = (message: string) => message;
|
|
@@ -48,26 +48,30 @@ function createStubAsciiBannerGeneratorService() {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
function
|
|
51
|
+
function createStubKeyValueService(updateAvailable: boolean, latestVersion: string) {
|
|
52
|
+
const cachedResult = updateAvailable
|
|
53
|
+
? { status: "checked", updateAvailable: true, latestVersion }
|
|
54
|
+
: { status: "checked", updateAvailable: false, latestVersion };
|
|
52
55
|
return {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
has: (key: string) => Promise.resolve(key === UPGRADE_CHECK_CACHE_KEY),
|
|
57
|
+
get: (key: string) =>
|
|
58
|
+
key === UPGRADE_CHECK_CACHE_KEY
|
|
59
|
+
? Promise.resolve(cachedResult)
|
|
60
|
+
: Promise.reject(new Error(`Attempt to access unknown key: ${key}`)),
|
|
61
|
+
set: () => Promise.reject(new Error("not implemented")),
|
|
62
|
+
delete: () => Promise.reject(new Error("not implemented")),
|
|
59
63
|
};
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
function createContext(
|
|
63
67
|
printerService: unknown,
|
|
64
68
|
asciiBannerGeneratorService: unknown,
|
|
65
|
-
|
|
69
|
+
keyValueService: unknown,
|
|
66
70
|
): Context {
|
|
67
71
|
const services: Record<string, unknown> = {
|
|
68
72
|
[PRINTER_SERVICE_ID]: printerService,
|
|
69
73
|
[ASCII_BANNER_GENERATOR_SERVICE_ID]: asciiBannerGeneratorService,
|
|
70
|
-
[
|
|
74
|
+
[KEY_VALUE_SERVICE_ID]: keyValueService,
|
|
71
75
|
};
|
|
72
76
|
return {
|
|
73
77
|
cliConfig: {
|
|
@@ -83,14 +87,14 @@ function createContext(
|
|
|
83
87
|
describe("Banner upgrade hint (dynamic-cli-framework #141)", () => {
|
|
84
88
|
test("prints the upgrade hint on the same line as the version when an upgrade is available", async () => {
|
|
85
89
|
const lines: string[] = [];
|
|
86
|
-
const
|
|
90
|
+
const task = createBannerStartupTask(50);
|
|
87
91
|
const context = createContext(
|
|
88
92
|
createStubPrinterService(lines),
|
|
89
93
|
createStubAsciiBannerGeneratorService(),
|
|
90
|
-
|
|
94
|
+
createStubKeyValueService(true, "99.0.0"),
|
|
91
95
|
);
|
|
92
96
|
|
|
93
|
-
await
|
|
97
|
+
await task.run(context);
|
|
94
98
|
|
|
95
99
|
const versionLine = lines.find((line) => line.includes("version:"));
|
|
96
100
|
expect(versionLine).toBeDefined();
|
|
@@ -99,14 +103,14 @@ describe("Banner upgrade hint (dynamic-cli-framework #141)", () => {
|
|
|
99
103
|
|
|
100
104
|
test("does not print a hint when no upgrade is available", async () => {
|
|
101
105
|
const lines: string[] = [];
|
|
102
|
-
const
|
|
106
|
+
const task = createBannerStartupTask(50);
|
|
103
107
|
const context = createContext(
|
|
104
108
|
createStubPrinterService(lines),
|
|
105
109
|
createStubAsciiBannerGeneratorService(),
|
|
106
|
-
|
|
110
|
+
createStubKeyValueService(false, "1.8.2"),
|
|
107
111
|
);
|
|
108
112
|
|
|
109
|
-
await
|
|
113
|
+
await task.run(context);
|
|
110
114
|
|
|
111
115
|
const versionLine = lines.find((line) => line.includes("version:"));
|
|
112
116
|
expect(versionLine).toBeDefined();
|