@flowscripter/example-cli 3.0.1 → 3.0.3
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/tests/banner_upgrade_hint_test.ts +66 -95
package/bun.lock
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "@flowscripter/example-cli",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@flowscripter/dynamic-cli-framework": "^7.0.
|
|
8
|
+
"@flowscripter/dynamic-cli-framework": "^7.0.8",
|
|
9
9
|
"@flowscripter/dynamic-cli-framework-api": "^4.0.4",
|
|
10
|
-
"@flowscripter/dynamic-plugin-framework": "2.2.
|
|
10
|
+
"@flowscripter/dynamic-plugin-framework": "2.2.14",
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/bun": "^1.4.2",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
"packages": {
|
|
24
|
-
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@7.0.
|
|
24
|
+
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@7.0.8", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^4.0.4", "@flowscripter/dynamic-plugin-framework": "^2.2.14", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.12.0", "highlight.js": "^11.12.0", "prettier": "^3.9.9", "semver": "^7.8.5", "supports-color": "^11.0.0", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-wlIGkPWyzsmBCVeJlh2qqxX/KG3sfbz2GNpbG4KbV5hhS12Y7WqRB/77m6uf5xRQIAP6ivb6vcQbVu6QVnWUTA=="],
|
|
25
25
|
|
|
26
26
|
"@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@4.0.4", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-Vb+dUEuQ48maXEUYJ906hrvcRxRtTkCXIJs6CEPDzgVZ7WVYgf1YXU/PNaxEhZ+On4RmMwvpej4Du6rci4Y48Q=="],
|
|
27
27
|
|
|
28
|
-
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.2.
|
|
28
|
+
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@2.2.14", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-I91cuIMSzhZ/ZZzqtmYyX9sw6TVFGDxRa1PMFPJBJYcydov+kxIbrRUUU9RHSjVO38eBZ6eugklDu0lJnNDaAQ=="],
|
|
29
29
|
|
|
30
30
|
"@oxfmt/binding-android-arm-eabi": ["@oxfmt/binding-android-arm-eabi@0.70.0", "", { "os": "android", "cpu": "arm" }, "sha512-Xd7YO4/T2axEj6FTLcj4Why3mTBqFMg+x24xtorT4Lb2+1g82090GH0a/4U1m0pABGYiix2bq1pqkYrmV3f0Sw=="],
|
|
31
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/example-cli",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
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": "^7.0.
|
|
27
|
+
"@flowscripter/dynamic-cli-framework": "^7.0.8",
|
|
28
28
|
"@flowscripter/dynamic-cli-framework-api": "^4.0.4",
|
|
29
|
-
"@flowscripter/dynamic-plugin-framework": "2.2.
|
|
29
|
+
"@flowscripter/dynamic-plugin-framework": "2.2.14"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/bun": "^1.4.2",
|
|
@@ -1,120 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "@flowscripter/dynamic-cli-framework-api";
|
|
8
|
-
import type { Context } from "@flowscripter/dynamic-cli-framework-api";
|
|
1
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
6
|
+
import packageJson from "../package.json";
|
|
9
7
|
|
|
10
|
-
// Functional test for dynamic-cli-framework#141: the startup banner must print the
|
|
8
|
+
// Functional test for dynamic-cli-framework#141/#213: the startup banner must print the
|
|
11
9
|
// upgrade-availability hint "(X.Y.Z available, run 'app upgrade')" on the SAME line as
|
|
12
|
-
// "version: X.Y.Z",
|
|
10
|
+
// "version: X.Y.Z", sourced from the cached upgrade-check result.
|
|
13
11
|
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
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";
|
|
12
|
+
// bannerStartupTask.ts only honours a cached result coming from the framework's own
|
|
13
|
+
// DefaultUpgradeService (via an `instanceof` check) - that class isn't part of the package's
|
|
14
|
+
// public exports, so it can't be stubbed from outside the framework. Instead this drives the
|
|
15
|
+
// real CLI end to end (same pattern as tests/version_command_test.ts), pre-seeding the on-disk
|
|
16
|
+
// config file's "services" key-value scope for UPGRADE_SERVICE_ID
|
|
17
|
+
// ("@flowscripter/dynamic-cli-framework/upgrade-service") with the cached
|
|
18
|
+
// "upgrade-check-result" entry that DefaultUpgradeService.getCachedUpgradeCheckResult() reads -
|
|
19
|
+
// the same entry refreshUpgradeCheckCache() would have written from a prior run.
|
|
20
|
+
const PROJECT_ROOT = path.join(import.meta.dir, "..");
|
|
21
|
+
const UPGRADE_SERVICE_ID = "@flowscripter/dynamic-cli-framework/upgrade-service";
|
|
29
22
|
|
|
30
|
-
|
|
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
|
-
}
|
|
23
|
+
let homeDir: string;
|
|
42
24
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
getRegisteredFonts: () => [],
|
|
47
|
-
generate: () => Promise.resolve("EXAMPLE-CLI"),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
homeDir = await mkdtemp(join(tmpdir(), "example-cli-home-"));
|
|
27
|
+
});
|
|
50
28
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
: { status: "checked", updateAvailable: false, latestVersion };
|
|
55
|
-
return {
|
|
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")),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
29
|
+
afterEach(async () => {
|
|
30
|
+
await rm(homeDir, { recursive: true, force: true });
|
|
31
|
+
});
|
|
65
32
|
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
33
|
+
async function seedUpgradeCheckCache(
|
|
34
|
+
updateAvailable: boolean,
|
|
35
|
+
latestVersion: string,
|
|
36
|
+
): Promise<void> {
|
|
37
|
+
const config = {
|
|
38
|
+
"key-values": {
|
|
39
|
+
services: {
|
|
40
|
+
[UPGRADE_SERVICE_ID]: {
|
|
41
|
+
"upgrade-check-result": {
|
|
42
|
+
status: "checked",
|
|
43
|
+
currentVersion: packageJson.version,
|
|
44
|
+
latestVersion,
|
|
45
|
+
updateAvailable,
|
|
46
|
+
os: "linux",
|
|
47
|
+
arch: "x64",
|
|
48
|
+
installMethod: "github-release",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
81
52
|
},
|
|
82
|
-
getServiceById: (id: string) => services[id],
|
|
83
|
-
doesServiceExist: (id: string) => id in services,
|
|
84
53
|
};
|
|
54
|
+
await writeFile(join(homeDir, ".examplecli.json"), JSON.stringify(config));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function runCli(): { stderr: string } {
|
|
58
|
+
const result = Bun.spawnSync([process.execPath, "run", "index.ts"], {
|
|
59
|
+
cwd: PROJECT_ROOT,
|
|
60
|
+
env: { ...process.env, HOME: homeDir },
|
|
61
|
+
stdin: "ignore",
|
|
62
|
+
stdout: "pipe",
|
|
63
|
+
stderr: "pipe",
|
|
64
|
+
});
|
|
65
|
+
return { stderr: result.stderr.toString("utf-8") };
|
|
85
66
|
}
|
|
86
67
|
|
|
87
68
|
describe("Banner upgrade hint (dynamic-cli-framework #141)", () => {
|
|
88
69
|
test("prints the upgrade hint on the same line as the version when an upgrade is available", async () => {
|
|
89
|
-
|
|
90
|
-
const task = createBannerStartupTask(50);
|
|
91
|
-
const context = createContext(
|
|
92
|
-
createStubPrinterService(lines),
|
|
93
|
-
createStubAsciiBannerGeneratorService(),
|
|
94
|
-
createStubKeyValueService(true, "99.0.0"),
|
|
95
|
-
);
|
|
70
|
+
await seedUpgradeCheckCache(true, "99.0.0");
|
|
96
71
|
|
|
97
|
-
|
|
72
|
+
const { stderr } = runCli();
|
|
98
73
|
|
|
99
|
-
const versionLine =
|
|
74
|
+
const versionLine = stderr.split("\n").find((line) => line.includes("version:"));
|
|
100
75
|
expect(versionLine).toBeDefined();
|
|
101
|
-
expect(versionLine).toContain(
|
|
76
|
+
expect(versionLine).toContain(
|
|
77
|
+
`version: ${packageJson.version} (99.0.0 available, run 'example-cli upgrade')`,
|
|
78
|
+
);
|
|
102
79
|
});
|
|
103
80
|
|
|
104
81
|
test("does not print a hint when no upgrade is available", async () => {
|
|
105
|
-
|
|
106
|
-
const task = createBannerStartupTask(50);
|
|
107
|
-
const context = createContext(
|
|
108
|
-
createStubPrinterService(lines),
|
|
109
|
-
createStubAsciiBannerGeneratorService(),
|
|
110
|
-
createStubKeyValueService(false, "1.8.2"),
|
|
111
|
-
);
|
|
82
|
+
await seedUpgradeCheckCache(false, packageJson.version);
|
|
112
83
|
|
|
113
|
-
|
|
84
|
+
const { stderr } = runCli();
|
|
114
85
|
|
|
115
|
-
const versionLine =
|
|
86
|
+
const versionLine = stderr.split("\n").find((line) => line.includes("version:"));
|
|
116
87
|
expect(versionLine).toBeDefined();
|
|
117
88
|
expect(versionLine).not.toContain("available");
|
|
118
|
-
expect(versionLine).toContain(
|
|
89
|
+
expect(versionLine).toContain(`version: ${packageJson.version}`);
|
|
119
90
|
});
|
|
120
91
|
});
|