eas-cli 12.5.1 → 12.5.3
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 +4 -1
- package/build/commands/env/create.js +133 -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 +44 -28
- package/build/commands/env/link.d.ts +4 -2
- package/build/commands/env/link.js +53 -14
- package/build/commands/env/list.d.ts +2 -2
- package/build/commands/env/list.js +59 -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 +6 -2
- package/build/commands/env/update.js +134 -70
- package/build/commands/update/index.js +0 -1
- package/build/commands/worker/deploy.js +31 -11
- package/build/graphql/generated.d.ts +103 -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 +24 -11
- package/build/graphql/queries/EnvironmentVariablesQuery.js +40 -17
- package/build/graphql/types/EnvironmentVariable.js +3 -1
- package/build/graphql/types/EnvironmentVariableWithSecret.d.ts +1 -0
- package/build/graphql/types/EnvironmentVariableWithSecret.js +18 -0
- package/build/prompts.d.ts +1 -0
- package/build/prompts.js +2 -0
- package/build/update/republish.js +1 -0
- package/build/utils/prompts.d.ts +16 -3
- package/build/utils/prompts.js +52 -8
- package/build/utils/variableUtils.d.ts +6 -0
- package/build/utils/variableUtils.js +62 -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 +98 -41
- package/package.json +3 -3
- package/build/utils/formatVariable.d.ts +0 -2
- package/build/utils/formatVariable.js +0 -16
|
@@ -5,13 +5,14 @@ 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>;
|
|
12
12
|
value: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
13
13
|
link: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
14
14
|
force: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
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;
|
|
@@ -19,5 +20,7 @@ export default class EnvironmentVariableCreate extends EasCommand {
|
|
|
19
20
|
privateProjectConfig: import("../../commandUtils/context/PrivateProjectConfigContextField").PrivateProjectConfigContextField;
|
|
20
21
|
};
|
|
21
22
|
runAsync(): Promise<void>;
|
|
23
|
+
private promptForOverwriteAsync;
|
|
24
|
+
private promptForMissingFlagsAsync;
|
|
22
25
|
private validateFlags;
|
|
23
26
|
}
|
|
@@ -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");
|
|
@@ -13,10 +15,12 @@ const log_1 = tslib_1.__importDefault(require("../../log"));
|
|
|
13
15
|
const projectUtils_1 = require("../../project/projectUtils");
|
|
14
16
|
const prompts_1 = require("../../prompts");
|
|
15
17
|
const prompts_2 = require("../../utils/prompts");
|
|
18
|
+
const variableUtils_1 = require("../../utils/variableUtils");
|
|
16
19
|
class EnvironmentVariableCreate extends EasCommand_1.default {
|
|
17
20
|
async runAsync() {
|
|
18
21
|
const { flags } = await this.parse(_a);
|
|
19
|
-
|
|
22
|
+
const validatedFlags = this.validateFlags(flags);
|
|
23
|
+
const { name, value, scope, 'non-interactive': nonInteractive, environment: environments, visibility, link, force, type, } = await this.promptForMissingFlagsAsync(validatedFlags);
|
|
20
24
|
const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
|
|
21
25
|
nonInteractive,
|
|
22
26
|
});
|
|
@@ -24,108 +28,159 @@ class EnvironmentVariableCreate extends EasCommand_1.default {
|
|
|
24
28
|
(0, projectUtils_1.getDisplayNameForProjectIdAsync)(graphqlClient, projectId),
|
|
25
29
|
(0, projectUtils_1.getOwnerAccountForProjectIdAsync)(graphqlClient, projectId),
|
|
26
30
|
]);
|
|
27
|
-
if (!name) {
|
|
28
|
-
name = await (0, prompts_2.promptVariableNameAsync)(nonInteractive);
|
|
29
|
-
}
|
|
30
31
|
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
32
|
if (scope === generated_1.EnvironmentVariableScope.Project) {
|
|
39
|
-
if (!environment) {
|
|
40
|
-
environment = await (0, prompts_2.promptVariableEnvironmentAsync)(nonInteractive);
|
|
41
|
-
}
|
|
42
33
|
const existingVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdAsync(graphqlClient, {
|
|
43
34
|
appId: projectId,
|
|
44
|
-
|
|
35
|
+
filterNames: [name],
|
|
45
36
|
});
|
|
46
|
-
const existingVariable = existingVariables.find(variable => variable.
|
|
37
|
+
const existingVariable = existingVariables.find(variable => !environments || variable.environments?.some(env => environments?.includes(env)));
|
|
47
38
|
if (existingVariable) {
|
|
39
|
+
if (existingVariable.scope === generated_1.EnvironmentVariableScope.Project) {
|
|
40
|
+
await this.promptForOverwriteAsync({
|
|
41
|
+
nonInteractive,
|
|
42
|
+
force,
|
|
43
|
+
message: `Variable ${name} already exists on this project.`,
|
|
44
|
+
suggestion: 'Do you want to overwrite it?',
|
|
45
|
+
});
|
|
46
|
+
overwrite = true;
|
|
47
|
+
}
|
|
48
48
|
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);
|
|
49
|
+
await this.promptForOverwriteAsync({
|
|
50
|
+
nonInteractive,
|
|
51
|
+
force,
|
|
52
|
+
message: `Shared variable with ${name} name already exists on this account.`,
|
|
53
|
+
suggestion: 'Do you want to unlink it first?',
|
|
54
|
+
});
|
|
62
55
|
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;
|
|
56
|
+
await (0, variableUtils_1.performForEnvironmentsAsync)(environments, async (environment) => {
|
|
57
|
+
await EnvironmentVariableMutation_1.EnvironmentVariableMutation.unlinkSharedEnvironmentVariableAsync(graphqlClient, existingVariable.id, projectId, environment);
|
|
58
|
+
});
|
|
78
59
|
}
|
|
79
60
|
}
|
|
80
|
-
const variable =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
61
|
+
const variable = overwrite && existingVariable
|
|
62
|
+
? await EnvironmentVariableMutation_1.EnvironmentVariableMutation.updateAsync(graphqlClient, {
|
|
63
|
+
id: existingVariable.id,
|
|
64
|
+
name,
|
|
65
|
+
value,
|
|
66
|
+
visibility,
|
|
67
|
+
environments,
|
|
68
|
+
type,
|
|
69
|
+
})
|
|
70
|
+
: await EnvironmentVariableMutation_1.EnvironmentVariableMutation.createForAppAsync(graphqlClient, {
|
|
71
|
+
name,
|
|
72
|
+
value,
|
|
73
|
+
environments,
|
|
74
|
+
visibility,
|
|
75
|
+
type: type ?? generated_1.EnvironmentSecretType.String,
|
|
76
|
+
}, projectId);
|
|
87
77
|
if (!variable) {
|
|
88
78
|
throw new Error(`Could not create variable with name ${name} on project ${projectDisplayName}`);
|
|
89
79
|
}
|
|
90
80
|
log_1.default.withTick(`Created a new variable ${chalk_1.default.bold(name)} on project ${chalk_1.default.bold(projectDisplayName)}.`);
|
|
91
81
|
}
|
|
92
82
|
else if (scope === generated_1.EnvironmentVariableScope.Shared) {
|
|
93
|
-
const
|
|
83
|
+
const existingVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedAsync(graphqlClient, {
|
|
94
84
|
appId: projectId,
|
|
85
|
+
filterNames: [name],
|
|
95
86
|
});
|
|
96
|
-
const existingVariable =
|
|
87
|
+
const existingVariable = existingVariables.find(variable => !environments || variable.environments?.some(env => environments?.includes(env)));
|
|
97
88
|
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.');
|
|
89
|
+
if (force) {
|
|
90
|
+
overwrite = true;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
throw new Error(`Shared variable with ${name} name already exists on this account.\n` +
|
|
94
|
+
`Use a different name or delete the existing variable on website or by using eas env:delete --name ${name} --scope shared command.`);
|
|
108
95
|
}
|
|
109
96
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
97
|
+
const variable = overwrite && existingVariable
|
|
98
|
+
? await EnvironmentVariableMutation_1.EnvironmentVariableMutation.updateAsync(graphqlClient, {
|
|
99
|
+
id: existingVariable.id,
|
|
100
|
+
name,
|
|
101
|
+
value,
|
|
102
|
+
visibility,
|
|
103
|
+
environments,
|
|
104
|
+
type,
|
|
105
|
+
})
|
|
106
|
+
: await EnvironmentVariableMutation_1.EnvironmentVariableMutation.createSharedVariableAsync(graphqlClient, {
|
|
107
|
+
name,
|
|
108
|
+
value,
|
|
109
|
+
visibility,
|
|
110
|
+
environments,
|
|
111
|
+
type: type ?? generated_1.EnvironmentSecretType.String,
|
|
112
|
+
}, ownerAccount.id);
|
|
118
113
|
if (!variable) {
|
|
119
114
|
throw new Error(`Could not create variable with name ${name} on account ${ownerAccount.name}`);
|
|
120
115
|
}
|
|
121
116
|
log_1.default.withTick(`Created a new variable ${chalk_1.default.bold(name)} on account ${chalk_1.default.bold(ownerAccount.name)}.`);
|
|
122
|
-
if (link
|
|
117
|
+
if (link) {
|
|
123
118
|
log_1.default.withTick(`Linking shared variable ${chalk_1.default.bold(name)} to project ${chalk_1.default.bold(projectDisplayName)}.`);
|
|
124
|
-
await
|
|
119
|
+
await (0, variableUtils_1.performForEnvironmentsAsync)(environments, async (environment) => {
|
|
120
|
+
await EnvironmentVariableMutation_1.EnvironmentVariableMutation.linkSharedEnvironmentVariableAsync(graphqlClient, variable.id, projectId, environment);
|
|
121
|
+
});
|
|
125
122
|
log_1.default.withTick(`Linked shared variable ${chalk_1.default.bold(name)} to project ${chalk_1.default.bold(projectDisplayName)}.`);
|
|
126
123
|
}
|
|
127
124
|
}
|
|
128
125
|
}
|
|
126
|
+
async promptForOverwriteAsync({ nonInteractive, force, message, suggestion, }) {
|
|
127
|
+
if (!nonInteractive) {
|
|
128
|
+
const confirmation = await (0, prompts_1.confirmAsync)({
|
|
129
|
+
message: `${message} ${suggestion}`,
|
|
130
|
+
});
|
|
131
|
+
if (!confirmation) {
|
|
132
|
+
log_1.default.log('Aborting');
|
|
133
|
+
throw new Error(`${message}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (!force) {
|
|
137
|
+
throw new Error(`${message} Use --force to overwrite it.`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async promptForMissingFlagsAsync({ name, value, environment, visibility = generated_1.EnvironmentVariableVisibility.Public, 'non-interactive': nonInteractive, type, ...rest }) {
|
|
141
|
+
if (!name) {
|
|
142
|
+
name = await (0, prompts_2.promptVariableNameAsync)(nonInteractive);
|
|
143
|
+
}
|
|
144
|
+
let newType;
|
|
145
|
+
if (type === 'file') {
|
|
146
|
+
newType = generated_1.EnvironmentSecretType.FileBase64;
|
|
147
|
+
}
|
|
148
|
+
else if (type === 'string') {
|
|
149
|
+
newType = generated_1.EnvironmentSecretType.String;
|
|
150
|
+
}
|
|
151
|
+
if (!type && !value && !nonInteractive) {
|
|
152
|
+
newType = await (0, prompts_2.promptVariableTypeAsync)(nonInteractive);
|
|
153
|
+
}
|
|
154
|
+
if (!value) {
|
|
155
|
+
value = await (0, prompts_2.promptVariableValueAsync)({
|
|
156
|
+
nonInteractive,
|
|
157
|
+
hidden: visibility !== generated_1.EnvironmentVariableVisibility.Public,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
let environmentFilePath;
|
|
161
|
+
if (newType === generated_1.EnvironmentSecretType.FileBase64) {
|
|
162
|
+
environmentFilePath = path_1.default.resolve(value);
|
|
163
|
+
if (!(await fs_extra_1.default.pathExists(environmentFilePath))) {
|
|
164
|
+
throw new Error(`File "${value}" does not exist`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
value = environmentFilePath ? await fs_extra_1.default.readFile(environmentFilePath, 'base64') : value;
|
|
168
|
+
if (!environment) {
|
|
169
|
+
environment = await (0, prompts_2.promptVariableEnvironmentAsync)({ nonInteractive, multiple: true });
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
name,
|
|
173
|
+
value,
|
|
174
|
+
environment,
|
|
175
|
+
visibility,
|
|
176
|
+
link: rest.link ?? false,
|
|
177
|
+
force: rest.force ?? false,
|
|
178
|
+
scope: rest.scope ?? generated_1.EnvironmentVariableScope.Project,
|
|
179
|
+
'non-interactive': nonInteractive,
|
|
180
|
+
type: newType,
|
|
181
|
+
...rest,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
129
184
|
validateFlags(flags) {
|
|
130
185
|
if (flags.scope !== generated_1.EnvironmentVariableScope.Shared && flags.link) {
|
|
131
186
|
throw new Error(`Unexpected argument: --link can only be used when creating shared variables`);
|
|
@@ -156,9 +211,13 @@ EnvironmentVariableCreate.flags = {
|
|
|
156
211
|
description: 'Overwrite existing variable',
|
|
157
212
|
default: false,
|
|
158
213
|
}),
|
|
214
|
+
type: core_1.Flags.enum({
|
|
215
|
+
description: 'The type of variable',
|
|
216
|
+
options: ['string', 'file'],
|
|
217
|
+
}),
|
|
159
218
|
...flags_1.EASVariableVisibilityFlag,
|
|
160
219
|
...flags_1.EASVariableScopeFlag,
|
|
161
|
-
...flags_1.
|
|
220
|
+
...flags_1.EASMultiEnvironmentFlag,
|
|
162
221
|
...flags_1.EASNonInteractiveFlag,
|
|
163
222
|
};
|
|
164
223
|
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,54 +3,69 @@ 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
|
}
|
|
32
|
-
|
|
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
|
+
}
|
|
50
|
+
if (variable.visibility === generated_1.EnvironmentVariableVisibility.Secret) {
|
|
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
|
}
|
|
35
53
|
if (format === 'short') {
|
|
36
|
-
log_1.default.log(`${chalk_1.default.bold(variable.name)}=${variable
|
|
54
|
+
log_1.default.log(`${chalk_1.default.bold(variable.name)}=${(0, variableUtils_1.formatVariableValue)(variable)}`);
|
|
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,37 @@ 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],
|
|
104
|
+
includeFileContent: true,
|
|
89
105
|
});
|
|
90
|
-
return appVariables
|
|
106
|
+
return appVariables;
|
|
91
107
|
}
|
|
92
|
-
|
|
108
|
+
else {
|
|
93
109
|
const sharedVariables = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.sharedWithSensitiveAsync(graphqlClient, {
|
|
94
110
|
appId: projectId,
|
|
95
111
|
filterNames: [name],
|
|
112
|
+
includeFileContent: true,
|
|
96
113
|
});
|
|
97
|
-
return sharedVariables
|
|
114
|
+
return sharedVariables;
|
|
98
115
|
}
|
|
99
|
-
return null;
|
|
100
116
|
}
|
|
@@ -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;
|