Skip to content

Commit d3cb09f

Browse files
committed
Add --plain option for simpler build server logs
1 parent 85fd901 commit d3cb09f

File tree

5 files changed

+96
-38
lines changed

5 files changed

+96
-38
lines changed

packages/cli-v3/src/build/buildWorker.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { isWindows } from "std-env";
1818
import { pathToFileURL } from "node:url";
1919
import { logger } from "../utilities/logger.js";
2020
import { SdkVersionExtractor } from "./plugins.js";
21+
import { spinner } from "../utilities/windows.js";
2122

2223
export type BuildWorkerEventListener = {
2324
onBundleStart?: () => void;
@@ -34,6 +35,7 @@ export type BuildWorkerOptions = {
3435
envVars?: Record<string, string>;
3536
rewritePaths?: boolean;
3637
forcedExternals?: string[];
38+
plain?: boolean;
3739
};
3840

3941
export async function buildWorker(options: BuildWorkerOptions) {
@@ -48,7 +50,21 @@ export async function buildWorker(options: BuildWorkerOptions) {
4850
resolvedConfig,
4951
options.forcedExternals
5052
);
51-
const buildContext = createBuildContext(options.target, resolvedConfig);
53+
const buildContext = createBuildContext(options.target, resolvedConfig, {
54+
logger: options.plain
55+
? {
56+
debug: (...args) => console.log(...args),
57+
log: (...args) => console.log(...args),
58+
warn: (...args) => console.log(...args),
59+
progress: (message) => console.log(message),
60+
spinner: (message) => {
61+
const $spinner = spinner({ plain: true });
62+
$spinner.start(message);
63+
return $spinner;
64+
},
65+
}
66+
: undefined,
67+
});
5268
buildContext.prependExtension(externalsExtension);
5369
await notifyExtensionOnBuildStart(buildContext);
5470
const pluginsFromExtensions = resolvePluginsForContext(buildContext);

packages/cli-v3/src/build/extensions.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
type BuildLogger,
23
BuildContext,
34
BuildExtension,
45
BuildLayer,
@@ -9,7 +10,8 @@ import { BuildManifest, BuildTarget } from "@trigger.dev/core/v3/schemas";
910
import * as esbuild from "esbuild";
1011
import { logger } from "../utilities/logger.js";
1112
import { resolveModule } from "./resolveModule.js";
12-
import { log, spinner } from "@clack/prompts";
13+
import { log } from "@clack/prompts";
14+
import { spinner } from "../utilities/windows.js";
1315

1416
export interface InternalBuildContext extends BuildContext {
1517
getLayers(): BuildLayer[];
@@ -54,12 +56,25 @@ export async function notifyExtensionOnBuildComplete(
5456

5557
export function createBuildContext(
5658
target: BuildTarget,
57-
config: ResolvedConfig
59+
config: ResolvedConfig,
60+
options?: { logger?: BuildLogger }
5861
): InternalBuildContext {
5962
const layers: BuildLayer[] = [];
6063
const registeredPlugins: RegisteredPlugin[] = [];
6164
const extensions: BuildExtension[] = config.build.extensions ?? [];
6265

66+
const buildLogger = options?.logger ?? {
67+
debug: (...args) => logger.debug(...args),
68+
log: (...args) => logger.log(...args),
69+
warn: (...args) => logger.warn(...args),
70+
progress: (message) => log.message(message),
71+
spinner: (message) => {
72+
const $spinner = spinner();
73+
$spinner.start(message);
74+
return $spinner;
75+
},
76+
};
77+
6378
return {
6479
target,
6580
config: config,
@@ -99,17 +114,7 @@ export function createBuildContext(
99114
prependExtension(extension) {
100115
extensions.unshift(extension);
101116
},
102-
logger: {
103-
debug: (...args) => logger.debug(...args),
104-
log: (...args) => logger.log(...args),
105-
warn: (...args) => logger.warn(...args),
106-
progress: (message) => log.message(message),
107-
spinner: (message) => {
108-
const $spinner = spinner();
109-
$spinner.start(message);
110-
return $spinner;
111-
},
112-
},
117+
logger: buildLogger,
113118
};
114119
}
115120

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

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const DeployCommandOptions = CommonCommandOptions.extend({
8080
builder: z.string().default("trigger"),
8181
nativeBuildServer: z.boolean().default(false),
8282
detach: z.boolean().default(false),
83+
plain: z.boolean().default(false),
8384
});
8485

8586
type DeployCommandOptions = z.infer<typeof DeployCommandOptions>;
@@ -184,6 +185,7 @@ export function configureDeployCommand(program: Command) {
184185
"Return immediately after the deployment is queued, do not wait for the build to complete. Implies using the native build server."
185186
).implies({ nativeBuildServer: true })
186187
)
188+
.addOption(new CommandOption("--plain", "Plain output").hideHelp())
187189
.action(async (path, options) => {
188190
await handleTelemetry(async () => {
189191
await printStandloneInitialBanner(true);
@@ -200,7 +202,9 @@ export async function deployCommand(dir: string, options: unknown) {
200202
}
201203

202204
async function _deployCommand(dir: string, options: DeployCommandOptions) {
203-
intro(`Deploying project${options.skipPromotion ? " (without promotion)" : ""}`);
205+
if (!options.plain) {
206+
intro(`Deploying project${options.skipPromotion ? " (without promotion)" : ""}`);
207+
}
204208

205209
if (!options.skipUpdateCheck) {
206210
await updateTriggerPackages(dir, { ...options }, true, true);
@@ -215,6 +219,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
215219
embedded: true,
216220
defaultApiUrl: options.apiUrl,
217221
profile: options.profile,
222+
silent: options.plain,
218223
});
219224

220225
if (!authorization.ok) {
@@ -321,7 +326,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
321326

322327
const destination = getTmpDir(resolvedConfig.workingDir, "build", options.dryRun);
323328

324-
const $buildSpinner = spinner();
329+
const $buildSpinner = spinner({ plain: options.plain });
325330

326331
const forcedExternals = await resolveAlwaysExternal(projectClient.client);
327332

@@ -337,13 +342,13 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
337342
rewritePaths: true,
338343
envVars: serverEnvVars.success ? serverEnvVars.data.variables : {},
339344
forcedExternals,
345+
plain: options.plain,
340346
listener: {
341347
onBundleStart() {
342348
$buildSpinner.start("Building trigger code");
343349
},
344350
onBundleComplete(result) {
345351
$buildSpinner.stop("Successfully built code");
346-
347352
logger.debug("Bundle result", result);
348353
},
349354
},
@@ -403,7 +408,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
403408
const vars = numberOfEnvVars === 1 ? "var" : "vars";
404409

405410
if (!options.skipSyncEnvVars) {
406-
const $spinner = spinner();
411+
const $spinner = spinner({ plain: options.plain });
407412
$spinner.start(`Syncing ${numberOfEnvVars} env ${vars} with the server`);
408413

409414
const uploadResult = await syncEnvVarsWithServer(
@@ -445,14 +450,16 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
445450
const deploymentLink = cliLink("View deployment", rawDeploymentLink);
446451
const testLink = cliLink("Test tasks", rawTestLink);
447452

448-
const $spinner = spinner();
453+
const $spinner = spinner({ plain: options.plain });
449454

450455
const buildSuffix =
451456
isLocalBuild && !process.env.TRIGGER_LOCAL_BUILD_LABEL_DISABLED ? " (local)" : "";
452457
const deploySuffix =
453458
isLocalBuild && !process.env.TRIGGER_LOCAL_BUILD_LABEL_DISABLED ? " (local build)" : "";
454459

455-
if (isCI) {
460+
if (options.plain) {
461+
$spinner.start(`Building version ${version}${buildSuffix}`);
462+
} else if (isCI) {
456463
log.step(`Building version ${version}\n`);
457464
} else {
458465
if (isLinksSupported) {
@@ -485,7 +492,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
485492
compilationPath: destination.path,
486493
buildEnvVars: buildManifest.build.env,
487494
onLog: (logMessage) => {
488-
if (isCI) {
495+
if (options.plain || isCI) {
489496
console.log(logMessage);
490497
return;
491498
}
@@ -582,7 +589,9 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
582589
throw new SkipLoggingError(errorData?.message ?? "Failed to get deployment with worker");
583590
}
584591

585-
if (isCI) {
592+
if (options.plain) {
593+
$spinner.message(`Deploying version ${version}${deploySuffix}`);
594+
} else if (isCI) {
586595
log.step(`Deploying version ${version}${deploySuffix}\n`);
587596
} else {
588597
if (isLinksSupported) {
@@ -600,7 +609,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
600609
skipPushToRegistry: remoteBuildExplicitlySkipped,
601610
},
602611
(logMessage) => {
603-
if (isCI) {
612+
if (options.plain || isCI) {
604613
console.log(logMessage);
605614
return;
606615
}
@@ -627,26 +636,39 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
627636
throw new SkipLoggingError("Failed to finalize deployment");
628637
}
629638

630-
if (isCI) {
639+
if (options.plain) {
640+
console.log(`Successfully deployed version ${version}${deploySuffix}`);
641+
} else if (isCI) {
631642
log.step(`Successfully deployed version ${version}${deploySuffix}`);
632643
} else {
633644
$spinner.stop(`Successfully deployed version ${version}${deploySuffix}`);
634645
}
635646

636647
const taskCount = deploymentWithWorker.worker?.tasks.length ?? 0;
637648

638-
outro(
639-
`Version ${version} deployed with ${taskCount} detected task${taskCount === 1 ? "" : "s"} ${
640-
isLinksSupported ? `| ${deploymentLink} | ${testLink}` : ""
641-
}`
642-
);
649+
if (options.plain) {
650+
console.log(
651+
`Version ${version} deployed with ${taskCount} detected task${taskCount === 1 ? "" : "s"}`
652+
);
653+
654+
if (!process.env.TRIGGER_DEPLOYMENT_LINK_OUTPUT_DISABLED) {
655+
console.log(`Deployment: ${rawDeploymentLink}`);
656+
console.log(`Test: ${rawTestLink}`);
657+
}
658+
} else {
659+
outro(
660+
`Version ${version} deployed with ${taskCount} detected task${taskCount === 1 ? "" : "s"} ${
661+
isLinksSupported ? `| ${deploymentLink} | ${testLink}` : ""
662+
}`
663+
);
643664

644-
if (!isLinksSupported) {
645-
console.log("View deployment");
646-
console.log(rawDeploymentLink);
647-
console.log(); // new line
648-
console.log("Test tasks");
649-
console.log(rawTestLink);
665+
if (!isLinksSupported) {
666+
console.log("View deployment");
667+
console.log(rawDeploymentLink);
668+
console.log(); // new line
669+
console.log("Test tasks");
670+
console.log(rawTestLink);
671+
}
650672
}
651673

652674
if (options.saveLogs) {

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,23 @@ const ballmerSpinner = () => ({
9898
},
9999
});
100100

101+
const plainSpinner = () => ({
102+
start: (msg?: string): void => {
103+
console.log(msg ?? "");
104+
},
105+
stop: (msg?: string, code?: number): void => {
106+
if (msg) console.log(msg ?? "");
107+
},
108+
message: (msg?: string): void => {
109+
if (msg) console.log(msg ?? "");
110+
},
111+
});
112+
101113
// This will become unecessary with the next clack release, the bug was fixed here:
102114
// https://github.com/natemoo-re/clack/pull/182
103-
export const spinner = (options: { cancelMessage?: string } = {}) =>
104-
isWindows ? ballmerSpinner() : wrappedClackSpinner(options);
115+
export const spinner = (options: { cancelMessage?: string; plain?: boolean } = {}) =>
116+
options.plain
117+
? plainSpinner()
118+
: isWindows
119+
? ballmerSpinner()
120+
: wrappedClackSpinner({ cancelMessage: options.cancelMessage });

references/hello-world/trigger.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default defineConfig({
2626
extensions: [
2727
lightpanda(),
2828
syncEnvVars(async (ctx) => {
29-
console.log("syncEnvVars", { environment: ctx.environment, branch: ctx.branch });
3029
return [
3130
{ name: "SYNC_ENV", value: ctx.environment },
3231
{ name: "BRANCH", value: ctx.branch ?? "NO_BRANCH" },

0 commit comments

Comments
 (0)