snapdiff-cli 0.1.2 → 0.1.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/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
1
  export {};
package/dist/index.js CHANGED
@@ -1,4 +1,8 @@
1
- #!/usr/bin/env node
1
+ import { readFileSync } from "fs";
2
+ import { join, dirname } from "path";
3
+ import { fileURLToPath } from "url";
4
+ const __dirname = dirname(fileURLToPath(import.meta.url));
5
+ const pkg = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf-8"));
2
6
  import { Command } from "commander";
3
7
  import pc from "picocolors";
4
8
  import { initCommand } from "./commands/init.js";
@@ -6,78 +10,62 @@ import { captureCommand } from "./commands/capture.js";
6
10
  import { diffCommand } from "./commands/diff.js";
7
11
  import { approveCommand } from "./commands/approve.js";
8
12
  import { statusCommand } from "./commands/status.js";
9
- // Global error handler — prevent raw stack traces from leaking to users
10
13
  process.on("unhandledRejection", (err) => {
11
14
  const msg = err instanceof Error ? err.message : String(err);
12
- console.error(pc.red(`\n 意外错误: ${msg}`));
13
- console.error(pc.dim(` 如需帮助,请提供以上完整输出来排查问题。`));
15
+ console.error(pc.red("\n \u26a0 \u610f\u5916\u9519\u8bef: " + msg));
16
+ console.error(pc.dim(" \u5982\u9700\u5e2e\u52a9\uff0c\u8bf7\u63d0\u4f9b\u4ee5\u4e0a\u5b8c\u6574\u8f93\u51fa\u6765\u6392\u67e5\u95ee\u9898\u3002"));
14
17
  process.exit(1);
15
18
  });
16
19
  process.on("uncaughtException", (err) => {
17
- console.error(pc.red(`\n 意外错误: ${err.message}`));
18
- console.error(pc.dim(` 如需帮助,请提供以上完整输出来排查问题。`));
20
+ console.error(pc.red("\n \u26a0 \u610f\u5916\u9519\u8bef: " + err.message));
21
+ console.error(pc.dim(" \u5982\u9700\u5e2e\u52a9\uff0c\u8bf7\u63d0\u4f9b\u4ee5\u4e0a\u5b8c\u6574\u8f93\u51fa\u6765\u6392\u67e5\u95ee\u9898\u3002"));
19
22
  process.exit(1);
20
23
  });
21
- // Detect non-TTY stdin early — e.g. piped input in CI
22
24
  const isInteractive = process.stdin.isTTY;
23
25
  const program = new Command();
24
26
  program
25
27
  .name("snapdiff")
26
- .description(pc.cyan("一行命令的视觉回归测试工具"))
27
- .version("0.1.0");
28
+ .description(pc.cyan("\u4e00\u884c\u547d\u4ee4\u7684\u89c6\u89c9\u56de\u5f52\u6d4b\u8bd5\u5de5\u5177"))
29
+ .version(pkg.version);
28
30
  program
29
31
  .command("init")
30
- .description("初始化 snapdiff 配置(交互式向导,自动完成首次截图)")
31
- .option("--ci", "同时生成 GitHub Action 配置文件")
32
- .option("--yes", "跳过交互提问,使用默认值")
33
- .addHelpText("after", pc.dim(`\n示例:\n $ snapdiff init\n $ snapdiff init --yes 非交互式,快速初始化\n $ snapdiff init --yes --ci 非交互式 + CI 配置\n`))
32
+ .description("\u521d\u59cb\u5316 snapdiff \u914d\u7f6e\uff08\u4ea4\u4e92\u5f0f\u5411\u5bfc\uff0c\u81ea\u52a8\u5b8c\u6210\u9996\u6b21\u622a\u56fe\uff09")
33
+ .option("--ci", "\u540c\u65f6\u751f\u6210 GitHub Action \u914d\u7f6e\u6587\u4ef6")
34
+ .option("--yes", "\u8df3\u8fc7\u4ea4\u4e92\u63d0\u95ee\uff0c\u4f7f\u7528\u9ed8\u8ba4\u503c")
35
+ .addHelpText("after", pc.dim("\n\u793a\u4f8b:\n $ snapdiff init\n $ snapdiff init --yes \u975e\u4ea4\u4e92\u5f0f\uff0c\u5feb\u901f\u521d\u59cb\u5316\n $ snapdiff init --yes --ci \u975e\u4ea4\u4e92\u5f0f + CI \u914d\u7f6e\n"))
34
36
  .action((opts) => {
35
- // If stdin is not a TTY and --yes not given, auto-enable --yes to avoid hanging
36
- if (!isInteractive && !opts.yes) {
37
+ if (!isInteractive && !opts.yes)
37
38
  opts.yes = true;
38
- }
39
39
  initCommand(opts);
40
40
  });
41
41
  program
42
42
  .command("capture")
43
- .description("截取当前页面作为基线截图")
44
- .argument("[url]", "页面 URL")
45
- .option("-n, --name <name>", "截图名称")
46
- .option("-s, --selector <selector>", "等页面中该元素出现后再截图,如 #app-root")
47
- .option("-w, --width <width>", "视口宽度", "1440")
48
- .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`))
43
+ .description("\u622a\u53d6\u5f53\u524d\u9875\u9762\u4f5c\u4e3a\u57fa\u7ebf\u622a\u56fe")
44
+ .argument("[url]", "\u9875\u9762 URL")
45
+ .option("-n, --name <name>", "\u622a\u56fe\u540d\u79f0")
46
+ .option("-s, --selector <selector>", "\u7b49\u9875\u9762\u4e2d\u8be5\u5143\u7d20\u51fa\u73b0\u540e\u518d\u622a\u56fe\uff0c\u5982 #app-root")
47
+ .option("-w, --width <width>", "\u89c6\u53e3\u5bbd\u5ea6", "1440")
48
+ .option("-h, --height <height>", "\u89c6\u53e3\u9ad8\u5ea6", "900")
49
+ .addHelpText("after", pc.dim("\n\u793a\u4f8b:\n $ snapdiff capture \u4ece\u914d\u7f6e\u6587\u4ef6\u6279\u91cf\u622a\u53d6\n $ snapdiff capture https://ex.com -n my-page \u622a\u53d6\u5355\u4e2a\u9875\u9762\n $ snapdiff capture https://ex.com -n home -s #main\n"))
50
50
  .action(captureCommand);
51
51
  program
52
52
  .command("diff")
53
- .description("对比当前页面与基线截图")
54
- .argument("[url]", "页面 URL")
55
- .option("-n, --name <name>", "截图名称")
56
- .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`))
53
+ .description("\u5bf9\u6bd4\u5f53\u524d\u9875\u9762\u4e0e\u57fa\u7ebf\u622a\u56fe")
54
+ .argument("[url]", "\u9875\u9762 URL")
55
+ .option("-n, --name <name>", "\u622a\u56fe\u540d\u79f0")
56
+ .option("-t, --threshold <threshold>", "\u5141\u8bb8\u7684\u5dee\u5f02\u9608\u503c\u767e\u5206\u6bd4\uff0c\u8d85\u51fa\u5373\u5224\u5b9a\u4e3a\u5931\u8d25", "0.1")
57
+ .addHelpText("after", pc.dim("\n\u793a\u4f8b:\n $ snapdiff diff \u5bf9\u6bd4\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u6240\u6709\u9875\u9762\n $ snapdiff diff https://ex.com -n my-page \u5bf9\u6bd4\u5355\u4e2a\u9875\u9762\n $ snapdiff diff -t 0.5 \u8bbe\u7f6e\u66f4\u5bbd\u677e\u7684\u9608\u503c\n"))
58
58
  .action(diffCommand);
59
59
  program
60
60
  .command("approve")
61
- .description("接受当前差异为新基线(覆盖旧基线)")
62
- .argument("<name>", "截图名称(必填)")
63
- .addHelpText("after", pc.dim(`\n示例:\n $ snapdiff approve my-page 将我页面的新状态设为基线\n`))
61
+ .description("\u63a5\u53d7\u5f53\u524d\u5dee\u5f02\u4e3a\u65b0\u57fa\u7ebf\uff08\u8986\u76d6\u65e7\u57fa\u7ebf\uff09")
62
+ .argument("<name>", "\u622a\u56fe\u540d\u79f0\uff08\u5fc5\u586b\uff09")
63
+ .addHelpText("after", pc.dim("\n\u793a\u4f8b:\n $ snapdiff approve my-page \u5c06\u6211\u9875\u9762\u7684\u65b0\u72b6\u6001\u8bbe\u4e3a\u57fa\u7ebf\n"))
64
64
  .action(approveCommand);
65
65
  program
66
66
  .command("status")
67
- .description("查看所有基线状态(表格展示)")
68
- .addHelpText("after", pc.dim(`\n示例:\n $ snapdiff status 查看哪些页面有基线,哪些还未截取\n`))
67
+ .description("\u67e5\u770b\u6240\u6709\u57fa\u7ebf\u72b6\u6001\uff08\u8868\u683c\u5c55\u793a\uff09")
68
+ .addHelpText("after", pc.dim("\n\u793a\u4f8b:\n $ snapdiff status \u67e5\u770b\u54ea\u4e9b\u9875\u9762\u6709\u57fa\u7ebf\uff0c\u54ea\u4e9b\u8fd8\u672a\u622a\u53d6\n"))
69
69
  .action(statusCommand);
70
- program.addHelpText("afterAll", `
71
- ${pc.bold("快速开始")}:
72
- $ snapdiff init 首次运行,走一遍向导
73
- $ snapdiff diff 改完代码后对比变化
74
-
75
- ${pc.bold("典型工作流")}:
76
- 1. ${pc.dim("snapdiff init")} 初始化项目,自动截取首张基线
77
- 2. ${pc.dim("修改代码")} 改你的 CSS/组件/页面
78
- 3. ${pc.dim("snapdiff diff")} 对比变化,查看差异
79
- 4. ${pc.dim("snapdiff approve <name>")} 确认变更,更新基线
80
-
81
- ${pc.dim("完整文档: https://github.com/your-org/snapdiff")}
82
- `);
70
+ program.addHelpText("afterAll", "\n" + pc.bold("\u5feb\u901f\u5f00\u59cb") + ":\n $ snapdiff init \u9996\u6b21\u8fd0\u884c\uff0c\u8d70\u4e00\u904d\u5411\u5bfc\n $ snapdiff diff \u6539\u5b8c\u4ee3\u7801\u540e\u5bf9\u6bd4\u53d8\u5316\n\n" + pc.bold("\u5178\u578b\u5de5\u4f5c\u6d41") + ":\n 1. " + pc.dim("snapdiff init") + " \u521d\u59cb\u5316\u9879\u76ee\uff0c\u81ea\u52a8\u622a\u53d6\u9996\u5f20\u57fa\u7ebf\n 2. " + pc.dim("\u4fee\u6539\u4ee3\u7801") + " \u6539\u4f60\u7684 CSS/\u7ec4\u4ef6/\u9875\u9762\n 3. " + pc.dim("snapdiff diff") + " \u5bf9\u6bd4\u53d8\u5316\uff0c\u67e5\u770b\u5dee\u5f02\n 4. " + pc.dim("snapdiff approve <name>") + " \u786e\u8ba4\u53d8\u66f4\uff0c\u66f4\u65b0\u57fa\u7ebf\n\n" + pc.dim("\u5b8c\u6574\u6587\u6863: https://github.com/your-org/snapdiff") + "\n");
83
71
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snapdiff-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "????????????????????????? Playwright + pixelmatch",
5
5
  "type": "module",
6
6
  "bin": {