snapdiff-cli 0.1.3 → 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.js +32 -43
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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"));
|
|
4
6
|
import { Command } from "commander";
|
|
5
7
|
import pc from "picocolors";
|
|
6
8
|
import { initCommand } from "./commands/init.js";
|
|
@@ -8,30 +10,29 @@ import { captureCommand } from "./commands/capture.js";
|
|
|
8
10
|
import { diffCommand } from "./commands/diff.js";
|
|
9
11
|
import { approveCommand } from "./commands/approve.js";
|
|
10
12
|
import { statusCommand } from "./commands/status.js";
|
|
11
|
-
// Global error handler
|
|
12
13
|
process.on("unhandledRejection", (err) => {
|
|
13
14
|
const msg = err instanceof Error ? err.message : String(err);
|
|
14
|
-
console.error(pc.red(
|
|
15
|
-
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"));
|
|
16
17
|
process.exit(1);
|
|
17
18
|
});
|
|
18
19
|
process.on("uncaughtException", (err) => {
|
|
19
|
-
console.error(pc.red(
|
|
20
|
-
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"));
|
|
21
22
|
process.exit(1);
|
|
22
23
|
});
|
|
23
24
|
const isInteractive = process.stdin.isTTY;
|
|
24
25
|
const program = new Command();
|
|
25
26
|
program
|
|
26
27
|
.name("snapdiff")
|
|
27
|
-
.description(pc.cyan("
|
|
28
|
+
.description(pc.cyan("\u4e00\u884c\u547d\u4ee4\u7684\u89c6\u89c9\u56de\u5f52\u6d4b\u8bd5\u5de5\u5177"))
|
|
28
29
|
.version(pkg.version);
|
|
29
30
|
program
|
|
30
31
|
.command("init")
|
|
31
|
-
.description("
|
|
32
|
-
.option("--ci", "
|
|
33
|
-
.option("--yes", "
|
|
34
|
-
.addHelpText("after", pc.dim("\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"))
|
|
35
36
|
.action((opts) => {
|
|
36
37
|
if (!isInteractive && !opts.yes)
|
|
37
38
|
opts.yes = true;
|
|
@@ -39,44 +40,32 @@ program
|
|
|
39
40
|
});
|
|
40
41
|
program
|
|
41
42
|
.command("capture")
|
|
42
|
-
.description("
|
|
43
|
-
.argument("[url]", "
|
|
44
|
-
.option("-n, --name <name>", "
|
|
45
|
-
.option("-s, --selector <selector>", "
|
|
46
|
-
.option("-w, --width <width>", "
|
|
47
|
-
.option("-h, --height <height>", "
|
|
48
|
-
.addHelpText("after", pc.dim("\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"))
|
|
49
50
|
.action(captureCommand);
|
|
50
51
|
program
|
|
51
52
|
.command("diff")
|
|
52
|
-
.description("
|
|
53
|
-
.argument("[url]", "
|
|
54
|
-
.option("-n, --name <name>", "
|
|
55
|
-
.option("-t, --threshold <threshold>", "
|
|
56
|
-
.addHelpText("after", pc.dim("\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"))
|
|
57
58
|
.action(diffCommand);
|
|
58
59
|
program
|
|
59
60
|
.command("approve")
|
|
60
|
-
.description("
|
|
61
|
-
.argument("<name>", "
|
|
62
|
-
.addHelpText("after", pc.dim("\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"))
|
|
63
64
|
.action(approveCommand);
|
|
64
65
|
program
|
|
65
66
|
.command("status")
|
|
66
|
-
.description("
|
|
67
|
-
.addHelpText("after", pc.dim("\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"))
|
|
68
69
|
.action(statusCommand);
|
|
69
|
-
program.addHelpText("afterAll",
|
|
70
|
-
${pc.bold("快速开始")}:
|
|
71
|
-
$ snapdiff init 首次运行,走一遍向导
|
|
72
|
-
$ snapdiff diff 改完代码后对比变化
|
|
73
|
-
|
|
74
|
-
${pc.bold("典型工作流")}:
|
|
75
|
-
1. ${pc.dim("snapdiff init")} 初始化项目,自动截取首张基线
|
|
76
|
-
2. ${pc.dim("修改代码")} 改你的 CSS/组件/页面
|
|
77
|
-
3. ${pc.dim("snapdiff diff")} 对比变化,查看差异
|
|
78
|
-
4. ${pc.dim("snapdiff approve <name>")} 确认变更,更新基线
|
|
79
|
-
|
|
80
|
-
${pc.dim("完整文档: https://github.com/your-org/snapdiff")}
|
|
81
|
-
`);
|
|
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");
|
|
82
71
|
program.parse(process.argv);
|