snapdiff-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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
1
  export {};
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env node
1
+ import { createRequire } from "module";
2
+ const require = createRequire(import.meta.url);
3
+ const pkg = require("../package.json");
2
4
  import { Command } from "commander";
3
5
  import pc from "picocolors";
4
6
  import { initCommand } from "./commands/init.js";
@@ -6,36 +8,33 @@ import { captureCommand } from "./commands/capture.js";
6
8
  import { diffCommand } from "./commands/diff.js";
7
9
  import { approveCommand } from "./commands/approve.js";
8
10
  import { statusCommand } from "./commands/status.js";
9
- // Global error handler — prevent raw stack traces from leaking to users
11
+ // Global error handler
10
12
  process.on("unhandledRejection", (err) => {
11
13
  const msg = err instanceof Error ? err.message : String(err);
12
14
  console.error(pc.red(`\n ⚠ 意外错误: ${msg}`));
13
- console.error(pc.dim(` 如需帮助,请提供以上完整输出来排查问题。`));
15
+ console.error(pc.dim(" 如需帮助,请提供以上完整输出来排查问题。"));
14
16
  process.exit(1);
15
17
  });
16
18
  process.on("uncaughtException", (err) => {
17
19
  console.error(pc.red(`\n ⚠ 意外错误: ${err.message}`));
18
- console.error(pc.dim(` 如需帮助,请提供以上完整输出来排查问题。`));
20
+ console.error(pc.dim(" 如需帮助,请提供以上完整输出来排查问题。"));
19
21
  process.exit(1);
20
22
  });
21
- // Detect non-TTY stdin early — e.g. piped input in CI
22
23
  const isInteractive = process.stdin.isTTY;
23
24
  const program = new Command();
24
25
  program
25
26
  .name("snapdiff")
26
27
  .description(pc.cyan("一行命令的视觉回归测试工具"))
27
- .version("0.1.0");
28
+ .version(pkg.version);
28
29
  program
29
30
  .command("init")
30
31
  .description("初始化 snapdiff 配置(交互式向导,自动完成首次截图)")
31
32
  .option("--ci", "同时生成 GitHub Action 配置文件")
32
33
  .option("--yes", "跳过交互提问,使用默认值")
33
- .addHelpText("after", pc.dim(`\n示例:\n $ snapdiff init\n $ snapdiff init --yes 非交互式,快速初始化\n $ snapdiff init --yes --ci 非交互式 + CI 配置\n`))
34
+ .addHelpText("after", pc.dim("\n示例:\n $ snapdiff init\n $ snapdiff init --yes 非交互式,快速初始化\n $ snapdiff init --yes --ci 非交互式 + CI 配置\n"))
34
35
  .action((opts) => {
35
- // If stdin is not a TTY and --yes not given, auto-enable --yes to avoid hanging
36
- if (!isInteractive && !opts.yes) {
36
+ if (!isInteractive && !opts.yes)
37
37
  opts.yes = true;
38
- }
39
38
  initCommand(opts);
40
39
  });
41
40
  program
@@ -46,7 +45,7 @@ program
46
45
  .option("-s, --selector <selector>", "等页面中该元素出现后再截图,如 #app-root")
47
46
  .option("-w, --width <width>", "视口宽度", "1440")
48
47
  .option("-h, --height <height>", "视口高度", "900")
49
- .addHelpText("after", pc.dim(`\n示例:\n $ snapdiff capture 从配置文件批量截取\n $ snapdiff capture https://ex.com -n my-page 截取单个页面\n $ snapdiff capture https://ex.com -n home -s #main\n`))
48
+ .addHelpText("after", pc.dim("\n示例:\n $ snapdiff capture 从配置文件批量截取\n $ snapdiff capture https://ex.com -n my-page 截取单个页面\n $ snapdiff capture https://ex.com -n home -s #main\n"))
50
49
  .action(captureCommand);
51
50
  program
52
51
  .command("diff")
@@ -54,18 +53,18 @@ program
54
53
  .argument("[url]", "页面 URL")
55
54
  .option("-n, --name <name>", "截图名称")
56
55
  .option("-t, --threshold <threshold>", "允许的差异阈值百分比,超出即判定为失败", "0.1")
57
- .addHelpText("after", pc.dim(`\n示例:\n $ snapdiff diff 对比配置文件中的所有页面\n $ snapdiff diff https://ex.com -n my-page 对比单个页面\n $ snapdiff diff -t 0.5 设置更宽松的阈值\n`))
56
+ .addHelpText("after", pc.dim("\n示例:\n $ snapdiff diff 对比配置文件中的所有页面\n $ snapdiff diff https://ex.com -n my-page 对比单个页面\n $ snapdiff diff -t 0.5 设置更宽松的阈值\n"))
58
57
  .action(diffCommand);
59
58
  program
60
59
  .command("approve")
61
60
  .description("接受当前差异为新基线(覆盖旧基线)")
62
61
  .argument("<name>", "截图名称(必填)")
63
- .addHelpText("after", pc.dim(`\n示例:\n $ snapdiff approve my-page 将我页面的新状态设为基线\n`))
62
+ .addHelpText("after", pc.dim("\n示例:\n $ snapdiff approve my-page 将我页面的新状态设为基线\n"))
64
63
  .action(approveCommand);
65
64
  program
66
65
  .command("status")
67
66
  .description("查看所有基线状态(表格展示)")
68
- .addHelpText("after", pc.dim(`\n示例:\n $ snapdiff status 查看哪些页面有基线,哪些还未截取\n`))
67
+ .addHelpText("after", pc.dim("\n示例:\n $ snapdiff status 查看哪些页面有基线,哪些还未截取\n"))
69
68
  .action(statusCommand);
70
69
  program.addHelpText("afterAll", `
71
70
  ${pc.bold("快速开始")}:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snapdiff-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "????????????????????????? Playwright + pixelmatch",
5
5
  "type": "module",
6
6
  "bin": {