@flowscripter/example-cli 1.8.2 → 1.8.4

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,9 +5,9 @@
5
5
  "": {
6
6
  "name": "@flowscripter/example-cli",
7
7
  "dependencies": {
8
- "@flowscripter/dynamic-cli-framework": "5.0.5",
8
+ "@flowscripter/dynamic-cli-framework": "5.1.1",
9
9
  "@flowscripter/dynamic-cli-framework-api": "^1.5.0",
10
- "@flowscripter/dynamic-plugin-framework": "2.0.3",
10
+ "@flowscripter/dynamic-plugin-framework": "2.1.1",
11
11
  },
12
12
  "devDependencies": {
13
13
  "@types/bun": "^1.3.14",
@@ -21,11 +21,11 @@
21
21
  },
22
22
  },
23
23
  "packages": {
24
- "@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@5.0.5", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^2.0.0", "@flowscripter/dynamic-plugin-framework": "2.0.3", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.11.0", "highlight.js": "^11.11.1", "prettier": "^3.9.4", "semver": "^7.7.3", "supports-color": "^10.2.2", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^6.0.3" } }, "sha512-Rz5vJ7oDse4TRgC6l/cUdOO4e+9MPraVyGogWntdX+hSq+7akX+H4p4P+BlzuwyHwR/zDcjZZ2GOwdCtt36lmg=="],
24
+ "@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@5.1.1", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^2.0.0", "@flowscripter/dynamic-plugin-framework": "2.1.1", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.11.0", "highlight.js": "^11.11.1", "prettier": "^3.9.4", "semver": "^7.7.3", "supports-color": "^10.2.2", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^6.0.3" } }, "sha512-g/GVKxyWmGMzf/exd8th0xTBXmj2vyRNStUAjP1cBkxtz8SOpwXDinSE/rgbElaPQGo43HlLFyoHqriWQHKdbQ=="],
25
25
 
26
26
  "@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@1.5.0", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-Tjs5rtaL7kEVZAdO2bM1vdbzCp5R5qGJxRFif6T1uilV5qQaVF92t1R90ndjSSb9G9KnyTDdhHe+NbpDOllvtA=="],
27
27
 
28
- "@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.0.3", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-qyQn+4v/T0ugsdYRFPsvIU7z2nvY2D0ZVPJ9ZdW0KJCFImY1VB/2fYtCBVTjHK339QXcYM+jBHv5Pvuf0emgEw=="],
28
+ "@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.1.1", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-0fHxgPAsb1xrnv3J8YdNtK0eOhTuKzM6J/fU4IYJEj5y8qlj7v1SZIO3+jvN3y8aEgYRxd6B2GAfXKk9WGR2Pg=="],
29
29
 
30
30
  "@oxfmt/binding-android-arm-eabi": ["@oxfmt/binding-android-arm-eabi@0.56.0", "", { "os": "android", "cpu": "arm" }, "sha512-CSCxi7ovYojgfdPOdUb9T508HKeAdDIKeRGg7x8IZwVJrWz9gVgX7MbUnFqtQAE4QvoNo07mj2JlwnOzJw4qqA=="],
31
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowscripter/example-cli",
3
- "version": "1.8.2",
3
+ "version": "1.8.4",
4
4
  "description": "Simple example CLI using https://github.com/flowscripter/dynamic-cli-framework",
5
5
  "keywords": [
6
6
  "bun",
@@ -24,9 +24,9 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@flowscripter/dynamic-cli-framework": "5.0.5",
27
+ "@flowscripter/dynamic-cli-framework": "5.1.1",
28
28
  "@flowscripter/dynamic-cli-framework-api": "^1.5.0",
29
- "@flowscripter/dynamic-plugin-framework": "2.0.3"
29
+ "@flowscripter/dynamic-plugin-framework": "2.1.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/bun": "^1.3.14",
@@ -0,0 +1,116 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { BannerServiceProvider } from "@flowscripter/dynamic-cli-framework";
3
+ import {
4
+ ASCII_BANNER_GENERATOR_SERVICE_ID,
5
+ PRINTER_SERVICE_ID,
6
+ UPGRADE_SERVICE_ID,
7
+ } from "@flowscripter/dynamic-cli-framework-api";
8
+ import type { Context } from "@flowscripter/dynamic-cli-framework-api";
9
+
10
+ // Functional test for dynamic-cli-framework#141: the startup banner must print the
11
+ // upgrade-availability hint "(X.Y.Z available, run 'app upgrade')" on the SAME line as
12
+ // "version: X.Y.Z", rather than as a separate line (the pre-fix behaviour).
13
+ //
14
+ // This drives the real, installed BannerServiceProvider@5.0.6 - the exact class example-cli's
15
+ // src/cli.ts instantiates (`new BannerServiceProvider(50)`) - with a stub UpgradeService that
16
+ // reports an upgrade as available.
17
+ //
18
+ // Why not a full black-box run of the built executable (as the #142 test below does)? Because in
19
+ // the real running CLI, BannerServiceProvider's configured priority (50) initialises before the
20
+ // framework's built-in UpgradeServiceProvider (priority 6, see BaseCLI.ts) has called
21
+ // setDependencies() on the upgrade service - services initialise in descending-priority order
22
+ // (DefaultServiceProviderRegistry.getServiceProviders()). So the banner's *opportunistic* upgrade
23
+ // check on a freshly spawned process always observes a not-yet-wired FetchService and resolves to
24
+ // a "failed" check, regardless of network speed or mocking - confirmed by direct reproduction
25
+ // against both `bun run` and a `--compile`d binary. That is a pre-existing framework behaviour
26
+ // unrelated to the #141 formatting fix itself, so an external black-box test can't reliably
27
+ // observe the hint. Driving BannerServiceProvider directly (as done here) isolates and verifies
28
+ // the actual formatting fix.
29
+
30
+ function createStubPrinterService(lines: string[]) {
31
+ const identity = (message: string) => message;
32
+ return {
33
+ blue: identity,
34
+ primary: identity,
35
+ secondary: identity,
36
+ info: (message: string) => {
37
+ lines.push(message);
38
+ return Promise.resolve();
39
+ },
40
+ };
41
+ }
42
+
43
+ function createStubAsciiBannerGeneratorService() {
44
+ return {
45
+ registerFont: () => {},
46
+ getRegisteredFonts: () => [],
47
+ generate: () => Promise.resolve("EXAMPLE-CLI"),
48
+ };
49
+ }
50
+
51
+ function createStubUpgradeService(updateAvailable: boolean, latestVersion: string) {
52
+ return {
53
+ getUpgradeCheckResult: () =>
54
+ Promise.resolve(
55
+ updateAvailable
56
+ ? { status: "checked", updateAvailable: true, latestVersion }
57
+ : { status: "checked", updateAvailable: false, latestVersion },
58
+ ),
59
+ };
60
+ }
61
+
62
+ function createContext(
63
+ printerService: unknown,
64
+ asciiBannerGeneratorService: unknown,
65
+ upgradeService: unknown,
66
+ ): Context {
67
+ const services: Record<string, unknown> = {
68
+ [PRINTER_SERVICE_ID]: printerService,
69
+ [ASCII_BANNER_GENERATOR_SERVICE_ID]: asciiBannerGeneratorService,
70
+ [UPGRADE_SERVICE_ID]: upgradeService,
71
+ };
72
+ return {
73
+ cliConfig: {
74
+ name: "example-cli",
75
+ description: "Simple example CLI using dynamic-cli-framework.",
76
+ version: "1.8.2",
77
+ },
78
+ getServiceById: (id: string) => services[id],
79
+ doesServiceExist: (id: string) => id in services,
80
+ };
81
+ }
82
+
83
+ describe("Banner upgrade hint (dynamic-cli-framework #141)", () => {
84
+ test("prints the upgrade hint on the same line as the version when an upgrade is available", async () => {
85
+ const lines: string[] = [];
86
+ const provider = new BannerServiceProvider(50);
87
+ const context = createContext(
88
+ createStubPrinterService(lines),
89
+ createStubAsciiBannerGeneratorService(),
90
+ createStubUpgradeService(true, "99.0.0"),
91
+ );
92
+
93
+ await provider.initService(context);
94
+
95
+ const versionLine = lines.find((line) => line.includes("version:"));
96
+ expect(versionLine).toBeDefined();
97
+ expect(versionLine).toContain("version: 1.8.2 (99.0.0 available, run 'example-cli upgrade')");
98
+ });
99
+
100
+ test("does not print a hint when no upgrade is available", async () => {
101
+ const lines: string[] = [];
102
+ const provider = new BannerServiceProvider(50);
103
+ const context = createContext(
104
+ createStubPrinterService(lines),
105
+ createStubAsciiBannerGeneratorService(),
106
+ createStubUpgradeService(false, "1.8.2"),
107
+ );
108
+
109
+ await provider.initService(context);
110
+
111
+ const versionLine = lines.find((line) => line.includes("version:"));
112
+ expect(versionLine).toBeDefined();
113
+ expect(versionLine).not.toContain("available");
114
+ expect(versionLine).toContain("version: 1.8.2");
115
+ });
116
+ });
@@ -0,0 +1,53 @@
1
+ import path from "node:path";
2
+ import { describe, expect, test } from "bun:test";
3
+
4
+ // Functional test for dynamic-cli-framework#142: the `version` command must no longer print the
5
+ // upgrade-availability hint - it should only ever print the plain version number. (The hint
6
+ // itself remains in the startup banner - see tests/banner_upgrade_hint_test.ts for #141.)
7
+ //
8
+ // This spawns example-cli's real executable entrypoint (`index.ts`, the same one the compiled
9
+ // binary runs) as a subprocess against the real installed @flowscripter/dynamic-cli-framework@5.0.6,
10
+ // so the exact `version` command code path is exercised end to end. No mocking is needed here:
11
+ // post-fix, VersionCommand.execute() prints `context.cliConfig.version` unconditionally and no
12
+ // longer consults the upgrade service at all, so this holds regardless of whether an upgrade is
13
+ // actually available on the real network.
14
+ //
15
+ // The banner (printed via printerService.info()) writes to stderr; command results (`version`'s
16
+ // own output, printed via printerService.print()) write to stdout.
17
+
18
+ const PROJECT_ROOT = path.join(import.meta.dir, "..");
19
+
20
+ function runCli(args: string[]): { exitCode: number; stdout: string; stderr: string } {
21
+ const result = Bun.spawnSync([process.execPath, "run", "index.ts", ...args], {
22
+ cwd: PROJECT_ROOT,
23
+ stdin: "ignore",
24
+ stdout: "pipe",
25
+ stderr: "pipe",
26
+ });
27
+ return {
28
+ exitCode: result.exitCode,
29
+ stdout: result.stdout.toString("utf-8"),
30
+ stderr: result.stderr.toString("utf-8"),
31
+ };
32
+ }
33
+
34
+ describe("version command output (dynamic-cli-framework #142)", () => {
35
+ test("prints only the plain version number, with no upgrade hint", () => {
36
+ const { exitCode, stdout, stderr } = runCli(["--no-banner", "version"]);
37
+
38
+ expect(exitCode).toBe(0);
39
+ expect(stdout).not.toContain("available");
40
+ expect(stderr).not.toContain("available");
41
+ expect(stdout.trim()).toMatch(/^\d+\.\d+\.\d+$/);
42
+ });
43
+
44
+ test("its own output line is the bare version number even alongside the startup banner", () => {
45
+ const { exitCode, stdout } = runCli(["version"]);
46
+
47
+ expect(exitCode).toBe(0);
48
+ // stdout only ever carries the version command's own print() output, never the banner
49
+ // (which goes to stderr) - so this alone confirms the command output has no hint appended.
50
+ expect(stdout).not.toContain("available");
51
+ expect(stdout.trim()).toMatch(/^\d+\.\d+\.\d+$/);
52
+ });
53
+ });