Skip to content

Commit d6b6aa7

Browse files
committed
fixing small bug with ui
1 parent 004faa1 commit d6b6aa7

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/cmd/run.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { Command } from "commander";
88
export async function runCommand(
99
projectconfig: ProjectConfig,
1010
cmd: string[],
11-
options?: { env?: string },
11+
options?: { env?: string; unmountSpinner?: () => void },
1212
): Promise<void> {
1313
const provider = providerRegistry.get(projectconfig.provider);
1414
if (!provider) {
@@ -22,6 +22,11 @@ export async function runCommand(
2222
const secrets = await provider.run(projectconfig, { env: options?.env });
2323
const env = buildEnvWithSecrets(secrets);
2424

25+
// Unmount spinner right after secrets are fetched, before command runs
26+
if (options?.unmountSpinner) {
27+
options.unmountSpinner();
28+
}
29+
2530
if (cmd.length === 0) {
2631
throw new Error("Command is required. Please provide a command to run.");
2732
}
@@ -60,8 +65,11 @@ export function registerRunCommand(program: Command) {
6065

6166
await RunFlow({
6267
envName: opts.env,
63-
run: async () => {
64-
await runCommand(projectConfig, cmd, opts);
68+
run: async (unmountSpinner) => {
69+
await runCommand(projectConfig, cmd, {
70+
...opts,
71+
unmountSpinner,
72+
});
6573
},
6674
});
6775
} catch (error) {

src/ui/RunFlow.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Spinner from "ink-spinner";
33

44
export interface RunFlowProps {
55
envName?: string;
6-
run: () => Promise<void>;
6+
run: (unmountSpinner: () => void) => Promise<void>;
77
}
88

99
function SpinnerComponent({ message }: { message: string }) {
@@ -24,17 +24,18 @@ export async function RunFlow({ envName, run }: RunFlowProps): Promise<void> {
2424
stdout: process.stderr,
2525
});
2626

27+
const unmountSpinner = () => spinner.unmount();
28+
2729
try {
28-
await run();
30+
await run(unmountSpinner);
2931

30-
spinner.unmount();
3132
const successMessage = envName
3233
? `Secrets injected successfully for environment "${envName}".\n`
3334
: "Secrets injected successfully.\n";
35+
3436
process.stderr.write(successMessage);
3537
} catch (error) {
3638
spinner.unmount();
37-
// Re-throw error - let command handler log it
3839
throw error;
3940
}
4041
}

test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
for (let i = 0; i < 2; i++) {
2+
//dealy of 1 sceond
3+
await new Promise((resolve) => setTimeout(resolve, 1000));
4+
console.log("Hello, world!");
5+
}

0 commit comments

Comments
 (0)