@project-ajax/sdk 0.0.51 → 0.0.53
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/dist/cli/api/client.d.ts +9 -0
- package/dist/cli/api/client.d.ts.map +1 -1
- package/dist/cli/api/client.js +11 -0
- package/dist/cli/commands/env.d.ts +2 -0
- package/dist/cli/commands/env.d.ts.map +1 -0
- package/dist/cli/commands/env.impl.d.ts +11 -0
- package/dist/cli/commands/env.impl.d.ts.map +1 -0
- package/dist/cli/commands/env.impl.js +65 -0
- package/dist/cli/commands/env.js +39 -0
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +1 -0
- package/dist/cli/routes.d.ts.map +1 -1
- package/dist/cli/routes.js +2 -0
- package/package.json +1 -1
- package/src/cli/api/client.ts +22 -0
- package/src/cli/commands/env.impl.ts +92 -0
- package/src/cli/commands/env.ts +38 -0
- package/src/cli/config.ts +5 -3
- package/src/cli/routes.ts +2 -0
package/dist/cli/api/client.d.ts
CHANGED
|
@@ -125,6 +125,15 @@ export declare class ApiClient {
|
|
|
125
125
|
kind: "keyValue" | "oauth";
|
|
126
126
|
}>;
|
|
127
127
|
}, ApiError>>;
|
|
128
|
+
/**
|
|
129
|
+
* Pull decrypted env vars for a worker
|
|
130
|
+
*/
|
|
131
|
+
pullEnv(workerId: string): Promise<Result<{
|
|
132
|
+
env: Array<{
|
|
133
|
+
key: string;
|
|
134
|
+
value: string;
|
|
135
|
+
}>;
|
|
136
|
+
}, ApiError>>;
|
|
128
137
|
listOauthProviders(): Promise<Result<{
|
|
129
138
|
providers: Array<{
|
|
130
139
|
key: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/cli/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aA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AAO,EAAE,MAAM,CAAC;YAChB,KAAK,EAAE,MAAM,CAAC;YACd,IAAI,EAAE,MAAM,CAAC;YACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;YACxB,SAAS,EAAE,MAAM,CAAC;YAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;SACvB,CAAC,CAAC;KACH,EACD,QAAQ,CACR,CACD;IASD;;OAEG;IACG,UAAU,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACX,OAAO,CACT,MAAM,CACL;QACC,IAAI,EAAE,MAAM,CAAC;KACb,EACD,QAAQ,CACR,CACD;CASD"}
|
package/dist/cli/api/client.js
CHANGED
|
@@ -143,6 +143,17 @@ class ApiClient {
|
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Pull decrypted env vars for a worker
|
|
148
|
+
*/
|
|
149
|
+
async pullEnv(workerId) {
|
|
150
|
+
return this.fetch("/workersPullEnv", {
|
|
151
|
+
method: "POST",
|
|
152
|
+
body: {
|
|
153
|
+
workerId
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
146
157
|
async listOauthProviders() {
|
|
147
158
|
return this.fetch("/workersListOauthProviders", {
|
|
148
159
|
method: "POST",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/env.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,wEAiCtB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface PullEnvFlags {
|
|
2
|
+
yes: boolean;
|
|
3
|
+
}
|
|
4
|
+
export declare const DEFAULT_ENV_FILE = ".env";
|
|
5
|
+
export declare const pullEnv: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags & PullEnvFlags, filePath?: string | undefined) => Promise<void>;
|
|
6
|
+
export declare function serializeEnvFile(envEntries: Array<{
|
|
7
|
+
key: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}>): string;
|
|
10
|
+
export declare function formatEnvValue(value: string): string;
|
|
11
|
+
//# sourceMappingURL=env.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/env.impl.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IAC5B,GAAG,EAAE,OAAO,CAAC;CACb;AAED,eAAO,MAAM,gBAAgB,SAAS,CAAC;AAEvC,eAAO,MAAM,OAAO,uJAmDlB,CAAC;AAEH,wBAAgB,gBAAgB,CAC/B,UAAU,EAAE,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GAC/C,MAAM,CASR;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAapD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import prompts from "prompts";
|
|
2
|
+
import { Result } from "../api/result.js";
|
|
3
|
+
import { buildAuthedHandler } from "../handler.js";
|
|
4
|
+
import { pluralize } from "../utils/string.js";
|
|
5
|
+
const DEFAULT_ENV_FILE = ".env";
|
|
6
|
+
const pullEnv = buildAuthedHandler(async function(flags, filePath) {
|
|
7
|
+
const { workerId } = this.config;
|
|
8
|
+
if (!workerId) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
const destination = filePath ?? DEFAULT_ENV_FILE;
|
|
14
|
+
const absoluteDestination = this.path.resolve(
|
|
15
|
+
this.process.cwd(),
|
|
16
|
+
destination
|
|
17
|
+
);
|
|
18
|
+
if (this.fs.existsSync(absoluteDestination) && !flags.yes) {
|
|
19
|
+
const { overwrite } = await prompts({
|
|
20
|
+
type: "confirm",
|
|
21
|
+
name: "overwrite",
|
|
22
|
+
message: `File "${destination}" already exists. Overwrite it?`,
|
|
23
|
+
initial: false
|
|
24
|
+
});
|
|
25
|
+
if (overwrite !== true) {
|
|
26
|
+
this.writer.writeErr("Aborted.");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
this.writer.writeErr("Fetching environment variables...");
|
|
31
|
+
const envResult = await this.apiClient.pullEnv(workerId);
|
|
32
|
+
if (Result.isFail(envResult)) {
|
|
33
|
+
this.writer.writeErr("\u2717 Failed to fetch env vars");
|
|
34
|
+
this.writer.writeErr(`\u2717 ${envResult.error.message}`);
|
|
35
|
+
throw new Error(envResult.error.message);
|
|
36
|
+
}
|
|
37
|
+
const envEntries = envResult.value.env;
|
|
38
|
+
const fileContents = serializeEnvFile(envEntries);
|
|
39
|
+
await this.fs.promises.mkdir(this.path.dirname(absoluteDestination), {
|
|
40
|
+
recursive: true
|
|
41
|
+
});
|
|
42
|
+
await this.fs.promises.writeFile(absoluteDestination, fileContents, "utf8");
|
|
43
|
+
this.writer.writeErr(
|
|
44
|
+
`Wrote ${pluralize(envEntries.length, "env var")} to "${destination}"`
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
function serializeEnvFile(envEntries) {
|
|
48
|
+
if (envEntries.length === 0) {
|
|
49
|
+
return "# No env vars configured for this worker\n";
|
|
50
|
+
}
|
|
51
|
+
return envEntries.map(({ key, value }) => `${key}=${formatEnvValue(value)}`).join("\n").concat("\n");
|
|
52
|
+
}
|
|
53
|
+
function formatEnvValue(value) {
|
|
54
|
+
if (/^[A-Za-z0-9_./:-]*$/.test(value)) {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
const escaped = value.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/"/g, '\\"');
|
|
58
|
+
return `"${escaped}"`;
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
DEFAULT_ENV_FILE,
|
|
62
|
+
formatEnvValue,
|
|
63
|
+
pullEnv,
|
|
64
|
+
serializeEnvFile
|
|
65
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
+
import { globalFlags } from "../flags.js";
|
|
3
|
+
const envCommands = buildRouteMap({
|
|
4
|
+
docs: {
|
|
5
|
+
brief: "Work with worker environment files"
|
|
6
|
+
},
|
|
7
|
+
routes: {
|
|
8
|
+
pull: buildCommand({
|
|
9
|
+
docs: {
|
|
10
|
+
brief: "Write the worker's env vars to a .env file"
|
|
11
|
+
},
|
|
12
|
+
parameters: {
|
|
13
|
+
positional: {
|
|
14
|
+
kind: "tuple",
|
|
15
|
+
parameters: [
|
|
16
|
+
{
|
|
17
|
+
brief: "Destination file path",
|
|
18
|
+
parse: String,
|
|
19
|
+
placeholder: "file",
|
|
20
|
+
optional: true
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
flags: {
|
|
25
|
+
...globalFlags,
|
|
26
|
+
yes: {
|
|
27
|
+
kind: "boolean",
|
|
28
|
+
brief: "Overwrite the output file without prompting",
|
|
29
|
+
default: false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
loader: () => import("./env.impl.js").then((m) => m.pullEnv)
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
export {
|
|
38
|
+
envCommands
|
|
39
|
+
};
|
package/dist/cli/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/cli/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,YAAY,8CAA+C,CAAC;AACzE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD,UAAU,SAAS;IAClB,WAAW,EAAE,WA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,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAM1D;AAED,qBAAa,gBAAiB,SAAQ,KAAK;gBAEzC,OAAO,GAAE,MAA6D;CAKvE;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;;gBAIN,IAAI,EAAE;QACjB,cAAc,EAAE,MAAM,CAAC;QACvB,UAAU,EAAE,SAAS,CAAC;KACtB;IAOD,IAAI,OAAO,WAEV;IAED,IAAI,KAAK,kBAER;IAED,IAAI,WAAW,yCAEd;IAED,IAAI,QAAQ,kBAEX;IAIK,cAAc,CAAC,WAAW,EAAE,WAAW;IAKvC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK7B,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAazC,IAAI,SAAS,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAQlE;WAEY,IAAI,CAAC,IAAI,EAAE;QACvB,cAAc,EAAE,MAAM,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC;QAC9B,KAAK,EAAE,WAAW,CAAC;KACnB;CAkED;AAQD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CACf,CAoCA"}
|
package/dist/cli/config.js
CHANGED
package/dist/cli/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/cli/routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/cli/routes.ts"],"names":[],"mappings":"AA4CA,eAAO,MAAM,GAAG,0EAgBd,CAAC"}
|
package/dist/cli/routes.js
CHANGED
|
@@ -5,6 +5,7 @@ import { bundleCommands } from "./commands/bundle.js";
|
|
|
5
5
|
import { capabilitiesCommands } from "./commands/capabilities.js";
|
|
6
6
|
import { connectCommands } from "./commands/connect.js";
|
|
7
7
|
import deploy from "./commands/deploy.js";
|
|
8
|
+
import { envCommands } from "./commands/env.js";
|
|
8
9
|
import exec from "./commands/exec.js";
|
|
9
10
|
import { runsCommands } from "./commands/runs.js";
|
|
10
11
|
import { secretsCommands } from "./commands/secrets.js";
|
|
@@ -33,6 +34,7 @@ variables can also be provided:
|
|
|
33
34
|
deploy,
|
|
34
35
|
exec,
|
|
35
36
|
connect: connectCommands,
|
|
37
|
+
env: envCommands,
|
|
36
38
|
runs: runsCommands,
|
|
37
39
|
secrets: secretsCommands,
|
|
38
40
|
bundle: bundleCommands
|
package/package.json
CHANGED
package/src/cli/api/client.ts
CHANGED
|
@@ -315,6 +315,28 @@ export class ApiClient {
|
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
/**
|
|
319
|
+
* Pull decrypted env vars for a worker
|
|
320
|
+
*/
|
|
321
|
+
async pullEnv(workerId: string): Promise<
|
|
322
|
+
Result<
|
|
323
|
+
{
|
|
324
|
+
env: Array<{
|
|
325
|
+
key: string;
|
|
326
|
+
value: string;
|
|
327
|
+
}>;
|
|
328
|
+
},
|
|
329
|
+
ApiError
|
|
330
|
+
>
|
|
331
|
+
> {
|
|
332
|
+
return this.fetch("/workersPullEnv", {
|
|
333
|
+
method: "POST",
|
|
334
|
+
body: {
|
|
335
|
+
workerId,
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
318
340
|
async listOauthProviders(): Promise<
|
|
319
341
|
Result<
|
|
320
342
|
{
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import prompts from "prompts";
|
|
2
|
+
|
|
3
|
+
import { Result } from "../api/result.js";
|
|
4
|
+
import { buildAuthedHandler } from "../handler.js";
|
|
5
|
+
import { pluralize } from "../utils/string.js";
|
|
6
|
+
|
|
7
|
+
export interface PullEnvFlags {
|
|
8
|
+
yes: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_ENV_FILE = ".env";
|
|
12
|
+
|
|
13
|
+
export const pullEnv = buildAuthedHandler(async function (
|
|
14
|
+
flags: PullEnvFlags,
|
|
15
|
+
filePath?: string,
|
|
16
|
+
) {
|
|
17
|
+
const { workerId } = this.config;
|
|
18
|
+
if (!workerId) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"No worker configured. Run 'workers deploy' first to create a worker.",
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const destination = filePath ?? DEFAULT_ENV_FILE;
|
|
25
|
+
const absoluteDestination = this.path.resolve(
|
|
26
|
+
this.process.cwd(),
|
|
27
|
+
destination,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
if (this.fs.existsSync(absoluteDestination) && !flags.yes) {
|
|
31
|
+
const { overwrite } = await prompts({
|
|
32
|
+
type: "confirm",
|
|
33
|
+
name: "overwrite",
|
|
34
|
+
message: `File "${destination}" already exists. Overwrite it?`,
|
|
35
|
+
initial: false,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (overwrite !== true) {
|
|
39
|
+
this.writer.writeErr("Aborted.");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.writer.writeErr("Fetching environment variables...");
|
|
45
|
+
const envResult = await this.apiClient.pullEnv(workerId);
|
|
46
|
+
|
|
47
|
+
if (Result.isFail(envResult)) {
|
|
48
|
+
this.writer.writeErr("✗ Failed to fetch env vars");
|
|
49
|
+
this.writer.writeErr(`✗ ${envResult.error.message}`);
|
|
50
|
+
throw new Error(envResult.error.message);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const envEntries = envResult.value.env;
|
|
54
|
+
const fileContents = serializeEnvFile(envEntries);
|
|
55
|
+
|
|
56
|
+
await this.fs.promises.mkdir(this.path.dirname(absoluteDestination), {
|
|
57
|
+
recursive: true,
|
|
58
|
+
});
|
|
59
|
+
await this.fs.promises.writeFile(absoluteDestination, fileContents, "utf8");
|
|
60
|
+
|
|
61
|
+
this.writer.writeErr(
|
|
62
|
+
`Wrote ${pluralize(envEntries.length, "env var")} to "${destination}"`,
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export function serializeEnvFile(
|
|
67
|
+
envEntries: Array<{ key: string; value: string }>,
|
|
68
|
+
): string {
|
|
69
|
+
if (envEntries.length === 0) {
|
|
70
|
+
return "# No env vars configured for this worker\n";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return envEntries
|
|
74
|
+
.map(({ key, value }) => `${key}=${formatEnvValue(value)}`)
|
|
75
|
+
.join("\n")
|
|
76
|
+
.concat("\n");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function formatEnvValue(value: string): string {
|
|
80
|
+
if (/^[A-Za-z0-9_./:-]*$/.test(value)) {
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const escaped = value
|
|
85
|
+
.replace(/\\/g, "\\\\")
|
|
86
|
+
.replace(/\n/g, "\\n")
|
|
87
|
+
.replace(/\r/g, "\\r")
|
|
88
|
+
.replace(/\t/g, "\\t")
|
|
89
|
+
.replace(/"/g, '\\"');
|
|
90
|
+
|
|
91
|
+
return `"${escaped}"`;
|
|
92
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
+
|
|
3
|
+
import { globalFlags } from "../flags.js";
|
|
4
|
+
|
|
5
|
+
export const envCommands = buildRouteMap({
|
|
6
|
+
docs: {
|
|
7
|
+
brief: "Work with worker environment files",
|
|
8
|
+
},
|
|
9
|
+
routes: {
|
|
10
|
+
pull: buildCommand({
|
|
11
|
+
docs: {
|
|
12
|
+
brief: "Write the worker's env vars to a .env file",
|
|
13
|
+
},
|
|
14
|
+
parameters: {
|
|
15
|
+
positional: {
|
|
16
|
+
kind: "tuple",
|
|
17
|
+
parameters: [
|
|
18
|
+
{
|
|
19
|
+
brief: "Destination file path",
|
|
20
|
+
parse: String,
|
|
21
|
+
placeholder: "file",
|
|
22
|
+
optional: true,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
flags: {
|
|
27
|
+
...globalFlags,
|
|
28
|
+
yes: {
|
|
29
|
+
kind: "boolean",
|
|
30
|
+
brief: "Overwrite the output file without prompting",
|
|
31
|
+
default: false,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
loader: () => import("./env.impl.js").then((m) => m.pullEnv),
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
});
|
package/src/cli/config.ts
CHANGED
|
@@ -142,21 +142,23 @@ export class Config {
|
|
|
142
142
|
configFile.workerId = opts.flags["worker-id"];
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
configFile.baseUrl ??= baseUrl(configFile.environment ?? "prod");
|
|
146
|
+
|
|
145
147
|
return new Config({
|
|
146
148
|
configFilePath: absConfigFilePath,
|
|
147
|
-
configFile,
|
|
149
|
+
configFile: configFile as ConfigMap,
|
|
148
150
|
});
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
static async #readConfigFile(configFilePath: string) {
|
|
152
|
-
let configFile: ConfigMap
|
|
154
|
+
let configFile: Partial<ConfigMap>;
|
|
153
155
|
try {
|
|
154
156
|
const configContents = await fs.promises.readFile(
|
|
155
157
|
configFilePath,
|
|
156
158
|
"utf-8",
|
|
157
159
|
);
|
|
158
160
|
|
|
159
|
-
configFile = JSON.parse(configContents) as ConfigMap
|
|
161
|
+
configFile = JSON.parse(configContents) as Partial<ConfigMap>;
|
|
160
162
|
} catch (error) {
|
|
161
163
|
if (isENOENT(error)) {
|
|
162
164
|
// The default, non-logged in configuration before overrides are
|
package/src/cli/routes.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { bundleCommands } from "./commands/bundle.js";
|
|
|
5
5
|
import { capabilitiesCommands } from "./commands/capabilities.js";
|
|
6
6
|
import { connectCommands } from "./commands/connect.js";
|
|
7
7
|
import deploy from "./commands/deploy.js";
|
|
8
|
+
import { envCommands } from "./commands/env.js";
|
|
8
9
|
import exec from "./commands/exec.js";
|
|
9
10
|
import { runsCommands } from "./commands/runs.js";
|
|
10
11
|
import { secretsCommands } from "./commands/secrets.js";
|
|
@@ -34,6 +35,7 @@ variables can also be provided:
|
|
|
34
35
|
deploy: deploy,
|
|
35
36
|
exec: exec,
|
|
36
37
|
connect: connectCommands,
|
|
38
|
+
env: envCommands,
|
|
37
39
|
runs: runsCommands,
|
|
38
40
|
secrets: secretsCommands,
|
|
39
41
|
bundle: bundleCommands,
|