Skip to content

Commit 5b745dc

Browse files
committed
Improved the dev CLI output
1 parent 2dea8de commit 5b745dc

File tree

12 files changed

+196
-108
lines changed

12 files changed

+196
-108
lines changed

.changeset/chilled-hornets-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Vastly improved dev command output

packages/cli-v3/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"node-fetch": "^3.3.0",
114114
"npm-check-updates": "^16.12.2",
115115
"object-hash": "^3.0.0",
116+
"p-debounce": "^4.0.0",
116117
"p-throttle": "^6.1.0",
117118
"partysocket": "^0.0.17",
118119
"proxy-agent": "^6.3.0",

packages/cli-v3/src/commands/dev.tsx

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
detectDependencyVersion,
99
serverWebsocketMessages,
1010
} from "@trigger.dev/core/v3";
11-
import chalk from "chalk";
1211
import { watch } from "chokidar";
1312
import { Command } from "commander";
1413
import { BuildContext, Metafile, context } from "esbuild";
@@ -18,7 +17,7 @@ import { createHash } from "node:crypto";
1817
import fs, { readFileSync } from "node:fs";
1918
import { ClientRequestArgs } from "node:http";
2019
import { basename, dirname, join } from "node:path";
21-
import pThrottle from "p-throttle";
20+
import pDebounce from "p-debounce";
2221
import { WebSocket } from "partysocket";
2322
import React, { Suspense, useEffect } from "react";
2423
import { ClientOptions, WebSocket as wsWebSocket } from "ws";
@@ -27,10 +26,10 @@ import * as packageJson from "../../package.json";
2726
import { CliApiClient } from "../apiClient";
2827
import { CommonCommandOptions, commonOptions, wrapCommandAction } from "../cli/common.js";
2928
import { bundleDependenciesPlugin, workerSetupImportConfigPlugin } from "../utilities/build";
30-
import { chalkPurple } from "../utilities/colors";
29+
import { chalkGrey, chalkPurple, chalkWorker } from "../utilities/cliOutput";
3130
import { readConfig } from "../utilities/configFiles";
3231
import { readJSONFile } from "../utilities/fileSystem";
33-
import { printStandloneInitialBanner } from "../utilities/initialBanner.js";
32+
import { printDevBanner, printStandloneInitialBanner } from "../utilities/initialBanner.js";
3433
import {
3534
detectPackageNameFromImportPath,
3635
parsePackageName,
@@ -104,6 +103,7 @@ async function startDev(
104103
}
105104

106105
await printStandloneInitialBanner(true);
106+
printDevBanner();
107107

108108
logger.debug("Starting dev session", { dir, options, authorization });
109109

@@ -339,7 +339,7 @@ function useDev({
339339

340340
let firstBuild = true;
341341

342-
logger.log(chalk.dim("⎔ Building background worker..."));
342+
logger.log(chalkGrey("○ Building background worker"));
343343

344344
ctx = await context({
345345
stdin: {
@@ -375,7 +375,7 @@ function useDev({
375375
}
376376

377377
if (!firstBuild) {
378-
logger.log(chalk.dim("⎔ Rebuilding background worker..."));
378+
logger.log(chalkGrey("○ Building background worker"));
379379
}
380380

381381
const metaOutputKey = join("out", `stdin.js`);
@@ -406,9 +406,8 @@ function useDev({
406406
const contentHash = md5Hasher.digest("hex");
407407

408408
if (latestWorkerContentHash === contentHash) {
409-
logger.log(chalk.dim("⎔ No changes detected, skipping build..."));
409+
logger.log(chalkGrey("○ No changes detected, skipping build"));
410410

411-
logger.debug(`No changes detected, skipping build`);
412411
return;
413412
}
414413

@@ -509,19 +508,13 @@ function useDev({
509508

510509
backgroundWorker.metadata = backgroundWorkerRecord.data;
511510

512-
if (firstBuild) {
513-
logger.log(
514-
chalk.green(
515-
`Background worker started (${backgroundWorkerRecord.data.version})`
516-
)
517-
);
518-
} else {
519-
logger.log(
520-
chalk.dim(
521-
`Background worker rebuilt (${backgroundWorkerRecord.data.version})`
522-
)
523-
);
524-
}
511+
logger.log(
512+
`${chalkGrey(
513+
`○ Background worker started -> ${chalkWorker(
514+
backgroundWorkerRecord.data.version
515+
)}`
516+
)}`
517+
);
525518

526519
firstBuild = false;
527520

@@ -555,13 +548,7 @@ function useDev({
555548
await ctx.watch();
556549
}
557550

558-
const throttle = pThrottle({
559-
limit: 1,
560-
interval: 1000,
561-
strict: true,
562-
});
563-
564-
const throttledRebuild = throttle(runBuild);
551+
const throttledRebuild = pDebounce(runBuild, 250, { before: true });
565552

566553
const taskFileWatcher = watch(
567554
config.triggerDirectories.map((triggerDir) => `${triggerDir}/*.ts`),
@@ -570,7 +557,7 @@ function useDev({
570557
}
571558
);
572559

573-
taskFileWatcher.on("change", async (path) => {
560+
taskFileWatcher.on("add", async (path) => {
574561
throttledRebuild().catch((error) => {
575562
logger.error(error);
576563
});

packages/cli-v3/src/commands/login.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
tracer,
1414
wrapCommandAction,
1515
} from "../cli/common.js";
16-
import { chalkLink } from "../utilities/colors.js";
16+
import { chalkLink } from "../utilities/cliOutput.js";
1717
import { readAuthConfigProfile, writeAuthConfigProfile } from "../utilities/configFiles.js";
1818
import { getVersion } from "../utilities/getVersion.js";
1919
import { printInitialBanner } from "../utilities/initialBanner.js";
@@ -75,7 +75,14 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
7575
const authConfig = readAuthConfigProfile(options?.profile);
7676

7777
if (authConfig && authConfig.accessToken) {
78-
const whoAmIResult = await whoAmI({ profile: options?.profile ?? "default", skipTelemetry: !span.isRecording(), logLevel: logger.loggerLevel }, opts.embedded);
78+
const whoAmIResult = await whoAmI(
79+
{
80+
profile: options?.profile ?? "default",
81+
skipTelemetry: !span.isRecording(),
82+
logLevel: logger.loggerLevel,
83+
},
84+
opts.embedded
85+
);
7986

8087
if (!whoAmIResult.success) {
8188
throw new Error(whoAmIResult.error);
@@ -175,9 +182,19 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
175182

176183
getPersonalAccessTokenSpinner.stop(`Logged in with token ${indexResult.obfuscatedToken}`);
177184

178-
writeAuthConfigProfile({ accessToken: indexResult.token, apiUrl: opts.defaultApiUrl }, options?.profile);
185+
writeAuthConfigProfile(
186+
{ accessToken: indexResult.token, apiUrl: opts.defaultApiUrl },
187+
options?.profile
188+
);
179189

180-
const whoAmIResult = await whoAmI({ profile: options?.profile ?? "default", skipTelemetry: !span.isRecording(), logLevel: logger.loggerLevel }, opts.embedded);
190+
const whoAmIResult = await whoAmI(
191+
{
192+
profile: options?.profile ?? "default",
193+
skipTelemetry: !span.isRecording(),
194+
logLevel: logger.loggerLevel,
195+
},
196+
opts.embedded
197+
);
181198

182199
if (!whoAmIResult.success) {
183200
throw new Error(whoAmIResult.error);

packages/cli-v3/src/commands/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { confirm, spinner } from "@clack/prompts";
22
import { RunOptions, run } from "npm-check-updates";
33
import path from "path";
44
import { z } from "zod";
5-
import { chalkError, chalkSuccess } from "../utilities/colors.js";
5+
import { chalkError, chalkSuccess } from "../utilities/cliOutput.js";
66
import { readJSONFileSync, writeJSONFile } from "../utilities/fileSystem.js";
77
import { installDependencies } from "../utilities/installDependencies.js";
88

packages/cli-v3/src/commands/whoami.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
import { intro, note, spinner } from "@clack/prompts";
2-
import { chalkLink } from "../utilities/colors.js";
2+
import { chalkLink } from "../utilities/cliOutput.js";
33
import { logger } from "../utilities/logger.js";
44
import { isLoggedIn } from "../utilities/session.js";
55
import { Command } from "commander";
66
import { printInitialBanner } from "../utilities/initialBanner.js";
7-
import { CommonCommandOptions, commonOptions, handleTelemetry, wrapCommandAction } from "../cli/common.js";
7+
import {
8+
CommonCommandOptions,
9+
commonOptions,
10+
handleTelemetry,
11+
wrapCommandAction,
12+
} from "../cli/common.js";
813
import { z } from "zod";
914
import { CliApiClient } from "../apiClient.js";
1015

1116
type WhoAmIResult =
1217
| {
13-
success: true;
14-
data: {
15-
userId: string;
16-
email: string;
17-
dashboardUrl: string;
18-
};
19-
}
18+
success: true;
19+
data: {
20+
userId: string;
21+
email: string;
22+
dashboardUrl: string;
23+
};
24+
}
2025
| {
21-
success: false;
22-
error: string;
23-
};
26+
success: false;
27+
error: string;
28+
};
2429

2530
const WhoamiCommandOptions = CommonCommandOptions;
2631

2732
type WhoamiCommandOptions = z.infer<typeof WhoamiCommandOptions>;
2833

2934
export function configureWhoamiCommand(program: Command) {
30-
return commonOptions(program
31-
.command("whoami")
32-
.description("display the current logged in user and project details"))
33-
.action(async (options) => {
34-
await handleTelemetry(async () => {
35-
await printInitialBanner(false);
36-
await whoAmICommand(options);
37-
});
35+
return commonOptions(
36+
program.command("whoami").description("display the current logged in user and project details")
37+
).action(async (options) => {
38+
await handleTelemetry(async () => {
39+
await printInitialBanner(false);
40+
await whoAmICommand(options);
3841
});
42+
});
3943
}
4044

4145
export async function whoAmICommand(options: unknown) {
@@ -61,7 +65,11 @@ export async function whoAmI(
6165
if (authentication.error === "fetch failed") {
6266
loadingSpinner.stop("Fetch failed. Platform down?");
6367
} else {
64-
loadingSpinner.stop(`You must login first. Use \`trigger.dev login --profile ${options?.profile ?? "default"}\` to login.`);
68+
loadingSpinner.stop(
69+
`You must login first. Use \`trigger.dev login --profile ${
70+
options?.profile ?? "default"
71+
}\` to login.`
72+
);
6573
}
6674

6775
return {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import chalk from "chalk";
2+
3+
export const green = "#4FFF54";
4+
export const purple = "#735BF3";
5+
6+
export function chalkGreen(text: string) {
7+
return chalk.hex(green)(text);
8+
}
9+
10+
export function chalkPurple(text: string) {
11+
return chalk.hex(purple)(text);
12+
}
13+
14+
export function chalkGrey(text: string) {
15+
return chalk.hex("#878C99")(text);
16+
}
17+
18+
export function chalkError(text: string) {
19+
return chalk.hex("#E11D48")(text);
20+
}
21+
22+
export function chalkWarning(text: string) {
23+
return chalk.yellow(text);
24+
}
25+
26+
export function chalkSuccess(text: string) {
27+
return chalk.hex("#28BF5C")(text);
28+
}
29+
30+
export function chalkLink(text: string) {
31+
return chalk.underline.hex("#D7D9DD")(text);
32+
}
33+
34+
export function chalkWorker(text: string) {
35+
return chalk.hex("#FFFF89")(text);
36+
}
37+
38+
export function chalkTask(text: string) {
39+
return chalk.hex("#60A5FA")(text);
40+
}
41+
42+
export function chalkRun(text: string) {
43+
return chalk.hex("#A78BFA")(text);
44+
}
45+
46+
export function logo() {
47+
return `${chalk.hex(green).bold("Trigger")}${chalk.hex(purple).bold(".dev")}`;
48+
}
49+
50+
// Mar 27 09:17:25.653
51+
export function prettyPrintDate(date: Date = new Date()) {
52+
let formattedDate = new Intl.DateTimeFormat("en-US", {
53+
month: "short",
54+
day: "2-digit",
55+
hour: "2-digit",
56+
minute: "2-digit",
57+
second: "2-digit",
58+
hour12: false,
59+
}).format(date);
60+
61+
// Append milliseconds
62+
formattedDate += "." + ("00" + date.getMilliseconds()).slice(-3);
63+
64+
return formattedDate;
65+
}

packages/cli-v3/src/utilities/colors.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/cli-v3/src/utilities/initialBanner.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import supportsColor from "supports-color";
44
import type { Result } from "update-check";
55
import checkForUpdate from "update-check";
66
import pkg from "../../package.json";
7-
import { chalkGrey, green, logo } from "./colors.js";
7+
import { chalkGrey, chalkRun, chalkTask, chalkWorker, green, logo } from "./cliOutput.js";
88
import { getVersion } from "./getVersion.js";
99
import { logger } from "./logger.js";
1010

@@ -52,9 +52,16 @@ export async function printStandloneInitialBanner(performUpdateCheck = true) {
5252
}
5353
}
5454

55+
logger.log(text + "\n" + (supportsColor.stdout ? chalkGrey("-".repeat(54)) : "-".repeat(54)));
56+
}
57+
58+
export function printDevBanner() {
5559
logger.log(
56-
text + "\n" + (supportsColor.stdout ? chalk.hex(green)("-".repeat(54)) : "-".repeat(54))
60+
`${chalkGrey("Key:")} ${chalkWorker("Worker")} ${chalkGrey("|")} ${chalkTask(
61+
"Task"
62+
)} ${chalkGrey("|")} ${chalkRun("Run")}`
5763
);
64+
logger.log(chalkGrey("-".repeat(54)));
5865
}
5966

6067
async function doUpdateCheck(): Promise<string | undefined> {

0 commit comments

Comments
 (0)