Skip to content

Commit

Permalink
Ask for file path in env:* commands (#2635)
Browse files Browse the repository at this point in the history
# Why

[ENG-13855: When creating `file` type env var in `env:create` ask about file path vs variable value](https://linear.app/expo/issue/ENG-13855/when-creating-file-type-env-var-in-envcreate-ask-about-file-path-vs)
  • Loading branch information
khamilowicz authored Oct 18, 2024
1 parent 1873804 commit c07fd22
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/eas-cli/src/commands/env/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
value = await promptVariableValueAsync({
nonInteractive,
hidden: newVisibility !== EnvironmentVariableVisibility.Public,
filePath: newType === EnvironmentSecretType.FileBase64,
});
}

Expand Down
8 changes: 2 additions & 6 deletions packages/eas-cli/src/commands/env/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ export default class EnvironmentVariableUpdate extends EasCommand {
}
}

Log.log(
selectedVariable.type,
EnvironmentSecretType.String === selectedVariable.type,
EnvironmentSecretType.FileBase64 === selectedVariable.type
);
if (!type && !value && !nonInteractive) {
newType = await promptVariableTypeAsync(nonInteractive, selectedVariable.type);

Expand All @@ -250,6 +245,7 @@ export default class EnvironmentVariableUpdate extends EasCommand {
value = await promptVariableValueAsync({
nonInteractive,
required: false,
filePath: (newType ?? selectedVariable.type) === EnvironmentSecretType.FileBase64,
initial:
(newType ?? selectedVariable.type) === EnvironmentSecretType.FileBase64
? undefined
Expand All @@ -263,7 +259,7 @@ export default class EnvironmentVariableUpdate extends EasCommand {

let environmentFilePath: string | undefined;

if (newType === EnvironmentSecretType.FileBase64 && value) {
if ((newType ?? selectedVariable.type) === EnvironmentSecretType.FileBase64 && value) {
environmentFilePath = path.resolve(value);
if (!(await fs.pathExists(environmentFilePath))) {
throw new Error(`File "${value}" does not exist`);
Expand Down
6 changes: 4 additions & 2 deletions packages/eas-cli/src/utils/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ export async function promptVariableValueAsync({
nonInteractive,
required = true,
hidden = false,
filePath = false,
initial,
}: {
nonInteractive: boolean;
required?: boolean;
initial?: string | null;
filePath?: boolean;
hidden?: boolean;
}): Promise<string> {
if (nonInteractive && required) {
Expand All @@ -142,9 +144,9 @@ export async function promptVariableValueAsync({
}

const { variableValue } = await promptAsync({
type: hidden ? 'password' : 'text',
type: hidden && !filePath ? 'password' : 'text',
name: 'variableValue',
message: 'Variable value:',
message: filePath ? 'File path:' : 'Variable value:',
initial: initial ?? '',
validate: variableValue => {
if (!required) {
Expand Down

0 comments on commit c07fd22

Please sign in to comment.