-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·158 lines (143 loc) · 4.36 KB
/
index.js
File metadata and controls
executable file
·158 lines (143 loc) · 4.36 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env node
const fs = require("fs");
const crypto = require("crypto");
const lib = require("./lib");
const Recorder = require("./recorder");
const packageMetadata = require("./package.json");
if (module.parent) {
module.exports = lib;
return;
}
const { program } = require("commander");
program
.name("dashcam")
.description("Capture the steps to reproduce every bug.")
.version(packageMetadata.version);
program.showHelpAfterError();
program
.command("auth")
.argument("<api-key>", "The team's ApiKey")
.description("Authenticate the dashcam desktop using a team's apiKey")
.action(async function (apiKey) {
await lib
.sendApiKey(apiKey)
.then(() => process.exit())
.catch(() => process.exit(1));
});
program
.command("create", { isDefault: true })
.description(
"Create a clip and output the resulting url or markdown. Will launch desktop app for local editing before publishing."
)
.option(
"-t, --title <string>",
"Title of the clip. Automatically generated if not supplied."
)
.option(
"-d, --description [text]",
"Markdown body."
)
.option("--md", "Returns code for a rich markdown image link.")
.option("-r --replay", "Create a replay not capture.")
.option(
"-p, --publish",
"Whether to publish the clip instantly after creation or not."
)
.option(
"-k, --project [string]",
"The project id to which to publish the replay"
)
.action(async function (str, options) {
try {
let description = this.opts().description;
let result = await lib.createClip({
title: this.opts().title,
description,
md: this.opts().md,
publish: this.opts().publish,
capture: !this.opts().replay,
png: this.opts().png,
project: this.opts().project,
});
console.log(result);
} catch (e) {
console.log("Error: ", e);
}
process.exit(0);
});
program
.command("record")
.option("-s, --silent", "Use silent mode when recording")
.description(
"Start a recording terminal to be included in your dashcam video recording"
)
.action(async function ({ silent }) {
try {
const dashcam = new lib.PersistantDashcamIPC();
const id = crypto.randomUUID();
const logFile = lib.getLogFilePath(id);
dashcam.onConnected = () => dashcam.emit("track-cli", logFile);
fs.appendFileSync(logFile, "");
const recorder = new Recorder(logFile, silent);
await recorder.start();
} catch (e) {
console.log("Error: ", e);
}
});
program
.command("pipe")
.description(
"Pipe command output to dashcam to be included in recorded video"
)
.action(async function () {
try {
const dashcam = new lib.PersistantDashcamIPC();
const id = crypto.randomUUID();
const logFile = lib.getLogFilePath(id);
dashcam.onConnected = () => dashcam.emit("track-cli", logFile);
fs.appendFileSync(logFile, "");
process.stdin.on("data", (data) => {
process.stdout.write(data);
fs.appendFileSync(logFile, data);
});
process.stdin.on("close", () => process.exit());
process.stdin.on("error", () => process.exit(1));
} catch (e) {
console.log("Error: ", e);
}
});
program
.command("track")
.requiredOption("--name <name>", "The name for the log config.")
.requiredOption(
"--type <type>",
'The type of log config ("web" or "application").'
)
.requiredOption(
"--pattern <patterns...>",
'The patterns of the urls in the case of "web" or the file paths in the case of "application" (Can contain wildcards \'*\'), multiple patterns can be provided.'
)
.description("Add a logs config to Dashcam")
.action(async function ({ name, type, pattern: patterns }) {
if (!["web", "application"].includes(type)) {
console.log('The "type" options needs to be "web" or "application"');
} else {
await lib.addLogsConfig({ name, type, patterns });
}
process.exit(0);
});
program
.command("start")
.description("Start capture on dashcam")
.option("-r, --replay", "Start replay, not capture.")
.action(async function (name, options) {
try {
const isCapture = !this.opts().replay;
await lib.startRecording(isCapture);
process.exit(0);
} catch (e) {
console.log("startRecording error: ", e);
process.exit(1);
}
});
program.parse(process.argv);