eas-cli 12.5.2 → 12.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +60 -60
  2. package/build/commandUtils/context/DynamicProjectConfigContextField.d.ts +1 -1
  3. package/build/commandUtils/context/OptionalPrivateProjectConfigContextField.d.ts +1 -1
  4. package/build/commandUtils/context/PrivateProjectConfigContextField.d.ts +1 -1
  5. package/build/commandUtils/context/contextUtils/getProjectIdAsync.d.ts +1 -1
  6. package/build/commandUtils/flags.d.ts +2 -2
  7. package/build/commandUtils/flags.js +1 -6
  8. package/build/commands/env/create.d.ts +3 -2
  9. package/build/commands/env/create.js +43 -7
  10. package/build/commands/env/get.js +11 -13
  11. package/build/commands/env/link.js +3 -0
  12. package/build/commands/env/list.d.ts +1 -0
  13. package/build/commands/env/list.js +21 -7
  14. package/build/commands/env/pull.js +1 -1
  15. package/build/commands/env/push.d.ts +1 -1
  16. package/build/commands/env/push.js +80 -74
  17. package/build/commands/env/update.d.ts +4 -2
  18. package/build/commands/env/update.js +88 -22
  19. package/build/eas-update/utils.d.ts +1 -1
  20. package/build/graphql/generated.d.ts +16 -0
  21. package/build/graphql/mutations/EnvironmentVariableMutation.d.ts +1 -1
  22. package/build/graphql/queries/EnvironmentVariablesQuery.d.ts +15 -8
  23. package/build/graphql/queries/EnvironmentVariablesQuery.js +25 -14
  24. package/build/graphql/types/EnvironmentVariable.js +1 -0
  25. package/build/graphql/types/EnvironmentVariableWithSecret.d.ts +1 -0
  26. package/build/graphql/types/EnvironmentVariableWithSecret.js +18 -0
  27. package/build/metadata/download.d.ts +1 -1
  28. package/build/metadata/upload.d.ts +1 -1
  29. package/build/prompts.d.ts +1 -0
  30. package/build/prompts.js +2 -0
  31. package/build/update/configure.d.ts +1 -1
  32. package/build/utils/expoCli.d.ts +1 -1
  33. package/build/utils/prompts.d.ts +5 -2
  34. package/build/utils/prompts.js +55 -12
  35. package/build/utils/variableUtils.d.ts +3 -1
  36. package/build/utils/variableUtils.js +34 -3
  37. package/oclif.manifest.json +36 -8
  38. package/package.json +3 -4
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@oclif/core");
6
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
8
+ const path_1 = tslib_1.__importDefault(require("path"));
7
9
  const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand"));
8
10
  const flags_1 = require("../../commandUtils/flags");
9
11
  const generated_1 = require("../../graphql/generated");
@@ -18,7 +20,7 @@ class EnvironmentVariableCreate extends EasCommand_1.default {
18
20
  async runAsync() {
19
21
  const { flags } = await this.parse(_a);
20
22
  const validatedFlags = this.validateFlags(flags);
21
- const { name, value, scope, 'non-interactive': nonInteractive, environment: environments, visibility, link, force, } = await this.promptForMissingFlagsAsync(validatedFlags);
23
+ const { name, value, scope, 'non-interactive': nonInteractive, environment: environments, visibility, link, force, type, } = await this.promptForMissingFlagsAsync(validatedFlags);
22
24
  const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
23
25
  nonInteractive,
24
26
  });
@@ -63,13 +65,14 @@ class EnvironmentVariableCreate extends EasCommand_1.default {
63
65
  value,
64
66
  visibility,
65
67
  environments,
68
+ type,
66
69
  })
67
70
  : await EnvironmentVariableMutation_1.EnvironmentVariableMutation.createForAppAsync(graphqlClient, {
68
71
  name,
69
72
  value,
70
73
  environments,
71
74
  visibility,
72
- type: generated_1.EnvironmentSecretType.String,
75
+ type: type ?? generated_1.EnvironmentSecretType.String,
73
76
  }, projectId);
74
77
  if (!variable) {
75
78
  throw new Error(`Could not create variable with name ${name} on project ${projectDisplayName}`);
@@ -98,13 +101,14 @@ class EnvironmentVariableCreate extends EasCommand_1.default {
98
101
  value,
99
102
  visibility,
100
103
  environments,
104
+ type,
101
105
  })
102
106
  : await EnvironmentVariableMutation_1.EnvironmentVariableMutation.createSharedVariableAsync(graphqlClient, {
103
107
  name,
104
108
  value,
105
109
  visibility,
106
110
  environments,
107
- type: generated_1.EnvironmentSecretType.String,
111
+ type: type ?? generated_1.EnvironmentSecretType.String,
108
112
  }, ownerAccount.id);
109
113
  if (!variable) {
110
114
  throw new Error(`Could not create variable with name ${name} on account ${ownerAccount.name}`);
@@ -133,34 +137,62 @@ class EnvironmentVariableCreate extends EasCommand_1.default {
133
137
  throw new Error(`${message} Use --force to overwrite it.`);
134
138
  }
135
139
  }
136
- async promptForMissingFlagsAsync({ name, value, environment, visibility = generated_1.EnvironmentVariableVisibility.Public, 'non-interactive': nonInteractive, ...rest }) {
140
+ async promptForMissingFlagsAsync({ name, value, environment, visibility, 'non-interactive': nonInteractive, type, ...rest }) {
137
141
  if (!name) {
138
142
  name = await (0, prompts_2.promptVariableNameAsync)(nonInteractive);
139
143
  }
144
+ let newType;
145
+ let newVisibility = visibility ? (0, prompts_2.parseVisibility)(visibility) : undefined;
146
+ if (type === 'file') {
147
+ newType = generated_1.EnvironmentSecretType.FileBase64;
148
+ }
149
+ else if (type === 'string') {
150
+ newType = generated_1.EnvironmentSecretType.String;
151
+ }
152
+ if (!type && !value && !nonInteractive) {
153
+ newType = await (0, prompts_2.promptVariableTypeAsync)(nonInteractive);
154
+ }
155
+ if (!newVisibility) {
156
+ newVisibility = await (0, prompts_2.promptVariableVisibilityAsync)(nonInteractive);
157
+ }
140
158
  if (!value) {
141
159
  value = await (0, prompts_2.promptVariableValueAsync)({
142
160
  nonInteractive,
143
- hidden: visibility !== generated_1.EnvironmentVariableVisibility.Public,
161
+ hidden: newVisibility !== generated_1.EnvironmentVariableVisibility.Public,
162
+ filePath: newType === generated_1.EnvironmentSecretType.FileBase64,
144
163
  });
145
164
  }
165
+ let environmentFilePath;
166
+ if (newType === generated_1.EnvironmentSecretType.FileBase64) {
167
+ environmentFilePath = path_1.default.resolve(value);
168
+ if (!(await fs_extra_1.default.pathExists(environmentFilePath))) {
169
+ throw new Error(`File "${value}" does not exist`);
170
+ }
171
+ }
172
+ value = environmentFilePath ? await fs_extra_1.default.readFile(environmentFilePath, 'base64') : value;
146
173
  if (!environment) {
147
174
  environment = await (0, prompts_2.promptVariableEnvironmentAsync)({ nonInteractive, multiple: true });
175
+ if (!environment || environment.length === 0) {
176
+ throw new Error('No environments selected');
177
+ }
148
178
  }
179
+ newVisibility = newVisibility ?? generated_1.EnvironmentVariableVisibility.Public;
149
180
  return {
150
181
  name,
151
182
  value,
152
183
  environment,
153
- visibility,
184
+ visibility: newVisibility,
154
185
  link: rest.link ?? false,
155
186
  force: rest.force ?? false,
156
187
  scope: rest.scope ?? generated_1.EnvironmentVariableScope.Project,
157
188
  'non-interactive': nonInteractive,
189
+ type: newType,
158
190
  ...rest,
159
191
  };
160
192
  }
161
193
  validateFlags(flags) {
162
194
  if (flags.scope !== generated_1.EnvironmentVariableScope.Shared && flags.link) {
163
- throw new Error(`Unexpected argument: --link can only be used when creating shared variables`);
195
+ throw new Error(`Unexpected argument: --link can only be used when creating shared variables`);
164
196
  }
165
197
  if (flags.scope === generated_1.EnvironmentVariableScope.Shared &&
166
198
  flags.environment &&
@@ -188,6 +220,10 @@ EnvironmentVariableCreate.flags = {
188
220
  description: 'Overwrite existing variable',
189
221
  default: false,
190
222
  }),
223
+ type: core_1.Flags.enum({
224
+ description: 'The type of variable',
225
+ options: ['string', 'file'],
226
+ }),
191
227
  ...flags_1.EASVariableVisibilityFlag,
192
228
  ...flags_1.EASVariableScopeFlag,
193
229
  ...flags_1.EASMultiEnvironmentFlag,
@@ -3,7 +3,6 @@ var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@oclif/core");
6
- const assert_1 = tslib_1.__importDefault(require("assert"));
7
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
7
  const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand"));
9
8
  const flags_1 = require("../../commandUtils/flags");
@@ -22,6 +21,12 @@ class EnvironmentVariableGet extends EasCommand_1.default {
22
21
  if (!name) {
23
22
  name = await (0, prompts_1.promptVariableNameAsync)(nonInteractive);
24
23
  }
24
+ if (!environment) {
25
+ environment = await (0, prompts_1.promptVariableEnvironmentAsync)({
26
+ nonInteractive,
27
+ multiple: false,
28
+ });
29
+ }
25
30
  const variables = await getVariablesAsync(graphqlClient, scope, projectId, name, environment);
26
31
  if (variables.length === 0) {
27
32
  log_1.default.error(`Variable with name "${name}" not found`);
@@ -29,29 +34,20 @@ class EnvironmentVariableGet extends EasCommand_1.default {
29
34
  }
30
35
  let variable;
31
36
  if (variables.length > 1) {
32
- if (!environment) {
33
- const availableEnvironments = variables.reduce((acc, v) => [...acc, ...(v.environments ?? [])], []);
34
- environment = await (0, prompts_1.promptVariableEnvironmentAsync)({
35
- nonInteractive,
36
- multiple: false,
37
- availableEnvironments,
38
- });
39
- }
40
- (0, assert_1.default)(environment, 'Environment is required.');
41
37
  const variableInEnvironment = variables.find(v => v.environments?.includes(environment));
42
38
  if (!variableInEnvironment) {
43
- throw new Error(`Variable with name "${name}" not found in environment "${environment}"`);
39
+ throw new Error(`Variable with name "${name}" not found in environment "${environment.toLocaleLowerCase()}"`);
44
40
  }
45
41
  variable = variableInEnvironment;
46
42
  }
47
43
  else {
48
44
  variable = variables[0];
49
45
  }
50
- if (!variable.value) {
46
+ if (variable.visibility === generated_1.EnvironmentVariableVisibility.Secret) {
51
47
  throw new Error(`${chalk_1.default.bold(variable.name)} is a secret variable and cannot be displayed once it has been created.`);
52
48
  }
53
49
  if (format === 'short') {
54
- log_1.default.log(`${chalk_1.default.bold(variable.name)}=${variable.value}`);
50
+ log_1.default.log(`${chalk_1.default.bold(variable.name)}=${(0, variableUtils_1.formatVariableValue)(variable)}`);
55
51
  }
56
52
  else {
57
53
  log_1.default.log((0, variableUtils_1.formatVariable)(variable));
@@ -101,6 +97,7 @@ async function getVariablesAsync(graphqlClient, scope, projectId, name, environm
101
97
  appId: projectId,
102
98
  environment,
103
99
  filterNames: [name],
100
+ includeFileContent: true,
104
101
  });
105
102
  return appVariables;
106
103
  }
@@ -108,6 +105,7 @@ async function getVariablesAsync(graphqlClient, scope, projectId, name, environm
108
105
  const sharedVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedWithSensitiveAsync(graphqlClient, {
109
106
  appId: projectId,
110
107
  filterNames: [name],
108
+ includeFileContent: true,
111
109
  });
112
110
  return sharedVariables;
113
111
  }
@@ -28,6 +28,9 @@ class EnvironmentVariableLink extends EasCommand_1.default {
28
28
  });
29
29
  let selectedVariable = variables[0];
30
30
  if (variables.length > 1) {
31
+ if (nonInteractive) {
32
+ throw new Error('Multiple variables found, run command with --variable-name and --variable-environment arguments.');
33
+ }
31
34
  selectedVariable = await (0, prompts_1.selectAsync)('Select shared variable', variables.map(variable => ({
32
35
  title: (0, variableUtils_1.formatVariableName)(variable),
33
36
  value: variable,
@@ -12,6 +12,7 @@ export default class EnvironmentValueList extends EasCommand {
12
12
  scope: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableScope>;
13
13
  format: import("@oclif/core/lib/interfaces").OptionFlag<string>;
14
14
  'include-sensitive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
15
+ 'include-file-content': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
15
16
  };
16
17
  runAsync(): Promise<void>;
17
18
  }
@@ -11,29 +11,36 @@ const EnvironmentVariablesQuery_1 = require("../../graphql/queries/EnvironmentVa
11
11
  const log_1 = tslib_1.__importDefault(require("../../log"));
12
12
  const prompts_1 = require("../../utils/prompts");
13
13
  const variableUtils_1 = require("../../utils/variableUtils");
14
- async function getVariablesForScopeAsync(graphqlClient, { scope, includingSensitive, environment, projectId, }) {
14
+ async function getVariablesForScopeAsync(graphqlClient, { scope, includingSensitive, includeFileContent, environment, projectId, }) {
15
15
  if (scope === generated_1.EnvironmentVariableScope.Project) {
16
16
  if (includingSensitive) {
17
17
  return await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, {
18
18
  appId: projectId,
19
19
  environment,
20
+ includeFileContent,
20
21
  });
21
22
  }
22
23
  return await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
23
24
  appId: projectId,
24
25
  environment,
26
+ includeFileContent,
25
27
  });
26
28
  }
27
29
  return includingSensitive
28
30
  ? await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedWithSensitiveAsync(graphqlClient, {
29
31
  appId: projectId,
30
32
  environment,
33
+ includeFileContent,
31
34
  })
32
- : await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, { appId: projectId, environment });
35
+ : await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, {
36
+ appId: projectId,
37
+ environment,
38
+ includeFileContent,
39
+ });
33
40
  }
34
41
  class EnvironmentValueList extends EasCommand_1.default {
35
42
  async runAsync() {
36
- let { flags: { environment: environments, format, scope, 'include-sensitive': includeSensitive, 'non-interactive': nonInteractive, }, } = await this.parse(_a);
43
+ let { flags: { environment: environments, format, scope, 'include-sensitive': includeSensitive, 'include-file-content': includeFileContent, 'non-interactive': nonInteractive, }, } = await this.parse(_a);
37
44
  const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
38
45
  nonInteractive: true,
39
46
  });
@@ -44,18 +51,21 @@ class EnvironmentValueList extends EasCommand_1.default {
44
51
  const variables = await getVariablesForScopeAsync(graphqlClient, {
45
52
  scope,
46
53
  includingSensitive: includeSensitive,
54
+ includeFileContent,
47
55
  environment,
48
56
  projectId,
49
57
  });
50
58
  log_1.default.addNewLineIfNone();
51
59
  if (environment) {
52
- log_1.default.log(chalk_1.default.bold(`Environment: ${environment}`));
60
+ log_1.default.log(chalk_1.default.bold(`Environment: ${environment.toLocaleLowerCase()}`));
61
+ }
62
+ if (variables.length === 0) {
63
+ log_1.default.log('No variables found for this environment.');
64
+ return;
53
65
  }
54
66
  if (format === 'short') {
55
67
  for (const variable of variables) {
56
- // TODO: Add Learn more link
57
- log_1.default.log(`${chalk_1.default.bold(variable.name)}=${variable.value ??
58
- "***** (This is a secret env variable that can only be accessed on EAS builder and can't be read in any UI. Learn more.)"}`);
68
+ log_1.default.log(`${chalk_1.default.bold(variable.name)}=${(0, variableUtils_1.formatVariableValue)(variable)}`);
59
69
  }
60
70
  }
61
71
  else {
@@ -82,6 +92,10 @@ EnvironmentValueList.flags = {
82
92
  description: 'Display sensitive values in the output',
83
93
  default: false,
84
94
  }),
95
+ 'include-file-content': core_1.Flags.boolean({
96
+ description: 'Display files content in the output',
97
+ default: false,
98
+ }),
85
99
  ...flags_1.EASVariableFormatFlag,
86
100
  ...flags_1.EASVariableScopeFlag,
87
101
  ...flags_1.EASMultiEnvironmentFlag,
@@ -33,7 +33,7 @@ class EnvironmentVariablePull extends EasCommand_1.default {
33
33
  throw new Error(`File ${targetPath} already exists.`);
34
34
  }
35
35
  }
36
- const filePrefix = `# Environment: ${environment}\n\n`;
36
+ const filePrefix = `# Environment: ${environment.toLocaleLowerCase()}\n\n`;
37
37
  const envFileContent = environmentVariables
38
38
  .map((variable) => {
39
39
  if (variable.value === null) {
@@ -9,7 +9,7 @@ export default class EnvironmentVariablePush extends EasCommand {
9
9
  };
10
10
  static flags: {
11
11
  path: import("@oclif/core/lib/interfaces").OptionFlag<string>;
12
- environment: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment | undefined>;
12
+ environment: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment[] | undefined>;
13
13
  };
14
14
  runAsync(): Promise<void>;
15
15
  private parseEnvFileAsync;
@@ -15,87 +15,93 @@ const prompts_1 = require("../../prompts");
15
15
  class EnvironmentVariablePush extends EasCommand_1.default {
16
16
  async runAsync() {
17
17
  const { flags } = await this.parse(_a);
18
- const { environment, path: envPath } = this.validateFlags(flags);
18
+ const { environment: environments, path: envPath } = this.validateFlags(flags);
19
19
  const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
20
20
  nonInteractive: false,
21
21
  });
22
- const updateVariables = await this.parseEnvFileAsync(envPath, environment);
22
+ const updateVariables = await this.parseEnvFileAsync(envPath, environments);
23
23
  const variableNames = Object.keys(updateVariables);
24
- const existingVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
25
- appId: projectId,
26
- environment,
27
- filterNames: variableNames,
28
- });
29
- const existingDifferentVariables = [];
30
- // Remove variables that are the same as the ones in the environment
31
- existingVariables.forEach(variable => {
32
- const existingVariableUpdate = updateVariables[variable.name];
33
- if (existingVariableUpdate && existingVariableUpdate.value !== variable.value) {
34
- existingDifferentVariables.push(variable);
35
- }
36
- else {
37
- delete updateVariables[variable.name];
38
- }
39
- });
40
- const existingDifferentSharedVariables = existingDifferentVariables.filter(variable => variable.scope === generated_1.EnvironmentVariableScope.Shared);
41
- if (existingDifferentSharedVariables.length > 0) {
42
- const existingDifferentSharedVariablesNames = existingDifferentSharedVariables.map(variable => variable.name);
43
- log_1.default.error('Shared variables cannot be overwritten by eas env:push command.');
44
- log_1.default.error('Remove them from the env file or unlink them from the project to continue:');
45
- existingDifferentSharedVariablesNames.forEach(name => {
46
- log_1.default.error(`- ${name}`);
24
+ for (const environment of environments) {
25
+ const displayedEnvironment = environment.toLocaleLowerCase();
26
+ const existingVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
27
+ appId: projectId,
28
+ environment,
29
+ filterNames: variableNames,
47
30
  });
48
- throw new Error('Shared variables cannot be overwritten by eas env:push command');
49
- }
50
- if (existingDifferentVariables.length > 0) {
51
- log_1.default.warn('Some variables already exist in the environment.');
52
- const variableNames = existingDifferentVariables.map(variable => variable.name);
53
- const confirmationMessage = variableNames.length > 1
54
- ? `The ${variableNames.join(', ')} environment variables already exist in ${environment} environment. Do you want to override them all?`
55
- : `The ${variableNames[0]} environment variable already exists in ${environment} environment. Do you want to override it?`;
56
- const confirm = await (0, prompts_1.confirmAsync)({
57
- message: confirmationMessage,
31
+ const existingDifferentVariables = [];
32
+ // Remove variables that are the same as the ones in the environment
33
+ existingVariables.forEach(existingVariable => {
34
+ const existingVariableUpdate = updateVariables[existingVariable.name];
35
+ if (existingVariableUpdate) {
36
+ const hasMoreEnvironments = existingVariableUpdate.environments.some(newEnv => !existingVariable.environments?.includes(newEnv));
37
+ if (existingVariableUpdate.value !== existingVariable.value || hasMoreEnvironments) {
38
+ existingDifferentVariables.push(existingVariable);
39
+ }
40
+ else {
41
+ delete updateVariables[existingVariable.name];
42
+ }
43
+ }
58
44
  });
59
- let variablesToOverwrite = [];
60
- if (!confirm && existingDifferentVariables.length === 1) {
61
- throw new Error('No new variables to push.');
62
- }
63
- if (confirm) {
64
- variablesToOverwrite = existingDifferentVariables.map(variable => variable.name);
65
- }
66
- else {
67
- const promptResult = await (0, prompts_1.promptAsync)({
68
- type: 'multiselect',
69
- name: 'variablesToOverwrite',
70
- message: 'Select variables to overwrite:',
71
- // @ts-expect-error property missing from `@types/prompts`
72
- optionsPerPage: 20,
73
- choices: existingDifferentVariables.map(variable => ({
74
- title: `${variable.name}: ${updateVariables[variable.name].value} (was ${variable.value ?? '(secret)'})`,
75
- value: variable.name,
76
- })),
45
+ const existingDifferentSharedVariables = existingDifferentVariables.filter(variable => variable.scope === generated_1.EnvironmentVariableScope.Shared);
46
+ if (existingDifferentSharedVariables.length > 0) {
47
+ const existingDifferentSharedVariablesNames = existingDifferentSharedVariables.map(variable => variable.name);
48
+ log_1.default.error('Shared variables cannot be overwritten by eas env:push command.');
49
+ log_1.default.error('Remove them from the env file or unlink them from the project to continue:');
50
+ existingDifferentSharedVariablesNames.forEach(name => {
51
+ log_1.default.error(`- ${name}`);
77
52
  });
78
- variablesToOverwrite = promptResult.variablesToOverwrite;
53
+ throw new Error('Shared variables cannot be overwritten by eas env:push command');
79
54
  }
80
- for (const existingVariable of existingVariables) {
81
- const name = existingVariable.name;
82
- if (variablesToOverwrite.includes(name)) {
83
- updateVariables[name]['overwrite'] = true;
55
+ if (existingDifferentVariables.length > 0) {
56
+ log_1.default.warn(`Some variables already exist in the ${displayedEnvironment} environment.`);
57
+ const variableNames = existingDifferentVariables.map(variable => variable.name);
58
+ const confirmationMessage = variableNames.length > 1
59
+ ? `The ${variableNames.join(', ')} environment variables already exist in ${displayedEnvironment} environment. Do you want to override them all?`
60
+ : `The ${variableNames[0]} environment variable already exists in ${displayedEnvironment} environment. Do you want to override it?`;
61
+ const confirm = await (0, prompts_1.confirmAsync)({
62
+ message: confirmationMessage,
63
+ });
64
+ let variablesToOverwrite = [];
65
+ if (!confirm && existingDifferentVariables.length === 0) {
66
+ throw new Error('No new variables to push.');
67
+ }
68
+ if (confirm) {
69
+ variablesToOverwrite = existingDifferentVariables.map(variable => variable.name);
84
70
  }
85
71
  else {
86
- delete updateVariables[name];
72
+ const promptResult = await (0, prompts_1.promptAsync)({
73
+ type: 'multiselect',
74
+ name: 'variablesToOverwrite',
75
+ message: 'Select variables to overwrite:',
76
+ // @ts-expect-error property missing from `@types/prompts`
77
+ optionsPerPage: 20,
78
+ choices: existingDifferentVariables.map(variable => ({
79
+ title: `${variable.name}: ${updateVariables[variable.name].value} (was ${variable.value ?? '(secret)'})`,
80
+ value: variable.name,
81
+ })),
82
+ });
83
+ variablesToOverwrite = promptResult.variablesToOverwrite;
84
+ }
85
+ for (const existingVariable of existingVariables) {
86
+ const name = existingVariable.name;
87
+ if (variablesToOverwrite.includes(name)) {
88
+ updateVariables[name]['overwrite'] = true;
89
+ }
90
+ else {
91
+ delete updateVariables[name];
92
+ }
87
93
  }
88
94
  }
89
- }
90
- // Check if any of the sensitive variables already exist in the environment. Prompt the user to overwrite them.
91
- const existingSensitiveVariables = existingVariables.filter(variable => variable.value === null);
92
- if (existingSensitiveVariables.length > 0) {
93
- const existingSensitiveVariablesNames = existingSensitiveVariables.map(variable => `- ${variable.name}`);
94
- const confirm = await (0, prompts_1.confirmAsync)({
95
- message: `You are about to overwrite sensitive variables.\n${existingSensitiveVariablesNames.join('\n')}\n Do you want to continue?`,
96
- });
97
- if (!confirm) {
98
- throw new Error('Aborting...');
95
+ // Check if any of the sensitive variables already exist in the environment. Prompt the user to overwrite them.
96
+ const existingSensitiveVariables = existingVariables.filter(variable => variable.visibility !== generated_1.EnvironmentVariableVisibility.Public);
97
+ if (existingSensitiveVariables.length > 0) {
98
+ const existingSensitiveVariablesNames = existingSensitiveVariables.map(variable => `- ${variable.name}`);
99
+ const confirm = await (0, prompts_1.confirmAsync)({
100
+ message: `You are about to overwrite sensitive variables.\n${existingSensitiveVariablesNames.join('\n')}\n Do you want to continue?`,
101
+ });
102
+ if (!confirm) {
103
+ throw new Error('Aborting...');
104
+ }
99
105
  }
100
106
  }
101
107
  const variablesToPush = Object.values(updateVariables);
@@ -104,9 +110,9 @@ class EnvironmentVariablePush extends EasCommand_1.default {
104
110
  return;
105
111
  }
106
112
  await EnvironmentVariableMutation_1.EnvironmentVariableMutation.createBulkEnvironmentVariablesForAppAsync(graphqlClient, variablesToPush, projectId);
107
- log_1.default.log(`Uploaded env file to ${environment} environment.`);
113
+ log_1.default.log(`Uploaded env file to ${environments.join(', ').toLocaleLowerCase()}.`);
108
114
  }
109
- async parseEnvFileAsync(envPath, environment) {
115
+ async parseEnvFileAsync(envPath, environments) {
110
116
  if (!(await fs_extra_1.default.exists(envPath))) {
111
117
  throw new Error(`File ${envPath} does not exist.`);
112
118
  }
@@ -116,7 +122,7 @@ class EnvironmentVariablePush extends EasCommand_1.default {
116
122
  pushInput[name] = {
117
123
  name,
118
124
  value,
119
- environment,
125
+ environments,
120
126
  visibility: name.startsWith('EXPO_SENSITIVE')
121
127
  ? generated_1.EnvironmentVariableVisibility.Sensitive
122
128
  : generated_1.EnvironmentVariableVisibility.Public,
@@ -125,7 +131,7 @@ class EnvironmentVariablePush extends EasCommand_1.default {
125
131
  return pushInput;
126
132
  }
127
133
  validateFlags(flags) {
128
- if (!flags.environment) {
134
+ if (!flags.environment || flags.environment.length === 0) {
129
135
  throw new Error('Please provide an environment to push the env file to.');
130
136
  }
131
137
  return { ...flags, environment: flags.environment };
@@ -139,7 +145,7 @@ EnvironmentVariablePush.contextDefinition = {
139
145
  ..._a.ContextOptions.LoggedIn,
140
146
  };
141
147
  EnvironmentVariablePush.flags = {
142
- ...flags_1.EASEnvironmentFlag,
148
+ ...flags_1.EASMultiEnvironmentFlag,
143
149
  path: core_1.Flags.string({
144
150
  description: 'Path to the input `.env` file',
145
151
  default: '.env.local',
@@ -1,5 +1,5 @@
1
1
  import EasCommand from '../../commandUtils/EasCommand';
2
- import { EnvironmentVariableEnvironment, EnvironmentVariableScope, EnvironmentVariableVisibility } from '../../graphql/generated';
2
+ import { EnvironmentVariableEnvironment, EnvironmentVariableScope } from '../../graphql/generated';
3
3
  export default class EnvironmentVariableUpdate extends EasCommand {
4
4
  static description: string;
5
5
  static hidden: boolean;
@@ -7,11 +7,12 @@ export default class EnvironmentVariableUpdate extends EasCommand {
7
7
  'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
8
  environment: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment[] | undefined>;
9
9
  scope: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableScope>;
10
- visibility: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableVisibility | undefined>;
10
+ visibility: import("@oclif/core/lib/interfaces").OptionFlag<"plaintext" | "encrypted" | "sensitive" | undefined>;
11
11
  'variable-name': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
12
12
  'variable-environment': import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment | undefined>;
13
13
  name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
14
14
  value: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
15
+ type: import("@oclif/core/lib/interfaces").OptionFlag<"string" | "file" | undefined>;
15
16
  };
16
17
  static contextDefinition: {
17
18
  loggedIn: import("../../commandUtils/context/LoggedInContextField").default;
@@ -20,4 +21,5 @@ export default class EnvironmentVariableUpdate extends EasCommand {
20
21
  };
21
22
  runAsync(): Promise<void>;
22
23
  private validateFlags;
24
+ private promptForMissingFlagsAsync;
23
25
  }