forked from triggerdotdev/trigger.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcliOutput.ts
More file actions
145 lines (114 loc) · 3.53 KB
/
cliOutput.ts
File metadata and controls
145 lines (114 loc) · 3.53 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
import { log } from "@clack/prompts";
import chalk from "chalk";
import { terminalLink, TerminalLinkOptions } from "./terminalLink.js";
import { hasTTY } from "std-env";
export const isInteractive = hasTTY;
export const isLinksSupported = terminalLink.isSupported;
export const green = "#4FFF54";
export const purple = "#735BF3";
export function chalkGreen(text: string) {
return chalk.hex(green)(text);
}
export function chalkPurple(text: string) {
return chalk.hex(purple)(text);
}
export function chalkGrey(text: string) {
return chalk.hex("#878C99")(text);
}
export function chalkError(text: string) {
return chalk.hex("#E11D48")(text);
}
export function chalkWarning(text: string) {
return chalk.yellow(text);
}
export function chalkSuccess(text: string) {
return chalk.hex("#28BF5C")(text);
}
export function chalkLink(text: string) {
return chalk.underline.hex("#D7D9DD")(text);
}
export function chalkWorker(text: string) {
return chalk.yellowBright(text);
}
export function chalkTask(text: string) {
return chalk.hex("#60A5FA")(text);
}
export function chalkRun(text: string) {
return chalk.hex("#A78BFA")(text);
}
export function logo() {
return `${chalk.hex(green).bold("Trigger")}${chalk.hex(purple).bold(".dev")}`;
}
// Mar 27 09:17:25.653
export function prettyPrintDate(date: Date = new Date()) {
let formattedDate = new Intl.DateTimeFormat("en-US", {
month: "short",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
}).format(date);
// Append milliseconds
formattedDate += "." + ("00" + date.getMilliseconds()).slice(-3);
return formattedDate;
}
export function prettyError(header: string, body?: string, footer?: string) {
const prefix = "Error: ";
const indent = Array(prefix.length).fill(" ").join("");
const spacing = "\n\n";
const prettyPrefix = chalkError(prefix);
const withIndents = (text?: string) =>
text
?.split("\n")
.map((line) => `${indent}${line}`)
.join("\n");
const prettyBody = withIndents(body?.trim());
const prettyFooter = withIndents(footer);
log.error(
`${prettyPrefix}${header}${prettyBody ? `${spacing}${prettyBody}` : ""}${
prettyFooter ? `${spacing}${prettyFooter}` : ""
}`
);
}
export function prettyWarning(header: string, body?: string, footer?: string) {
const prefix = "Warning: ";
const indent = Array(prefix.length).fill(" ").join("");
const spacing = "\n\n";
const prettyPrefix = chalkWarning(prefix);
const withIndents = (text?: string) =>
text
?.split("\n")
.map((line) => `${indent}${line}`)
.join("\n");
const prettyBody = withIndents(body);
const prettyFooter = withIndents(footer);
log.warn(
`${prettyPrefix}${header}${prettyBody ? `${spacing}${prettyBody}` : ""}${
prettyFooter ? `${spacing}${prettyFooter}` : ""
}`
);
}
export function aiHelpLink({
dashboardUrl,
project,
query,
}: {
dashboardUrl: string;
project: string;
query: string;
}) {
const searchParams = new URLSearchParams();
//the max length for a URL is 1950 characters
const clippedQuery = query.slice(0, 1950);
searchParams.set("q", clippedQuery);
const url = new URL(`/projects/${project}/ai-help`, dashboardUrl);
url.search = searchParams.toString();
log.message(chalkLink(cliLink("💡 Get a fix for this error using AI", url.toString())));
}
export function cliLink(text: string, url: string, options?: TerminalLinkOptions) {
return terminalLink(text, url, {
fallback: (text, url) => `${text} ${url}`,
...options,
});
}