eas-cli 12.5.0 → 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 +72 -64
- package/build/build/build.js +4 -4
- package/build/build/evaluateConfigWithEnvVarsAsync.d.ts +1 -4
- package/build/build/evaluateConfigWithEnvVarsAsync.js +3 -6
- package/build/build/runBuildAndSubmit.d.ts +0 -2
- package/build/build/runBuildAndSubmit.js +0 -1
- package/build/commandUtils/flags.d.ts +9 -2
- package/build/commandUtils/flags.js +14 -21
- package/build/commands/build/index.d.ts +0 -2
- package/build/commands/build/index.js +0 -2
- package/build/commands/build/resign.d.ts +0 -1
- package/build/commands/build/resign.js +0 -2
- package/build/commands/build/version/get.d.ts +0 -1
- package/build/commands/build/version/get.js +0 -2
- package/build/commands/build/version/set.d.ts +0 -1
- package/build/commands/build/version/set.js +0 -3
- package/build/commands/build/version/sync.d.ts +0 -1
- package/build/commands/build/version/sync.js +0 -3
- package/build/commands/config.d.ts +0 -1
- package/build/commands/config.js +0 -2
- 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.d.ts +23 -0
- package/build/commands/env/exec.js +125 -0
- 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/update/republish.d.ts +2 -0
- package/build/commands/update/republish.js +34 -4
- package/build/commands/worker/deploy.js +44 -21
- package/build/credentials/manager/Actions.d.ts +4 -2
- package/build/credentials/manager/Actions.js +2 -0
- package/build/credentials/manager/AndroidActions.js +5 -0
- package/build/credentials/manager/IosActions.js +5 -0
- package/build/credentials/manager/ManageAndroid.js +3 -0
- package/build/credentials/manager/ManageIos.js +3 -0
- package/build/graphql/generated.d.ts +103 -22
- 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/graphql/types/Submission.js +1 -1
- package/build/project/publish.js +3 -2
- package/build/submit/utils/logs.js +16 -17
- package/build/update/getBranchFromChannelNameAndCreateAndLinkIfNotExistsAsync.d.ts +5 -0
- package/build/update/{getBranchNameFromChannelNameAsync.js → getBranchFromChannelNameAndCreateAndLinkIfNotExistsAsync.js} +8 -7
- package/build/update/republish.js +3 -2
- 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 +7 -2
- package/build/worker/assets.js +5 -4
- package/build/worker/deployment.d.ts +10 -0
- package/build/worker/deployment.js +33 -22
- package/build/worker/upload.d.ts +1 -0
- package/build/worker/upload.js +29 -7
- package/build/worker/utils/logs.d.ts +14 -13
- package/build/worker/utils/logs.js +18 -18
- package/oclif.manifest.json +118 -108
- package/package.json +3 -3
- package/build/update/getBranchNameFromChannelNameAsync.d.ts +0 -2
- package/build/utils/formatVariable.d.ts +0 -2
- package/build/utils/formatVariable.js +0 -16
|
@@ -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 = {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import EasCommand from '../../commandUtils/EasCommand';
|
|
2
|
+
import { EnvironmentVariableEnvironment } from '../../graphql/generated';
|
|
3
|
+
export default class EnvExec extends EasCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static hidden: boolean;
|
|
6
|
+
static contextDefinition: {
|
|
7
|
+
loggedIn: import("../../commandUtils/context/LoggedInContextField").default;
|
|
8
|
+
privateProjectConfig: import("../../commandUtils/context/PrivateProjectConfigContextField").PrivateProjectConfigContextField;
|
|
9
|
+
};
|
|
10
|
+
static flags: {
|
|
11
|
+
'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
environment: import("@oclif/core/lib/interfaces").OptionFlag<EnvironmentVariableEnvironment | undefined>;
|
|
13
|
+
};
|
|
14
|
+
static args: {
|
|
15
|
+
name: string;
|
|
16
|
+
required: boolean;
|
|
17
|
+
description: string;
|
|
18
|
+
}[];
|
|
19
|
+
runAsync(): Promise<void>;
|
|
20
|
+
private sanitizeFlags;
|
|
21
|
+
private runCommandWithEnvVarsAsync;
|
|
22
|
+
private loadEnvironmentVariablesAsync;
|
|
23
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const spawn_async_1 = tslib_1.__importDefault(require("@expo/spawn-async"));
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
+
const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand"));
|
|
8
|
+
const flags_1 = require("../../commandUtils/flags");
|
|
9
|
+
const EnvironmentVariablesQuery_1 = require("../../graphql/queries/EnvironmentVariablesQuery");
|
|
10
|
+
const log_1 = tslib_1.__importDefault(require("../../log"));
|
|
11
|
+
const prompts_1 = require("../../utils/prompts");
|
|
12
|
+
class EnvExec extends EasCommand_1.default {
|
|
13
|
+
async runAsync() {
|
|
14
|
+
const { flags, args: { BASH_COMMAND: command }, } = await this.parse(_a);
|
|
15
|
+
const parsedFlags = this.sanitizeFlags(flags);
|
|
16
|
+
const { privateProjectConfig: { projectId }, loggedIn: { graphqlClient }, } = await this.getContextAsync(_a, {
|
|
17
|
+
nonInteractive: parsedFlags.nonInteractive,
|
|
18
|
+
});
|
|
19
|
+
const environment = parsedFlags.environment ??
|
|
20
|
+
(await (0, prompts_1.promptVariableEnvironmentAsync)({ nonInteractive: parsedFlags.nonInteractive }));
|
|
21
|
+
const environmentVariables = await this.loadEnvironmentVariablesAsync({
|
|
22
|
+
graphqlClient,
|
|
23
|
+
projectId,
|
|
24
|
+
environment,
|
|
25
|
+
});
|
|
26
|
+
await this.runCommandWithEnvVarsAsync({ command, environmentVariables });
|
|
27
|
+
}
|
|
28
|
+
sanitizeFlags(rawFlags) {
|
|
29
|
+
const environment = rawFlags.environment;
|
|
30
|
+
if (rawFlags['non-interactive']) {
|
|
31
|
+
if (!environment) {
|
|
32
|
+
throw new Error('You must specify an environment when running in non-interactive mode. Use the --environment flag.');
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
nonInteractive: true,
|
|
36
|
+
environment,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
nonInteractive: false,
|
|
41
|
+
environment: rawFlags.environment,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async runCommandWithEnvVarsAsync({ command, environmentVariables, }) {
|
|
45
|
+
log_1.default.log(`Running command: ${chalk_1.default.bold(command)}`);
|
|
46
|
+
const spawnPromise = (0, spawn_async_1.default)('bash', ['-c', command], {
|
|
47
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
48
|
+
env: {
|
|
49
|
+
...process.env,
|
|
50
|
+
...environmentVariables,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
const { child: { stdout, stderr }, } = spawnPromise;
|
|
54
|
+
if (!stdout || !stderr) {
|
|
55
|
+
throw new Error(`Failed to spawn ${command}`);
|
|
56
|
+
}
|
|
57
|
+
stdout.on('data', data => {
|
|
58
|
+
for (const line of data.toString().trim().split('\n')) {
|
|
59
|
+
log_1.default.log(`${chalk_1.default.gray('[stdout]')} ${line}`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
stderr.on('data', data => {
|
|
63
|
+
for (const line of data.toString().trim().split('\n')) {
|
|
64
|
+
log_1.default.warn(`${chalk_1.default.gray('[stderr]')} ${line}`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
await spawnPromise;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
log_1.default.error(`❌ ${chalk_1.default.bold(command)} failed`);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async loadEnvironmentVariablesAsync({ graphqlClient, projectId, environment, }) {
|
|
76
|
+
const environmentVariablesQueryResult = await EnvironmentVariablesQuery_1.EnvironmentVariablesQuery.byAppIdWithSensitiveAsync(graphqlClient, {
|
|
77
|
+
appId: projectId,
|
|
78
|
+
environment,
|
|
79
|
+
});
|
|
80
|
+
const secretEnvironmentVariables = environmentVariablesQueryResult.filter(({ value }) => !value);
|
|
81
|
+
if (secretEnvironmentVariables.length > 0) {
|
|
82
|
+
log_1.default.warn(`The following environment variables are secret and cannot be downloaded locally:`);
|
|
83
|
+
for (const { name } of secretEnvironmentVariables) {
|
|
84
|
+
log_1.default.warn(`- ${name}`);
|
|
85
|
+
}
|
|
86
|
+
log_1.default.warn('Proceeding with the rest of the environment variables.');
|
|
87
|
+
log_1.default.newLine();
|
|
88
|
+
}
|
|
89
|
+
const nonSecretEnvironmentVariables = environmentVariablesQueryResult.filter(({ value }) => !!value);
|
|
90
|
+
if (nonSecretEnvironmentVariables.length === 0) {
|
|
91
|
+
throw new Error('No readable environment variables found for the selected environment.');
|
|
92
|
+
}
|
|
93
|
+
log_1.default.log(`Loaded environment variables for the selected environment "${environment.toLowerCase()}":`);
|
|
94
|
+
for (const { name } of nonSecretEnvironmentVariables) {
|
|
95
|
+
log_1.default.log(`- ${name}`);
|
|
96
|
+
}
|
|
97
|
+
log_1.default.newLine();
|
|
98
|
+
const environmentVariables = {};
|
|
99
|
+
for (const { name, value } of nonSecretEnvironmentVariables) {
|
|
100
|
+
if (value) {
|
|
101
|
+
environmentVariables[name] = value;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return environmentVariables;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_a = EnvExec;
|
|
108
|
+
EnvExec.description = 'execute a bash command with environment variables from the selected environment';
|
|
109
|
+
EnvExec.hidden = true;
|
|
110
|
+
EnvExec.contextDefinition = {
|
|
111
|
+
..._a.ContextOptions.ProjectConfig,
|
|
112
|
+
..._a.ContextOptions.LoggedIn,
|
|
113
|
+
};
|
|
114
|
+
EnvExec.flags = {
|
|
115
|
+
...flags_1.EASEnvironmentFlag,
|
|
116
|
+
...flags_1.EASNonInteractiveFlag,
|
|
117
|
+
};
|
|
118
|
+
EnvExec.args = [
|
|
119
|
+
{
|
|
120
|
+
name: 'BASH_COMMAND',
|
|
121
|
+
required: true,
|
|
122
|
+
description: 'bash command to execute with the environment variables from the environment',
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
exports.default = EnvExec;
|
|
@@ -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;
|
|
@@ -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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
}
|