Skip to content

Commit

Permalink
[eas-cli] Silence all non-command output in non-interactive mode of e…
Browse files Browse the repository at this point in the history
…as env:exec
  • Loading branch information
wschurman committed Jan 6, 2025
1 parent 59bbe19 commit 09c685e
Showing 1 changed file with 50 additions and 15 deletions.
65 changes: 50 additions & 15 deletions packages/eas-cli/src/commands/env/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,20 @@ export default class EnvExec extends EasCommand {
graphqlClient,
projectId,
environment,
nonInteractive: parsedFlags.nonInteractive,
});

await this.runCommandWithEnvVarsAsync({
command: parsedFlags.command,
environmentVariables,
});
if (parsedFlags.nonInteractive) {
await this.runCommandNonInteractiveWithEnvVarsAsync({
command: parsedFlags.command,
environmentVariables,
});
} else {
await this.runCommandWithEnvVarsAsync({
command: parsedFlags.command,
environmentVariables,
});
}
}

private sanitizeFlagsAndArgs(
Expand All @@ -103,6 +111,29 @@ export default class EnvExec extends EasCommand {
};
}

private async runCommandNonInteractiveWithEnvVarsAsync({
command,
environmentVariables,
}: {
command: string;
environmentVariables: Record<string, string>;
}): Promise<void> {
try {
const { stdout } = await spawnAsync('bash', ['-c', command], {
env: {
...process.env,
...environmentVariables,
},
});
Log.log(stdout);
} catch (error: any) {
if (error.stderr) {
Log.error(error.stderr);
}
throw error;
}
}

private async runCommandWithEnvVarsAsync({
command,
environmentVariables,
Expand Down Expand Up @@ -147,10 +178,12 @@ export default class EnvExec extends EasCommand {
graphqlClient,
projectId,
environment,
nonInteractive,
}: {
graphqlClient: ExpoGraphqlClient;
projectId: string;
environment: EnvironmentVariableEnvironment;
nonInteractive: boolean;
}): Promise<Record<string, string>> {
const environmentVariablesQueryResult =
await EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, {
Expand All @@ -162,18 +195,20 @@ export default class EnvExec extends EasCommand {
({ value }) => !!value
);

if (nonSecretEnvironmentVariables.length > 0) {
Log.log(
`Environment variables with visibility "Plain text" and "Sensitive" loaded from the "${environment.toLowerCase()}" environment on EAS: ${nonSecretEnvironmentVariables
.map(e => e.name)
.join(', ')}.`
);
} else {
Log.log(
`No environment variables with visibility "Plain text" and "Sensitive" found for the "${environment.toLowerCase()}" environment on EAS.`
);
if (!nonInteractive) {
if (nonSecretEnvironmentVariables.length > 0) {
Log.log(
`Environment variables with visibility "Plain text" and "Sensitive" loaded from the "${environment.toLowerCase()}" environment on EAS: ${nonSecretEnvironmentVariables
.map(e => e.name)
.join(', ')}.`
);
} else {
Log.log(
`No environment variables with visibility "Plain text" and "Sensitive" found for the "${environment.toLowerCase()}" environment on EAS.`
);
}
Log.newLine();
}
Log.newLine();

const environmentVariables: Record<string, string> = {};
for (const { name, value } of nonSecretEnvironmentVariables) {
Expand Down

0 comments on commit 09c685e

Please sign in to comment.