eas-cli 12.5.1 → 12.5.2

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 (41) hide show
  1. package/README.md +66 -62
  2. package/build/build/build.js +4 -4
  3. package/build/commandUtils/flags.d.ts +10 -0
  4. package/build/commandUtils/flags.js +15 -8
  5. package/build/commands/env/create.d.ts +3 -1
  6. package/build/commands/env/create.js +106 -74
  7. package/build/commands/env/delete.d.ts +2 -2
  8. package/build/commands/env/delete.js +37 -26
  9. package/build/commands/env/exec.js +2 -1
  10. package/build/commands/env/get.d.ts +2 -2
  11. package/build/commands/env/get.js +40 -26
  12. package/build/commands/env/link.d.ts +4 -2
  13. package/build/commands/env/link.js +53 -14
  14. package/build/commands/env/list.d.ts +1 -2
  15. package/build/commands/env/list.js +49 -42
  16. package/build/commands/env/pull.js +1 -1
  17. package/build/commands/env/unlink.d.ts +3 -2
  18. package/build/commands/env/unlink.js +48 -21
  19. package/build/commands/env/update.d.ts +4 -2
  20. package/build/commands/env/update.js +68 -66
  21. package/build/commands/update/index.js +0 -1
  22. package/build/commands/worker/deploy.js +31 -11
  23. package/build/graphql/generated.d.ts +87 -15
  24. package/build/graphql/mutations/EnvironmentVariableMutation.d.ts +13 -22
  25. package/build/graphql/mutations/EnvironmentVariableMutation.js +18 -2
  26. package/build/graphql/queries/EnvironmentVariablesQuery.d.ts +13 -7
  27. package/build/graphql/queries/EnvironmentVariablesQuery.js +21 -9
  28. package/build/graphql/types/EnvironmentVariable.js +2 -1
  29. package/build/update/republish.js +1 -0
  30. package/build/utils/prompts.d.ts +15 -3
  31. package/build/utils/prompts.js +33 -8
  32. package/build/utils/variableUtils.d.ts +4 -0
  33. package/build/utils/variableUtils.js +31 -0
  34. package/build/worker/assets.d.ts +6 -1
  35. package/build/worker/assets.js +1 -2
  36. package/build/worker/upload.d.ts +1 -0
  37. package/build/worker/upload.js +25 -1
  38. package/oclif.manifest.json +70 -41
  39. package/package.json +3 -3
  40. package/build/utils/formatVariable.d.ts +0 -2
  41. package/build/utils/formatVariable.js +0 -16
@@ -6,50 +6,89 @@ const core_1 = require("@oclif/core");
6
6
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
7
  const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand"));
8
8
  const flags_1 = require("../../commandUtils/flags");
9
+ const generated_1 = require("../../graphql/generated");
9
10
  const EnvironmentVariableMutation_1 = require("../../graphql/mutations/EnvironmentVariableMutation");
10
11
  const EnvironmentVariablesQuery_1 = require("../../graphql/queries/EnvironmentVariablesQuery");
11
12
  const log_1 = tslib_1.__importDefault(require("../../log"));
12
13
  const projectUtils_1 = require("../../project/projectUtils");
13
14
  const prompts_1 = require("../../prompts");
14
15
  const prompts_2 = require("../../utils/prompts");
16
+ const variableUtils_1 = require("../../utils/variableUtils");
15
17
  class EnvironmentVariableLink extends EasCommand_1.default {
16
18
  async runAsync() {
17
- let { flags: { name, 'non-interactive': nonInteractive, environment }, } = await this.parse(_a);
19
+ let { flags: { 'variable-name': name, 'variable-environment': currentEnvironment, 'non-interactive': nonInteractive, environment: environments, }, } = await this.parse(_a);
18
20
  const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
19
21
  nonInteractive,
20
22
  });
21
23
  const projectDisplayName = await (0, projectUtils_1.getDisplayNameForProjectIdAsync)(graphqlClient, projectId);
22
24
  const variables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, {
23
25
  appId: projectId,
26
+ environment: currentEnvironment,
27
+ filterNames: name ? [name] : undefined,
24
28
  });
25
- if (!name) {
26
- name = await (0, prompts_1.selectAsync)('Select shared variable', variables.map(variable => ({
27
- title: variable.name,
28
- value: variable.name,
29
+ let selectedVariable = variables[0];
30
+ if (variables.length > 1) {
31
+ selectedVariable = await (0, prompts_1.selectAsync)('Select shared variable', variables.map(variable => ({
32
+ title: (0, variableUtils_1.formatVariableName)(variable),
33
+ value: variable,
29
34
  })));
30
35
  }
31
- const selectedVariable = variables.find(variable => variable.name === name);
32
36
  if (!selectedVariable) {
33
37
  throw new Error(`Shared variable ${name} doesn't exist`);
34
38
  }
35
- if (!environment) {
36
- environment = await (0, prompts_2.promptVariableEnvironmentAsync)(nonInteractive);
39
+ let explicitSelect = false;
40
+ if (!nonInteractive && !environments) {
41
+ const selectedEnvironments = (selectedVariable.linkedEnvironments ?? []).length > 0
42
+ ? selectedVariable.linkedEnvironments
43
+ : selectedVariable.environments;
44
+ environments = await (0, prompts_2.promptVariableEnvironmentAsync)({
45
+ nonInteractive,
46
+ multiple: true,
47
+ selectedEnvironments: selectedEnvironments ?? [],
48
+ });
49
+ explicitSelect = true;
37
50
  }
38
- const linkedVariable = await EnvironmentVariableMutation_1.EnvironmentVariableMutation.linkSharedEnvironmentVariableAsync(graphqlClient, selectedVariable.id, projectId, environment);
39
- if (!linkedVariable) {
40
- throw new Error(`Could not link variable with name ${selectedVariable.name} to project with id ${projectId}`);
51
+ if (!environments) {
52
+ await EnvironmentVariableMutation_1.EnvironmentVariableMutation.linkSharedEnvironmentVariableAsync(graphqlClient, selectedVariable.id, projectId);
53
+ log_1.default.withTick(`Linked variable ${chalk_1.default.bold(selectedVariable.name)} to project ${chalk_1.default.bold(projectDisplayName)} in ${selectedVariable.environments?.join(', ').toLocaleLowerCase()}.`);
54
+ return;
55
+ }
56
+ for (const environment of Object.values(generated_1.EnvironmentVariableEnvironment)) {
57
+ try {
58
+ if (selectedVariable.linkedEnvironments?.includes(environment) ===
59
+ environments.includes(environment)) {
60
+ if (!explicitSelect && environments.includes(environment)) {
61
+ log_1.default.withTick(`Variable ${chalk_1.default.bold(selectedVariable.name)} is already linked to ${environment.toLocaleLowerCase()}.`);
62
+ }
63
+ continue;
64
+ }
65
+ if (environments.includes(environment)) {
66
+ await EnvironmentVariableMutation_1.EnvironmentVariableMutation.linkSharedEnvironmentVariableAsync(graphqlClient, selectedVariable.id, projectId, environment);
67
+ log_1.default.withTick(`Linked variable ${chalk_1.default.bold(selectedVariable.name)} to project ${chalk_1.default.bold(projectDisplayName)} in ${environment.toLocaleLowerCase()}.`);
68
+ }
69
+ else if (explicitSelect) {
70
+ await EnvironmentVariableMutation_1.EnvironmentVariableMutation.unlinkSharedEnvironmentVariableAsync(graphqlClient, selectedVariable.id, projectId, environment);
71
+ log_1.default.withTick(`Unlinked variable ${chalk_1.default.bold(selectedVariable.name)} from project ${chalk_1.default.bold(projectDisplayName)} in ${environment.toLocaleLowerCase()}.`);
72
+ }
73
+ }
74
+ catch (err) {
75
+ log_1.default.warn(err.message);
76
+ }
41
77
  }
42
- log_1.default.withTick(`Linked variable ${chalk_1.default.bold(linkedVariable.name)} to project ${chalk_1.default.bold(projectDisplayName)}.`);
43
78
  }
44
79
  }
45
80
  _a = EnvironmentVariableLink;
46
81
  EnvironmentVariableLink.description = 'link a shared environment variable to the current project';
47
82
  EnvironmentVariableLink.hidden = true;
48
83
  EnvironmentVariableLink.flags = {
49
- name: core_1.Flags.string({
84
+ 'variable-name': core_1.Flags.string({
50
85
  description: 'Name of the variable',
51
86
  }),
52
- ...flags_1.EASEnvironmentFlag,
87
+ 'variable-environment': core_1.Flags.enum({
88
+ ...flags_1.EasEnvironmentFlagParameters,
89
+ description: 'Current environment of the variable to link',
90
+ }),
91
+ ...flags_1.EASMultiEnvironmentFlag,
53
92
  ...flags_1.EASNonInteractiveFlag,
54
93
  };
55
94
  EnvironmentVariableLink.contextDefinition = {
@@ -8,11 +8,10 @@ export default class EnvironmentValueList extends EasCommand {
8
8
  privateProjectConfig: import("../../commandUtils/context/PrivateProjectConfigContextField").PrivateProjectConfigContextField;
9
9
  };
10
10
  static flags: {
11
- environment: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment | undefined>;
11
+ environment: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment[] | undefined>;
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
15
  };
16
16
  runAsync(): Promise<void>;
17
- private getVariablesForScopeAsync;
18
17
  }
@@ -9,58 +9,65 @@ const flags_1 = require("../../commandUtils/flags");
9
9
  const generated_1 = require("../../graphql/generated");
10
10
  const EnvironmentVariablesQuery_1 = require("../../graphql/queries/EnvironmentVariablesQuery");
11
11
  const log_1 = tslib_1.__importDefault(require("../../log"));
12
- const formatVariable_1 = require("../../utils/formatVariable");
13
12
  const prompts_1 = require("../../utils/prompts");
13
+ const variableUtils_1 = require("../../utils/variableUtils");
14
+ async function getVariablesForScopeAsync(graphqlClient, { scope, includingSensitive, environment, projectId, }) {
15
+ if (scope === generated_1.EnvironmentVariableScope.Project) {
16
+ if (includingSensitive) {
17
+ return await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, {
18
+ appId: projectId,
19
+ environment,
20
+ });
21
+ }
22
+ return await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
23
+ appId: projectId,
24
+ environment,
25
+ });
26
+ }
27
+ return includingSensitive
28
+ ? await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedWithSensitiveAsync(graphqlClient, {
29
+ appId: projectId,
30
+ environment,
31
+ })
32
+ : await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, { appId: projectId, environment });
33
+ }
14
34
  class EnvironmentValueList extends EasCommand_1.default {
15
35
  async runAsync() {
16
- let { flags: { environment, format, scope, 'include-sensitive': includeSensitive }, } = await this.parse(_a);
36
+ let { flags: { environment: environments, format, scope, 'include-sensitive': includeSensitive, 'non-interactive': nonInteractive, }, } = await this.parse(_a);
17
37
  const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
18
38
  nonInteractive: true,
19
39
  });
20
- if (scope === generated_1.EnvironmentVariableScope.Project && !environment) {
21
- environment = await (0, prompts_1.promptVariableEnvironmentAsync)(false);
40
+ if (!environments) {
41
+ environments = await (0, prompts_1.promptVariableEnvironmentAsync)({ nonInteractive, multiple: true });
22
42
  }
23
- const variables = await this.getVariablesForScopeAsync(graphqlClient, {
24
- scope,
25
- includingSensitive: includeSensitive,
26
- environment,
27
- projectId,
28
- });
29
- if (format === 'short') {
30
- for (const variable of variables) {
31
- // TODO: Add Learn more link
32
- log_1.default.log(`${chalk_1.default.bold(variable.name)}=${variable.value ??
33
- "***** (This is a secret env variable that can only be accessed on EAS builder and can't be read in any UI. Learn more.)"}`);
43
+ await (0, variableUtils_1.performForEnvironmentsAsync)(environments, async (environment) => {
44
+ const variables = await getVariablesForScopeAsync(graphqlClient, {
45
+ scope,
46
+ includingSensitive: includeSensitive,
47
+ environment,
48
+ projectId,
49
+ });
50
+ log_1.default.addNewLineIfNone();
51
+ if (environment) {
52
+ log_1.default.log(chalk_1.default.bold(`Environment: ${environment}`));
34
53
  }
35
- }
36
- else {
37
- if (scope === generated_1.EnvironmentVariableScope.Shared) {
38
- log_1.default.log(chalk_1.default.bold('Shared variables for this account:'));
54
+ if (format === 'short') {
55
+ 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.)"}`);
59
+ }
39
60
  }
40
61
  else {
41
- log_1.default.log(chalk_1.default.bold(`Variables for this project for environment ${environment}:`));
42
- }
43
- log_1.default.log(variables.map(variable => (0, formatVariable_1.formatVariable)(variable)).join(`\n\n${chalk_1.default.dim('———')}\n\n`));
44
- }
45
- }
46
- async getVariablesForScopeAsync(graphqlClient, { scope, includingSensitive, environment, projectId, }) {
47
- if (scope === generated_1.EnvironmentVariableScope.Project && environment) {
48
- if (includingSensitive) {
49
- return await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, {
50
- appId: projectId,
51
- environment,
52
- });
62
+ if (scope === generated_1.EnvironmentVariableScope.Shared) {
63
+ log_1.default.log(chalk_1.default.bold('Shared variables for this account:'));
64
+ }
65
+ else {
66
+ log_1.default.log(chalk_1.default.bold(`Variables for this project:`));
67
+ }
68
+ log_1.default.log(variables.map(variable => (0, variableUtils_1.formatVariable)(variable)).join(`\n\n${chalk_1.default.dim('———')}\n\n`));
53
69
  }
54
- return await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
55
- appId: projectId,
56
- environment,
57
- });
58
- }
59
- return includingSensitive
60
- ? await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedWithSensitiveAsync(graphqlClient, {
61
- appId: projectId,
62
- })
63
- : await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, { appId: projectId });
70
+ });
64
71
  }
65
72
  }
66
73
  _a = EnvironmentValueList;
@@ -77,6 +84,6 @@ EnvironmentValueList.flags = {
77
84
  }),
78
85
  ...flags_1.EASVariableFormatFlag,
79
86
  ...flags_1.EASVariableScopeFlag,
80
- ...flags_1.EASEnvironmentFlag,
87
+ ...flags_1.EASMultiEnvironmentFlag,
81
88
  };
82
89
  exports.default = EnvironmentValueList;
@@ -14,7 +14,7 @@ class EnvironmentVariablePull extends EasCommand_1.default {
14
14
  async runAsync() {
15
15
  let { flags: { environment, path: targetPath, 'non-interactive': nonInteractive }, } = await this.parse(_a);
16
16
  if (!environment) {
17
- environment = await (0, prompts_2.promptVariableEnvironmentAsync)(nonInteractive);
17
+ environment = await (0, prompts_2.promptVariableEnvironmentAsync)({ nonInteractive });
18
18
  }
19
19
  const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
20
20
  nonInteractive,
@@ -1,11 +1,12 @@
1
1
  import EasCommand from '../../commandUtils/EasCommand';
2
+ import { EnvironmentVariableEnvironment } from '../../graphql/generated';
2
3
  export default class EnvironmentVariableUnlink extends EasCommand {
3
4
  static description: string;
4
5
  static hidden: boolean;
5
6
  static flags: {
6
7
  'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
7
- environment: import("@oclif/core/lib/interfaces").OptionFlag<import("../../graphql/generated").EnvironmentVariableEnvironment | undefined>;
8
- name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
8
+ environment: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment[] | undefined>;
9
+ 'variable-name': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
9
10
  };
10
11
  static contextDefinition: {
11
12
  loggedIn: import("../../commandUtils/context/LoggedInContextField").default;
@@ -13,49 +13,76 @@ const log_1 = tslib_1.__importDefault(require("../../log"));
13
13
  const projectUtils_1 = require("../../project/projectUtils");
14
14
  const prompts_1 = require("../../prompts");
15
15
  const prompts_2 = require("../../utils/prompts");
16
+ const variableUtils_1 = require("../../utils/variableUtils");
16
17
  class EnvironmentVariableUnlink extends EasCommand_1.default {
17
18
  async runAsync() {
18
- let { flags: { name, 'non-interactive': nonInteractive, environment }, } = await this.parse(_a);
19
+ let { flags: { 'variable-name': name, 'non-interactive': nonInteractive, environment: unlinkEnvironments, }, } = await this.parse(_a);
19
20
  const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
20
21
  nonInteractive,
21
22
  });
22
- if (!environment) {
23
- environment = await (0, prompts_2.promptVariableEnvironmentAsync)(nonInteractive);
24
- }
25
23
  const projectDisplayName = await (0, projectUtils_1.getDisplayNameForProjectIdAsync)(graphqlClient, projectId);
26
- const appVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
24
+ const variables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, {
27
25
  appId: projectId,
28
- environment,
26
+ filterNames: name ? [name] : undefined,
29
27
  });
30
- const linkedVariables = appVariables.filter(({ scope }) => scope === generated_1.EnvironmentVariableScope.Shared);
31
- if (linkedVariables.length === 0) {
32
- throw new Error(`There are no linked shared env variables for project ${projectDisplayName}`);
33
- }
34
- if (!name) {
35
- name = await (0, prompts_1.selectAsync)('Select shared variable to unlink', linkedVariables.map(variable => ({
36
- title: variable.name,
37
- value: variable.name,
28
+ let selectedVariable = variables[0];
29
+ if (variables.length > 1) {
30
+ if (nonInteractive) {
31
+ throw new Error("Multiple variables found, please select one using '--variable-name'");
32
+ }
33
+ selectedVariable = await (0, prompts_1.selectAsync)('Select shared variable', variables.map(variable => ({
34
+ title: (0, variableUtils_1.formatVariableName)(variable),
35
+ value: variable,
38
36
  })));
39
37
  }
40
- const selectedVariable = linkedVariables.find(variable => variable.name === name);
41
38
  if (!selectedVariable) {
42
39
  throw new Error(`Shared variable ${name} doesn't exist`);
43
40
  }
44
- const unlinkedVariable = await EnvironmentVariableMutation_1.EnvironmentVariableMutation.unlinkSharedEnvironmentVariableAsync(graphqlClient, selectedVariable.id, projectId, environment);
45
- if (!unlinkedVariable) {
46
- throw new Error(`Could not unlink variable with name ${selectedVariable.name} from project ${projectDisplayName}`);
41
+ let explicitSelect = false;
42
+ if (!nonInteractive && !unlinkEnvironments) {
43
+ const selectedEnvironments = (selectedVariable.linkedEnvironments ?? []).length > 0
44
+ ? selectedVariable.linkedEnvironments
45
+ : selectedVariable.environments;
46
+ const environments = await (0, prompts_2.promptVariableEnvironmentAsync)({
47
+ nonInteractive,
48
+ multiple: true,
49
+ selectedEnvironments: selectedEnvironments ?? [],
50
+ });
51
+ explicitSelect = true;
52
+ unlinkEnvironments = Object.values(generated_1.EnvironmentVariableEnvironment).filter(env => !environments.includes(env));
53
+ }
54
+ if (!unlinkEnvironments) {
55
+ await EnvironmentVariableMutation_1.EnvironmentVariableMutation.unlinkSharedEnvironmentVariableAsync(graphqlClient, selectedVariable.id, projectId);
56
+ log_1.default.withTick(`Unlinked variable ${chalk_1.default.bold(selectedVariable.name)} from project ${chalk_1.default.bold(projectDisplayName)} in ${selectedVariable.environments?.join(', ').toLocaleLowerCase()}.`);
57
+ return;
58
+ }
59
+ for (const environment of Object.values(generated_1.EnvironmentVariableEnvironment)) {
60
+ if (selectedVariable.linkedEnvironments?.includes(environment) !==
61
+ unlinkEnvironments.includes(environment)) {
62
+ if (!explicitSelect && unlinkEnvironments.includes(environment)) {
63
+ log_1.default.withTick(`Variable ${chalk_1.default.bold(selectedVariable.name)} is already unlinked from ${environment.toLocaleLowerCase()}.`);
64
+ }
65
+ continue;
66
+ }
67
+ if (unlinkEnvironments.includes(environment)) {
68
+ await EnvironmentVariableMutation_1.EnvironmentVariableMutation.unlinkSharedEnvironmentVariableAsync(graphqlClient, selectedVariable.id, projectId, environment);
69
+ log_1.default.withTick(`Unlinked variable ${chalk_1.default.bold(selectedVariable.name)} from project ${chalk_1.default.bold(projectDisplayName)} in ${environment.toLocaleLowerCase()}.`);
70
+ }
71
+ else if (explicitSelect) {
72
+ await EnvironmentVariableMutation_1.EnvironmentVariableMutation.linkSharedEnvironmentVariableAsync(graphqlClient, selectedVariable.id, projectId, environment);
73
+ log_1.default.withTick(`Linked variable ${chalk_1.default.bold(selectedVariable.name)} to project ${chalk_1.default.bold(projectDisplayName)} in ${environment.toLocaleLowerCase()}.`);
74
+ }
47
75
  }
48
- log_1.default.withTick(`Unlinked variable ${chalk_1.default.bold(unlinkedVariable.name)} from the project ${chalk_1.default.bold(projectDisplayName)}.`);
49
76
  }
50
77
  }
51
78
  _a = EnvironmentVariableUnlink;
52
79
  EnvironmentVariableUnlink.description = 'unlink a shared environment variable to the current project';
53
80
  EnvironmentVariableUnlink.hidden = true;
54
81
  EnvironmentVariableUnlink.flags = {
55
- name: core_1.Flags.string({
82
+ 'variable-name': core_1.Flags.string({
56
83
  description: 'Name of the variable',
57
84
  }),
58
- ...flags_1.EASEnvironmentFlag,
85
+ ...flags_1.EASMultiEnvironmentFlag,
59
86
  ...flags_1.EASNonInteractiveFlag,
60
87
  };
61
88
  EnvironmentVariableUnlink.contextDefinition = {
@@ -1,13 +1,15 @@
1
1
  import EasCommand from '../../commandUtils/EasCommand';
2
- import { EnvironmentVariableScope, EnvironmentVariableVisibility } from '../../graphql/generated';
2
+ import { EnvironmentVariableEnvironment, EnvironmentVariableScope, EnvironmentVariableVisibility } from '../../graphql/generated';
3
3
  export default class EnvironmentVariableUpdate extends EasCommand {
4
4
  static description: string;
5
5
  static hidden: boolean;
6
6
  static flags: {
7
7
  'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
- environment: import("@oclif/core/lib/interfaces").OptionFlag<import("../../graphql/generated").EnvironmentVariableEnvironment | undefined>;
8
+ environment: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment[] | undefined>;
9
9
  scope: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableScope>;
10
10
  visibility: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableVisibility | undefined>;
11
+ 'variable-name': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
12
+ 'variable-environment': import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment | undefined>;
11
13
  name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
12
14
  value: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
13
15
  };
@@ -3,6 +3,7 @@ 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"));
6
7
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
8
  const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand"));
8
9
  const flags_1 = require("../../commandUtils/flags");
@@ -13,10 +14,11 @@ const log_1 = tslib_1.__importDefault(require("../../log"));
13
14
  const projectUtils_1 = require("../../project/projectUtils");
14
15
  const prompts_1 = require("../../prompts");
15
16
  const prompts_2 = require("../../utils/prompts");
17
+ const variableUtils_1 = require("../../utils/variableUtils");
16
18
  class EnvironmentVariableUpdate extends EasCommand_1.default {
17
19
  async runAsync() {
18
20
  const { flags } = await this.parse(_a);
19
- let { name, value, scope, 'non-interactive': nonInteractive, environment, visibility, } = this.validateFlags(flags);
21
+ let { name, value, scope, 'variable-name': currentName, 'variable-environment': currentEnvironment, 'non-interactive': nonInteractive, environment: environments, visibility, } = this.validateFlags(flags);
20
22
  const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
21
23
  nonInteractive,
22
24
  });
@@ -24,89 +26,82 @@ class EnvironmentVariableUpdate extends EasCommand_1.default {
24
26
  (0, projectUtils_1.getDisplayNameForProjectIdAsync)(graphqlClient, projectId),
25
27
  (0, projectUtils_1.getOwnerAccountForProjectIdAsync)(graphqlClient, projectId),
26
28
  ]);
29
+ let selectedVariable;
30
+ let existingVariables = [];
31
+ const suffix = scope === generated_1.EnvironmentVariableScope.Project
32
+ ? `on project ${projectDisplayName}`
33
+ : `on account ${ownerAccount.name}`;
27
34
  if (scope === generated_1.EnvironmentVariableScope.Project) {
28
- if (!environment) {
29
- environment = await (0, prompts_2.promptVariableEnvironmentAsync)(nonInteractive);
30
- }
31
- const existingVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
35
+ existingVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
32
36
  appId: projectId,
33
- environment,
37
+ environment: currentEnvironment,
38
+ filterNames: currentName ? [currentName] : undefined,
34
39
  });
35
- if (!name) {
36
- name = await (0, prompts_1.selectAsync)('Select variable', existingVariables.map(variable => ({
37
- title: variable.name,
38
- value: variable.name,
39
- })));
40
- }
41
- const existingVariable = existingVariables.find(variable => variable.name === name);
42
- if (!existingVariable) {
43
- throw new Error(`Variable with name ${name} does not exist on project ${projectDisplayName}`);
44
- }
45
- if (!value) {
46
- value = await (0, prompts_2.promptVariableValueAsync)({
47
- nonInteractive,
48
- required: false,
49
- initial: existingVariable.value,
50
- });
51
- if (!value || value.length === 0) {
52
- value = '';
53
- }
54
- }
55
- const variable = await EnvironmentVariableMutation_1.EnvironmentVariableMutation.createForAppAsync(graphqlClient, {
56
- name,
57
- value,
58
- environment,
59
- visibility,
60
- overwrite: true,
61
- }, projectId);
62
- if (!variable) {
63
- throw new Error(`Could not update variable with name ${name} on project ${projectDisplayName}`);
64
- }
65
- log_1.default.withTick(`Updated variable ${chalk_1.default.bold(name)} on project ${chalk_1.default.bold(projectDisplayName)}.`);
66
40
  }
67
- else if (scope === generated_1.EnvironmentVariableScope.Shared) {
68
- const sharedVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, {
41
+ if (scope === generated_1.EnvironmentVariableScope.Shared) {
42
+ existingVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, {
69
43
  appId: projectId,
44
+ environment: currentEnvironment,
45
+ filterNames: currentName ? [currentName] : undefined,
70
46
  });
47
+ }
48
+ if (existingVariables.length === 0) {
49
+ throw new Error(`Variable with name ${currentName} ${currentEnvironment ? `in environment ${currentEnvironment}` : ''} does not exist ${suffix}.`);
50
+ }
51
+ else if (existingVariables.length > 1) {
52
+ selectedVariable = await (0, prompts_1.selectAsync)('Select variable', existingVariables.map(variable => ({
53
+ title: (0, variableUtils_1.formatVariableName)(variable),
54
+ value: variable,
55
+ })));
56
+ }
57
+ else {
58
+ selectedVariable = existingVariables[0];
59
+ }
60
+ (0, assert_1.default)(selectedVariable, 'Variable must be selected');
61
+ if (!nonInteractive) {
71
62
  if (!name) {
72
- name = await (0, prompts_1.selectAsync)('Select variable', sharedVariables.map(variable => ({
73
- title: variable.name,
74
- value: variable.name,
75
- })));
76
- }
77
- const existingVariable = sharedVariables.find(variable => variable.name === name);
78
- if (!existingVariable) {
79
- throw new Error("Variable with this name doesn't exist on this account. Use a different name.");
63
+ name = await (0, prompts_2.promptVariableNameAsync)(nonInteractive, selectedVariable.name);
64
+ if (!name || name.length === 0) {
65
+ name = undefined;
66
+ }
80
67
  }
81
68
  if (!value) {
82
69
  value = await (0, prompts_2.promptVariableValueAsync)({
83
70
  nonInteractive,
84
71
  required: false,
85
- initial: existingVariable.value,
72
+ initial: selectedVariable.value,
86
73
  });
87
74
  if (!value || value.length === 0) {
88
- value = '';
75
+ value = undefined;
89
76
  }
90
77
  }
91
- const variable = await EnvironmentVariableMutation_1.EnvironmentVariableMutation.createSharedVariableAsync(graphqlClient, {
92
- name,
93
- value,
94
- visibility,
95
- overwrite: true,
96
- }, ownerAccount.id);
97
- if (!variable) {
98
- throw new Error(`Could not update variable with name ${name} on account ${ownerAccount.name}`);
78
+ if (!environments || environments.length === 0) {
79
+ environments = await (0, prompts_2.promptVariableEnvironmentAsync)({
80
+ nonInteractive,
81
+ multiple: true,
82
+ selectedEnvironments: selectedVariable.environments ?? [],
83
+ });
99
84
  }
100
- log_1.default.withTick(`Updated shared variable ${chalk_1.default.bold(name)} on account ${chalk_1.default.bold(ownerAccount.name)}.`);
85
+ if (!visibility) {
86
+ visibility = await (0, prompts_2.promptVariableVisibilityAsync)(nonInteractive, selectedVariable.visibility);
87
+ }
88
+ }
89
+ const variable = await EnvironmentVariableMutation_1.EnvironmentVariableMutation.updateAsync(graphqlClient, {
90
+ id: selectedVariable.id,
91
+ name,
92
+ value,
93
+ environments,
94
+ visibility,
95
+ });
96
+ if (!variable) {
97
+ throw new Error(`Could not update variable with name ${name} ${suffix}`);
101
98
  }
99
+ log_1.default.withTick(`Updated variable ${chalk_1.default.bold(selectedVariable.name)} ${suffix}.`);
102
100
  }
103
101
  validateFlags(flags) {
104
102
  if (flags['non-interactive']) {
105
- if (!flags.name) {
106
- throw new Error('Variable name is required in non-interactive mode. Run the command with --name flag.');
107
- }
108
- if (flags.scope === generated_1.EnvironmentVariableScope.Project && !flags.environment) {
109
- throw new Error('Environment is required when updating project-wide variable in non-interactive mode. Run the command with --environment flag.');
103
+ if (!flags['variable-name']) {
104
+ throw new Error('Current name is required in non-interactive mode. Run the command with --variable-name flag.');
110
105
  }
111
106
  }
112
107
  return flags;
@@ -116,15 +111,22 @@ _a = EnvironmentVariableUpdate;
116
111
  EnvironmentVariableUpdate.description = 'update an environment variable on the current project or owner account';
117
112
  EnvironmentVariableUpdate.hidden = true;
118
113
  EnvironmentVariableUpdate.flags = {
114
+ 'variable-name': core_1.Flags.string({
115
+ description: 'Current name of the variable',
116
+ }),
117
+ 'variable-environment': core_1.Flags.enum({
118
+ ...flags_1.EasEnvironmentFlagParameters,
119
+ description: 'Current environment of the variable to update',
120
+ }),
119
121
  name: core_1.Flags.string({
120
- description: 'Name of the variable',
122
+ description: 'New name of the variable',
121
123
  }),
122
124
  value: core_1.Flags.string({
123
- description: 'Text value or the variable',
125
+ description: 'New value or the variable',
124
126
  }),
125
127
  ...flags_1.EASVariableVisibilityFlag,
126
128
  ...flags_1.EASVariableScopeFlag,
127
- ...flags_1.EASEnvironmentFlag,
129
+ ...flags_1.EASMultiEnvironmentFlag,
128
130
  ...flags_1.EASNonInteractiveFlag,
129
131
  };
130
132
  EnvironmentVariableUpdate.contextDefinition = {
@@ -426,7 +426,6 @@ UpdatePublish.flags = {
426
426
  'rollout-percentage': core_1.Flags.integer({
427
427
  description: `Percentage of users this update should be immediately available to. Users not in the rollout will be served the previous latest update on the branch, even if that update is itself being rolled out. The specified number must be an integer between 1 and 100. When not specified, this defaults to 100.`,
428
428
  required: false,
429
- hidden: true,
430
429
  min: 0,
431
430
  max: 100,
432
431
  }),