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.
- package/README.md +66 -62
- package/build/build/build.js +4 -4
- package/build/commandUtils/flags.d.ts +10 -0
- package/build/commandUtils/flags.js +15 -8
- package/build/commands/env/create.d.ts +3 -1
- package/build/commands/env/create.js +106 -74
- package/build/commands/env/delete.d.ts +2 -2
- package/build/commands/env/delete.js +37 -26
- package/build/commands/env/exec.js +2 -1
- package/build/commands/env/get.d.ts +2 -2
- package/build/commands/env/get.js +40 -26
- package/build/commands/env/link.d.ts +4 -2
- package/build/commands/env/link.js +53 -14
- package/build/commands/env/list.d.ts +1 -2
- package/build/commands/env/list.js +49 -42
- package/build/commands/env/pull.js +1 -1
- package/build/commands/env/unlink.d.ts +3 -2
- package/build/commands/env/unlink.js +48 -21
- package/build/commands/env/update.d.ts +4 -2
- package/build/commands/env/update.js +68 -66
- package/build/commands/update/index.js +0 -1
- package/build/commands/worker/deploy.js +31 -11
- package/build/graphql/generated.d.ts +87 -15
- package/build/graphql/mutations/EnvironmentVariableMutation.d.ts +13 -22
- package/build/graphql/mutations/EnvironmentVariableMutation.js +18 -2
- package/build/graphql/queries/EnvironmentVariablesQuery.d.ts +13 -7
- package/build/graphql/queries/EnvironmentVariablesQuery.js +21 -9
- package/build/graphql/types/EnvironmentVariable.js +2 -1
- package/build/update/republish.js +1 -0
- package/build/utils/prompts.d.ts +15 -3
- package/build/utils/prompts.js +33 -8
- package/build/utils/variableUtils.d.ts +4 -0
- package/build/utils/variableUtils.js +31 -0
- package/build/worker/assets.d.ts +6 -1
- package/build/worker/assets.js +1 -2
- package/build/worker/upload.d.ts +1 -0
- package/build/worker/upload.js +25 -1
- package/oclif.manifest.json +70 -41
- package/package.json +3 -3
- package/build/utils/formatVariable.d.ts +0 -2
- package/build/utils/formatVariable.js +0 -16
|
@@ -5,7 +5,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
|
|
|
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<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
11
|
name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
@@ -19,5 +19,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
|
|
|
19
19
|
privateProjectConfig: import("../../commandUtils/context/PrivateProjectConfigContextField").PrivateProjectConfigContextField;
|
|
20
20
|
};
|
|
21
21
|
runAsync(): Promise<void>;
|
|
22
|
+
private promptForOverwriteAsync;
|
|
23
|
+
private promptForMissingFlagsAsync;
|
|
22
24
|
private validateFlags;
|
|
23
25
|
}
|
|
@@ -13,10 +13,12 @@ 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 EnvironmentVariableCreate extends EasCommand_1.default {
|
|
17
18
|
async runAsync() {
|
|
18
19
|
const { flags } = await this.parse(_a);
|
|
19
|
-
|
|
20
|
+
const validatedFlags = this.validateFlags(flags);
|
|
21
|
+
const { name, value, scope, 'non-interactive': nonInteractive, environment: environments, visibility, link, force, } = await this.promptForMissingFlagsAsync(validatedFlags);
|
|
20
22
|
const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
|
|
21
23
|
nonInteractive,
|
|
22
24
|
});
|
|
@@ -24,108 +26,138 @@ class EnvironmentVariableCreate extends EasCommand_1.default {
|
|
|
24
26
|
(0, projectUtils_1.getDisplayNameForProjectIdAsync)(graphqlClient, projectId),
|
|
25
27
|
(0, projectUtils_1.getOwnerAccountForProjectIdAsync)(graphqlClient, projectId),
|
|
26
28
|
]);
|
|
27
|
-
if (!name) {
|
|
28
|
-
name = await (0, prompts_2.promptVariableNameAsync)(nonInteractive);
|
|
29
|
-
}
|
|
30
29
|
let overwrite = false;
|
|
31
|
-
visibility = visibility ?? generated_1.EnvironmentVariableVisibility.Public;
|
|
32
|
-
if (!value) {
|
|
33
|
-
value = await (0, prompts_2.promptVariableValueAsync)({
|
|
34
|
-
nonInteractive,
|
|
35
|
-
hidden: visibility !== generated_1.EnvironmentVariableVisibility.Public,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
30
|
if (scope === generated_1.EnvironmentVariableScope.Project) {
|
|
39
|
-
if (!environment) {
|
|
40
|
-
environment = await (0, prompts_2.promptVariableEnvironmentAsync)(nonInteractive);
|
|
41
|
-
}
|
|
42
31
|
const existingVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
|
|
43
32
|
appId: projectId,
|
|
44
|
-
|
|
33
|
+
filterNames: [name],
|
|
45
34
|
});
|
|
46
|
-
const existingVariable = existingVariables.find(variable => variable.
|
|
35
|
+
const existingVariable = existingVariables.find(variable => !environments || variable.environments?.some(env => environments?.includes(env)));
|
|
47
36
|
if (existingVariable) {
|
|
37
|
+
if (existingVariable.scope === generated_1.EnvironmentVariableScope.Project) {
|
|
38
|
+
await this.promptForOverwriteAsync({
|
|
39
|
+
nonInteractive,
|
|
40
|
+
force,
|
|
41
|
+
message: `Variable ${name} already exists on this project.`,
|
|
42
|
+
suggestion: 'Do you want to overwrite it?',
|
|
43
|
+
});
|
|
44
|
+
overwrite = true;
|
|
45
|
+
}
|
|
48
46
|
if (existingVariable.scope === generated_1.EnvironmentVariableScope.Shared) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
throw new Error(`Shared variable ${name} already exists on this project.`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else if (!force) {
|
|
59
|
-
throw new Error(`Shared variable ${name} already exists on this project. Use --force to overwrite it.`);
|
|
60
|
-
}
|
|
61
|
-
await EnvironmentVariableMutation_1.EnvironmentVariableMutation.unlinkSharedEnvironmentVariableAsync(graphqlClient, existingVariable.id, projectId, environment);
|
|
47
|
+
await this.promptForOverwriteAsync({
|
|
48
|
+
nonInteractive,
|
|
49
|
+
force,
|
|
50
|
+
message: `Shared variable with ${name} name already exists on this account.`,
|
|
51
|
+
suggestion: 'Do you want to unlink it first?',
|
|
52
|
+
});
|
|
62
53
|
log_1.default.withTick(`Unlinking shared variable ${chalk_1.default.bold(name)} on project ${chalk_1.default.bold(projectDisplayName)}.`);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const confirmation = await (0, prompts_1.confirmAsync)({
|
|
67
|
-
message: `Variable ${name} already exists on this project. Do you want to overwrite it?`,
|
|
68
|
-
});
|
|
69
|
-
if (!confirmation) {
|
|
70
|
-
log_1.default.log('Aborting');
|
|
71
|
-
throw new Error(`Variable ${name} already exists on this project. Use --force to overwrite it.`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else if (!force) {
|
|
75
|
-
throw new Error(`Variable ${name} already exists on this project. Use --force to overwrite it.`);
|
|
76
|
-
}
|
|
77
|
-
overwrite = true;
|
|
54
|
+
await (0, variableUtils_1.performForEnvironmentsAsync)(environments, async (environment) => {
|
|
55
|
+
await EnvironmentVariableMutation_1.EnvironmentVariableMutation.unlinkSharedEnvironmentVariableAsync(graphqlClient, existingVariable.id, projectId, environment);
|
|
56
|
+
});
|
|
78
57
|
}
|
|
79
58
|
}
|
|
80
|
-
const variable =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
59
|
+
const variable = overwrite && existingVariable
|
|
60
|
+
? await EnvironmentVariableMutation_1.EnvironmentVariableMutation.updateAsync(graphqlClient, {
|
|
61
|
+
id: existingVariable.id,
|
|
62
|
+
name,
|
|
63
|
+
value,
|
|
64
|
+
visibility,
|
|
65
|
+
environments,
|
|
66
|
+
})
|
|
67
|
+
: await EnvironmentVariableMutation_1.EnvironmentVariableMutation.createForAppAsync(graphqlClient, {
|
|
68
|
+
name,
|
|
69
|
+
value,
|
|
70
|
+
environments,
|
|
71
|
+
visibility,
|
|
72
|
+
type: generated_1.EnvironmentSecretType.String,
|
|
73
|
+
}, projectId);
|
|
87
74
|
if (!variable) {
|
|
88
75
|
throw new Error(`Could not create variable with name ${name} on project ${projectDisplayName}`);
|
|
89
76
|
}
|
|
90
77
|
log_1.default.withTick(`Created a new variable ${chalk_1.default.bold(name)} on project ${chalk_1.default.bold(projectDisplayName)}.`);
|
|
91
78
|
}
|
|
92
79
|
else if (scope === generated_1.EnvironmentVariableScope.Shared) {
|
|
93
|
-
const
|
|
80
|
+
const existingVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, {
|
|
94
81
|
appId: projectId,
|
|
82
|
+
filterNames: [name],
|
|
95
83
|
});
|
|
96
|
-
const existingVariable =
|
|
84
|
+
const existingVariable = existingVariables.find(variable => !environments || variable.environments?.some(env => environments?.includes(env)));
|
|
97
85
|
if (existingVariable) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
});
|
|
105
|
-
if (!confirmation) {
|
|
106
|
-
log_1.default.log('Aborting');
|
|
107
|
-
throw new Error('Unexpected argument: --environment can only be used with --link flag.');
|
|
86
|
+
if (force) {
|
|
87
|
+
overwrite = true;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new Error(`Shared variable with ${name} name already exists on this account.\n` +
|
|
91
|
+
`Use a different name or delete the existing variable on website or by using eas env:delete --name ${name} --scope shared command.`);
|
|
108
92
|
}
|
|
109
93
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
94
|
+
const variable = overwrite && existingVariable
|
|
95
|
+
? await EnvironmentVariableMutation_1.EnvironmentVariableMutation.updateAsync(graphqlClient, {
|
|
96
|
+
id: existingVariable.id,
|
|
97
|
+
name,
|
|
98
|
+
value,
|
|
99
|
+
visibility,
|
|
100
|
+
environments,
|
|
101
|
+
})
|
|
102
|
+
: await EnvironmentVariableMutation_1.EnvironmentVariableMutation.createSharedVariableAsync(graphqlClient, {
|
|
103
|
+
name,
|
|
104
|
+
value,
|
|
105
|
+
visibility,
|
|
106
|
+
environments,
|
|
107
|
+
type: generated_1.EnvironmentSecretType.String,
|
|
108
|
+
}, ownerAccount.id);
|
|
118
109
|
if (!variable) {
|
|
119
110
|
throw new Error(`Could not create variable with name ${name} on account ${ownerAccount.name}`);
|
|
120
111
|
}
|
|
121
112
|
log_1.default.withTick(`Created a new variable ${chalk_1.default.bold(name)} on account ${chalk_1.default.bold(ownerAccount.name)}.`);
|
|
122
|
-
if (link
|
|
113
|
+
if (link) {
|
|
123
114
|
log_1.default.withTick(`Linking shared variable ${chalk_1.default.bold(name)} to project ${chalk_1.default.bold(projectDisplayName)}.`);
|
|
124
|
-
await
|
|
115
|
+
await (0, variableUtils_1.performForEnvironmentsAsync)(environments, async (environment) => {
|
|
116
|
+
await EnvironmentVariableMutation_1.EnvironmentVariableMutation.linkSharedEnvironmentVariableAsync(graphqlClient, variable.id, projectId, environment);
|
|
117
|
+
});
|
|
125
118
|
log_1.default.withTick(`Linked shared variable ${chalk_1.default.bold(name)} to project ${chalk_1.default.bold(projectDisplayName)}.`);
|
|
126
119
|
}
|
|
127
120
|
}
|
|
128
121
|
}
|
|
122
|
+
async promptForOverwriteAsync({ nonInteractive, force, message, suggestion, }) {
|
|
123
|
+
if (!nonInteractive) {
|
|
124
|
+
const confirmation = await (0, prompts_1.confirmAsync)({
|
|
125
|
+
message: `${message} ${suggestion}`,
|
|
126
|
+
});
|
|
127
|
+
if (!confirmation) {
|
|
128
|
+
log_1.default.log('Aborting');
|
|
129
|
+
throw new Error(`${message}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (!force) {
|
|
133
|
+
throw new Error(`${message} Use --force to overwrite it.`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async promptForMissingFlagsAsync({ name, value, environment, visibility = generated_1.EnvironmentVariableVisibility.Public, 'non-interactive': nonInteractive, ...rest }) {
|
|
137
|
+
if (!name) {
|
|
138
|
+
name = await (0, prompts_2.promptVariableNameAsync)(nonInteractive);
|
|
139
|
+
}
|
|
140
|
+
if (!value) {
|
|
141
|
+
value = await (0, prompts_2.promptVariableValueAsync)({
|
|
142
|
+
nonInteractive,
|
|
143
|
+
hidden: visibility !== generated_1.EnvironmentVariableVisibility.Public,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (!environment) {
|
|
147
|
+
environment = await (0, prompts_2.promptVariableEnvironmentAsync)({ nonInteractive, multiple: true });
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
name,
|
|
151
|
+
value,
|
|
152
|
+
environment,
|
|
153
|
+
visibility,
|
|
154
|
+
link: rest.link ?? false,
|
|
155
|
+
force: rest.force ?? false,
|
|
156
|
+
scope: rest.scope ?? generated_1.EnvironmentVariableScope.Project,
|
|
157
|
+
'non-interactive': nonInteractive,
|
|
158
|
+
...rest,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
129
161
|
validateFlags(flags) {
|
|
130
162
|
if (flags.scope !== generated_1.EnvironmentVariableScope.Shared && flags.link) {
|
|
131
163
|
throw new Error(`Unexpected argument: --link can only be used when creating shared variables`);
|
|
@@ -158,7 +190,7 @@ EnvironmentVariableCreate.flags = {
|
|
|
158
190
|
}),
|
|
159
191
|
...flags_1.EASVariableVisibilityFlag,
|
|
160
192
|
...flags_1.EASVariableScopeFlag,
|
|
161
|
-
...flags_1.
|
|
193
|
+
...flags_1.EASMultiEnvironmentFlag,
|
|
162
194
|
...flags_1.EASNonInteractiveFlag,
|
|
163
195
|
};
|
|
164
196
|
EnvironmentVariableCreate.contextDefinition = {
|
|
@@ -5,9 +5,9 @@ export default class EnvironmentVariableDelete extends EasCommand {
|
|
|
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<EnvironmentVariableEnvironment | undefined>;
|
|
9
8
|
scope: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableScope>;
|
|
10
|
-
name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
9
|
+
'variable-name': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
10
|
+
'variable-environment': import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment | undefined>;
|
|
11
11
|
};
|
|
12
12
|
static contextDefinition: {
|
|
13
13
|
loggedIn: import("../../commandUtils/context/LoggedInContextField").default;
|
|
@@ -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");
|
|
@@ -11,45 +12,52 @@ const EnvironmentVariableMutation_1 = require("../../graphql/mutations/Environme
|
|
|
11
12
|
const EnvironmentVariablesQuery_1 = require("../../graphql/queries/EnvironmentVariablesQuery");
|
|
12
13
|
const log_1 = tslib_1.__importDefault(require("../../log"));
|
|
13
14
|
const prompts_1 = require("../../prompts");
|
|
14
|
-
const
|
|
15
|
+
const variableUtils_1 = require("../../utils/variableUtils");
|
|
15
16
|
class EnvironmentVariableDelete extends EasCommand_1.default {
|
|
16
17
|
async runAsync() {
|
|
17
18
|
const { flags } = await this.parse(_a);
|
|
18
|
-
|
|
19
|
+
const { 'variable-name': name, 'variable-environment': environment, 'non-interactive': nonInteractive, scope, } = this.validateFlags(flags);
|
|
19
20
|
const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
|
|
20
21
|
nonInteractive,
|
|
21
22
|
});
|
|
22
|
-
|
|
23
|
-
if (!environment) {
|
|
24
|
-
environment = await (0, prompts_2.promptVariableEnvironmentAsync)(nonInteractive);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const variables = scope === generated_1.EnvironmentVariableScope.Project && environment
|
|
23
|
+
const variables = scope === generated_1.EnvironmentVariableScope.Project
|
|
28
24
|
? await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
|
|
29
25
|
appId: projectId,
|
|
30
26
|
environment,
|
|
31
27
|
})
|
|
32
|
-
: await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, {
|
|
28
|
+
: await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, {
|
|
29
|
+
appId: projectId,
|
|
30
|
+
environment,
|
|
31
|
+
});
|
|
32
|
+
let selectedVariable;
|
|
33
33
|
if (!name) {
|
|
34
|
-
({
|
|
34
|
+
({ variable: selectedVariable } = await (0, prompts_1.promptAsync)({
|
|
35
35
|
type: 'select',
|
|
36
|
-
name: '
|
|
36
|
+
name: 'variable',
|
|
37
37
|
message: 'Pick the variable to be deleted:',
|
|
38
38
|
choices: variables
|
|
39
39
|
.filter(({ scope: variableScope }) => scope === variableScope)
|
|
40
|
-
.map(variable =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
.map(variable => {
|
|
41
|
+
return {
|
|
42
|
+
title: (0, variableUtils_1.formatVariableName)(variable),
|
|
43
|
+
value: variable,
|
|
44
|
+
};
|
|
45
|
+
}),
|
|
44
46
|
}));
|
|
45
|
-
if (!name) {
|
|
46
|
-
throw new Error(`Environment variable wasn't selected. Run the command again and select existing variable or run it with ${chalk_1.default.bold('--name VARIABLE_NAME')} flag to fix the issue.`);
|
|
47
|
-
}
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
else {
|
|
49
|
+
const selectedVariables = variables.filter(variable => variable.name === name && (!environment || variable.environments?.includes(environment)));
|
|
50
|
+
if (selectedVariables.length !== 1) {
|
|
51
|
+
if (selectedVariables.length === 0) {
|
|
52
|
+
throw new Error(`Variable "${name}" not found.`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw new Error(`Multiple variables with name "${name}" found. Please select the variable to delete interactively or run command with --variable-environment ENVIRONMENT option.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
selectedVariable = selectedVariables[0];
|
|
52
59
|
}
|
|
60
|
+
(0, assert_1.default)(selectedVariable, `Variable "${name}" not found.`);
|
|
53
61
|
if (!nonInteractive) {
|
|
54
62
|
log_1.default.addNewLineIfNone();
|
|
55
63
|
log_1.default.warn(`You are about to permanently delete variable ${selectedVariable.name}.`);
|
|
@@ -62,7 +70,7 @@ class EnvironmentVariableDelete extends EasCommand_1.default {
|
|
|
62
70
|
});
|
|
63
71
|
if (!confirmed) {
|
|
64
72
|
log_1.default.error(`Canceled deletion of variable ${selectedVariable.name}.`);
|
|
65
|
-
throw new Error(`Variable "${name}" not deleted.`);
|
|
73
|
+
throw new Error(`Variable "${selectedVariable.name}" not deleted.`);
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
await EnvironmentVariableMutation_1.EnvironmentVariableMutation.deleteAsync(graphqlClient, selectedVariable.id);
|
|
@@ -70,8 +78,8 @@ class EnvironmentVariableDelete extends EasCommand_1.default {
|
|
|
70
78
|
}
|
|
71
79
|
validateFlags(flags) {
|
|
72
80
|
if (flags['non-interactive']) {
|
|
73
|
-
if (!flags
|
|
74
|
-
throw new Error(`Environment variable needs 'name' to be specified when running in non-interactive mode. Run the command with ${chalk_1.default.bold('--name VARIABLE_NAME')} flag to fix the issue`);
|
|
81
|
+
if (!flags['variable-name']) {
|
|
82
|
+
throw new Error(`Environment variable needs 'name' to be specified when running in non-interactive mode. Run the command with ${chalk_1.default.bold('--variable-name VARIABLE_NAME')} flag to fix the issue`);
|
|
75
83
|
}
|
|
76
84
|
}
|
|
77
85
|
return flags;
|
|
@@ -81,11 +89,14 @@ _a = EnvironmentVariableDelete;
|
|
|
81
89
|
EnvironmentVariableDelete.description = 'delete an environment variable by name';
|
|
82
90
|
EnvironmentVariableDelete.hidden = true;
|
|
83
91
|
EnvironmentVariableDelete.flags = {
|
|
84
|
-
name: core_1.Flags.string({
|
|
92
|
+
'variable-name': core_1.Flags.string({
|
|
85
93
|
description: 'Name of the variable to delete',
|
|
86
94
|
}),
|
|
95
|
+
'variable-environment': core_1.Flags.enum({
|
|
96
|
+
...flags_1.EasEnvironmentFlagParameters,
|
|
97
|
+
description: 'Current environment of the variable to delete',
|
|
98
|
+
}),
|
|
87
99
|
...flags_1.EASVariableScopeFlag,
|
|
88
|
-
...flags_1.EASEnvironmentFlag,
|
|
89
100
|
...flags_1.EASNonInteractiveFlag,
|
|
90
101
|
};
|
|
91
102
|
EnvironmentVariableDelete.contextDefinition = {
|
|
@@ -16,7 +16,8 @@ class EnvExec extends EasCommand_1.default {
|
|
|
16
16
|
const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
|
|
17
17
|
nonInteractive: parsedFlags.nonInteractive,
|
|
18
18
|
});
|
|
19
|
-
const environment = parsedFlags.environment ??
|
|
19
|
+
const environment = parsedFlags.environment ??
|
|
20
|
+
(await (0, prompts_1.promptVariableEnvironmentAsync)({ nonInteractive: parsedFlags.nonInteractive }));
|
|
20
21
|
const environmentVariables = await this.loadEnvironmentVariablesAsync({
|
|
21
22
|
graphqlClient,
|
|
22
23
|
projectId,
|
|
@@ -8,11 +8,11 @@ export default class EnvironmentVariableGet 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>;
|
|
12
11
|
'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
13
12
|
scope: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableScope>;
|
|
14
13
|
format: import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
15
|
-
name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
14
|
+
'variable-name': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
15
|
+
'variable-environment': import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment | undefined>;
|
|
16
16
|
};
|
|
17
17
|
runAsync(): Promise<void>;
|
|
18
18
|
private validateFlags;
|
|
@@ -3,32 +3,50 @@ 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");
|
|
9
10
|
const generated_1 = require("../../graphql/generated");
|
|
10
11
|
const EnvironmentVariablesQuery_1 = require("../../graphql/queries/EnvironmentVariablesQuery");
|
|
11
12
|
const log_1 = tslib_1.__importDefault(require("../../log"));
|
|
12
|
-
const formatVariable_1 = require("../../utils/formatVariable");
|
|
13
13
|
const prompts_1 = require("../../utils/prompts");
|
|
14
|
+
const variableUtils_1 = require("../../utils/variableUtils");
|
|
14
15
|
class EnvironmentVariableGet extends EasCommand_1.default {
|
|
15
16
|
async runAsync() {
|
|
16
17
|
const { flags } = await this.parse(_a);
|
|
17
|
-
let { environment, name, 'non-interactive': nonInteractive, format, scope, } = this.validateFlags(flags);
|
|
18
|
+
let { 'variable-environment': environment, 'variable-name': name, 'non-interactive': nonInteractive, format, scope, } = this.validateFlags(flags);
|
|
18
19
|
const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
|
|
19
20
|
nonInteractive,
|
|
20
21
|
});
|
|
21
22
|
if (!name) {
|
|
22
23
|
name = await (0, prompts_1.promptVariableNameAsync)(nonInteractive);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
const variable = await getVariableAsync(graphqlClient, scope, projectId, name, environment);
|
|
28
|
-
if (!variable) {
|
|
25
|
+
const variables = await getVariablesAsync(graphqlClient, scope, projectId, name, environment);
|
|
26
|
+
if (variables.length === 0) {
|
|
29
27
|
log_1.default.error(`Variable with name "${name}" not found`);
|
|
30
28
|
return;
|
|
31
29
|
}
|
|
30
|
+
let variable;
|
|
31
|
+
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
|
+
const variableInEnvironment = variables.find(v => v.environments?.includes(environment));
|
|
42
|
+
if (!variableInEnvironment) {
|
|
43
|
+
throw new Error(`Variable with name "${name}" not found in environment "${environment}"`);
|
|
44
|
+
}
|
|
45
|
+
variable = variableInEnvironment;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
variable = variables[0];
|
|
49
|
+
}
|
|
32
50
|
if (!variable.value) {
|
|
33
51
|
throw new Error(`${chalk_1.default.bold(variable.name)} is a secret variable and cannot be displayed once it has been created.`);
|
|
34
52
|
}
|
|
@@ -36,21 +54,18 @@ class EnvironmentVariableGet extends EasCommand_1.default {
|
|
|
36
54
|
log_1.default.log(`${chalk_1.default.bold(variable.name)}=${variable.value}`);
|
|
37
55
|
}
|
|
38
56
|
else {
|
|
39
|
-
log_1.default.log((0,
|
|
57
|
+
log_1.default.log((0, variableUtils_1.formatVariable)(variable));
|
|
40
58
|
}
|
|
41
59
|
}
|
|
42
60
|
validateFlags(flags) {
|
|
43
|
-
if (flags.environment && flags.scope === generated_1.EnvironmentVariableScope.Shared) {
|
|
44
|
-
throw new Error(`Unexpected argument: --environment can only be used with project variables`);
|
|
45
|
-
}
|
|
46
61
|
if (flags['non-interactive']) {
|
|
47
|
-
if (!flags
|
|
48
|
-
throw new Error('Variable name is required. Run the command with --name flag.');
|
|
62
|
+
if (!flags['variable-name']) {
|
|
63
|
+
throw new Error('Variable name is required. Run the command with --variable-name flag.');
|
|
49
64
|
}
|
|
50
65
|
if (!flags.scope) {
|
|
51
66
|
throw new Error('Scope is required. Run the command with --scope flag.');
|
|
52
67
|
}
|
|
53
|
-
if (!flags
|
|
68
|
+
if (!flags['variable-environment']) {
|
|
54
69
|
throw new Error('Environment is required.');
|
|
55
70
|
}
|
|
56
71
|
}
|
|
@@ -65,36 +80,35 @@ EnvironmentVariableGet.contextDefinition = {
|
|
|
65
80
|
..._a.ContextOptions.LoggedIn,
|
|
66
81
|
};
|
|
67
82
|
EnvironmentVariableGet.flags = {
|
|
68
|
-
name: core_1.Flags.string({
|
|
83
|
+
'variable-name': core_1.Flags.string({
|
|
69
84
|
description: 'Name of the variable',
|
|
70
85
|
}),
|
|
86
|
+
'variable-environment': core_1.Flags.enum({
|
|
87
|
+
...flags_1.EasEnvironmentFlagParameters,
|
|
88
|
+
description: 'Current environment of the variable',
|
|
89
|
+
}),
|
|
71
90
|
...flags_1.EASVariableFormatFlag,
|
|
72
91
|
...flags_1.EASVariableScopeFlag,
|
|
73
92
|
...flags_1.EASNonInteractiveFlag,
|
|
74
|
-
...flags_1.EASEnvironmentFlag,
|
|
75
93
|
};
|
|
76
94
|
exports.default = EnvironmentVariableGet;
|
|
77
|
-
async function
|
|
78
|
-
if (!environment && scope === generated_1.EnvironmentVariableScope.Project) {
|
|
79
|
-
throw new Error('Environment is required.');
|
|
80
|
-
}
|
|
95
|
+
async function getVariablesAsync(graphqlClient, scope, projectId, name, environment) {
|
|
81
96
|
if (!name) {
|
|
82
|
-
throw new Error("Variable name is required. Run the command with '--name VARIABLE_NAME' flag.");
|
|
97
|
+
throw new Error("Variable name is required. Run the command with '--variable-name VARIABLE_NAME' flag.");
|
|
83
98
|
}
|
|
84
|
-
if (
|
|
99
|
+
if (scope === generated_1.EnvironmentVariableScope.Project) {
|
|
85
100
|
const appVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, {
|
|
86
101
|
appId: projectId,
|
|
87
102
|
environment,
|
|
88
103
|
filterNames: [name],
|
|
89
104
|
});
|
|
90
|
-
return appVariables
|
|
105
|
+
return appVariables;
|
|
91
106
|
}
|
|
92
|
-
|
|
107
|
+
else {
|
|
93
108
|
const sharedVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedWithSensitiveAsync(graphqlClient, {
|
|
94
109
|
appId: projectId,
|
|
95
110
|
filterNames: [name],
|
|
96
111
|
});
|
|
97
|
-
return sharedVariables
|
|
112
|
+
return sharedVariables;
|
|
98
113
|
}
|
|
99
|
-
return null;
|
|
100
114
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import EasCommand from '../../commandUtils/EasCommand';
|
|
2
|
+
import { EnvironmentVariableEnvironment } from '../../graphql/generated';
|
|
2
3
|
export default class EnvironmentVariableLink 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<
|
|
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>;
|
|
10
|
+
'variable-environment': import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment | undefined>;
|
|
9
11
|
};
|
|
10
12
|
static contextDefinition: {
|
|
11
13
|
loggedIn: import("../../commandUtils/context/LoggedInContextField").default;
|