-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (62 loc) · 1.91 KB
/
index.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
import { Command as Commander } from "commander";
import { laptop, mobile } from "./utils/index.js";
import {
takeScreenshot,
takeGif,
mockupScreenshot,
mockupGif,
doubleShot,
} from "./libs/index.js";
const command = new Commander();
command
.version("1.0.9", "-v, --version", "Print version")
.usage("[OPTIONS]...")
.option("-n, --name <filename>", "Sets filename that will be exported")
.option(
"-t, --type <type>",
`Defines type of screenshot will be taken,
> screenshot - will take single shot,
> banner - will take a shot for both devices and then export as single file,
> gif - will record gif
`,
"screenshot"
)
.option("-m, --mockup", "Adds mockup to result.")
// .option(
// "-b, --banner",
// "Take screenshots for both devices and then export as single png"
// )
.option(
"-d, --device <device_type>",
"Sets device type mobile or laptop",
"laptop"
)
.option(
"-u, --url <url>",
"Sets url that will be recorded",
"https://myusuf.net/"
)
// .option('-c, --custom <value>', 'Overwriting value.', 'Default')
.parse(process.argv);
const options = command.opts();
const device = options.device === "mobile" ? mobile : laptop;
// console.log(options);
if (!options.name) {
const hostname = new URL(options.url).hostname.split(".").join("");
options.name = hostname;
}
if (options.type === "screenshot") {
if (options.mockup) {
mockupScreenshot(options.url, options.name, device);
} else {
takeScreenshot(options.url, options.name, device);
}
} else if (options.type === "banner") {
doubleShot(options.url, options.name);
} else if (options.type === "gif") {
if (options.mockup) {
mockupGif(options.url, options.name, device);
} else {
takeGif(options.url, options.name, device);
}
}