Skip to content

Commit a6b2499

Browse files
committed
Enhance lifecycle command execution with a delay and improve logging
- Added a 5-second sleep command in the lifecycle start sequence to ensure proper initialization. - Introduced console logging for command execution starts and completions in the executeCommand utility, enhancing visibility during background and synchronous command executions. - Added empty console logs in startApp and stopApp functions for better separation of log outputs.
1 parent 569ae78 commit a6b2499

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

demo/.testing/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ lifecycle:
22
start:
33
- command: echo 'Start database here'
44
timeout: 30000
5+
- command: sleep 5
6+
timeout: 10000
57
- command: pnpm dev
68
keepAlive: true
79
envs:

src/core/start-app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export async function startApp(config: Config, url?: string): Promise<() => Prom
1919
}
2020
}
2121

22+
console.log();
23+
2224
// Wait for URL to become available if:
2325
// 1. A URL was provided AND
2426
// 2. At least one command has keepAlive: true

src/core/stop-app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { executeCommand } from "./utils/execute-command.js";
77
* @param config The validated configuration object
88
*/
99
export async function stopApp(cleanup: () => Promise<void>, config: Config): Promise<void> {
10+
console.log();
11+
1012
// First, execute the cleanup function to stop running processes
1113
await cleanup();
1214

src/core/utils/execute-command.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import chalk from "chalk";
12
import { execa } from "execa";
23
import type { LifecycleCommand } from "../types.js";
34

@@ -30,23 +31,34 @@ export async function executeCommand(
3031
const envVars = cmd.envs ? { ...process.env, ...cmd.envs } : process.env;
3132

3233
if (isBackground || cmd.keepAlive) {
34+
// Log execution start for background process - only show "Executing" since it runs indefinitely
35+
process.stdout.write(`${chalk.cyan("Executing:")} ${chalk.dim(cmd.command)}\n`);
36+
3337
// Start process in background - no timeout since it runs indefinitely
3438
// The process will be manually killed later via the cleanup function
35-
const process = execa(command, args, {
39+
const childProcess = execa(command, args, {
3640
cleanup: true,
3741
detached: false,
3842
// Don't pass timeout - this process runs until manually killed
3943
env: envVars,
4044
});
4145

4246
// Don't await, just return the process
43-
return { process, command: cmd.command };
47+
// Skip "Executed" message for background processes since they run indefinitely
48+
return { process: childProcess, command: cmd.command };
4449
}
4550

51+
// Log execution start for synchronous command (without newline)
52+
process.stdout.write(`${chalk.cyan("Executing:")} ${chalk.dim(cmd.command)}`);
53+
4654
// Execute synchronously and wait for completion
4755
await execa(command, args, {
4856
timeout,
4957
env: envVars,
5058
});
59+
60+
// Clear the line and overwrite with success message
61+
process.stdout.write(`\r\x1b[K${chalk.green("Executed :")} ${chalk.dim(cmd.command)}\n`);
62+
5163
return null;
5264
}

0 commit comments

Comments
 (0)