persona-test-cli 0.1.2 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +32 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import { dirname, join } from "node:path";
2
5
  import { Command } from "commander";
3
6
  import { registerCommand } from "./commands/register.js";
4
7
  import { loginCommand } from "./commands/login.js";
@@ -9,13 +12,42 @@ import { personasCommand } from "./commands/personas.js";
9
12
  import { eventsCommand } from "./commands/events.js";
10
13
  import { usersCommand } from "./commands/users.js";
11
14
  import { examplesCommand } from "./commands/examples.js";
15
+ import { jsonMode } from "./output.js";
16
+ // Reads package.json's version whether running from source (cli/index.ts,
17
+ // package.json next to it) or from the built dist/index.js (package.json one
18
+ // directory up) — avoids a hardcoded version string drifting from package.json.
19
+ function readVersion() {
20
+ const here = dirname(fileURLToPath(import.meta.url));
21
+ for (const candidate of [join(here, "..", "package.json"), join(here, "package.json")]) {
22
+ try {
23
+ return JSON.parse(readFileSync(candidate, "utf8")).version;
24
+ }
25
+ catch {
26
+ continue;
27
+ }
28
+ }
29
+ return "0.0.0";
30
+ }
31
+ const version = readVersion();
12
32
  const program = new Command();
13
33
  program
14
34
  .name("persona-test-cli")
15
35
  .description("persona-test 运维 CLI —— admin 和已审核通过的普通用户都能用,普通用户只能看到/编辑自己创建的 campaigns/personas。\n" +
16
36
  "先跑一次 `persona-test-cli examples` 看全部子命令的可复制示例。")
37
+ .version(version, "-v, --version", "打印版本号")
17
38
  .option("--json", "所有命令输出纯 JSON(成功到 stdout,失败到 stderr),适合脚本/agent 调用")
18
39
  .configureHelp({ sortSubcommands: true });
40
+ program
41
+ .command("version")
42
+ .description("打印版本号(等价于 -v/--version)")
43
+ .action(() => {
44
+ if (jsonMode) {
45
+ console.log(JSON.stringify({ version }));
46
+ }
47
+ else {
48
+ console.log(version);
49
+ }
50
+ });
19
51
  registerCommand(program);
20
52
  loginCommand(program);
21
53
  logoutCommand(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "persona-test-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "运维 CLI for persona-test — admin 和已审核通过的普通用户都能用;设备码浏览器授权登录,管理分享链接(campaigns)和画像(personas),普通用户只能看到/编辑自己创建的。",
5
5
  "type": "module",
6
6
  "bin": {