-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
executable file
·80 lines (76 loc) · 1.76 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env node
const meow = require("meow");
const w3Diff = require("./index");
const fs = require('fs').promises
const cli = meow(
`Usage
$ wwwdiff https://example.com/a https://example.com/b > diff.png
Options
--color, -c <color> hightlighting color. The default is #ff00ff.
--delay, -d <millisecond> duration until shot. The default value is 0.
--output, -o <file path> Use specified file path as output, not sdtout.
--width, -w <width> viewport width.
--verbose shows debug messages.
`,
{
flags: {
color: {
type: "string",
alias: "c",
default: "#ff00ff",
},
delay: {
type: "number",
alias: "d",
default: 0,
},
output: {
type: "string",
alias: "o",
},
width: {
type: "number",
alias: "w",
},
verbose: {
type: "boolean",
default: false,
},
reference: {
type: "boolean",
default: false,
},
current: {
type: "boolean",
default: false,
},
},
}
);
const main = async () => {
const [url1, url2] = cli.input;
const options = cli.flags;
if (options.h || options.help) {
cli.showHelp();
} else if (options.v || options.version) {
cli.showVersion();
} else {
try {
const diff = await w3Diff(url1, url2, options);
if(options.output) {
await fs.writeFile(options.output, diff);
} else {
process.stdout.write(diff);
}
process.exit(0);
} catch (error) {
if(error && typeof error.toString === 'function') {
process.stderr.write(error.toString())
} else {
process.stderr.write(error)
}
process.exit(1)
}
}
};
main();