Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ export function createTrpcClient(debug: boolean, deployUrl: string) {
errorLink,
retryLink({
retry({ error: err }) {
if (
!(err?.data?.code !== "NOT_AUTHENTICATED" &&
err?.data?.code !== "TOKEN_EXPIRED")
) {
const code = err?.data?.code;
if (!(code === "NOT_AUTHENTICATED" || code === "TOKEN_EXPIRED")) {
return false;
}

Expand Down
13 changes: 7 additions & 6 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"imports": {
"@cfa/gitignore-parser": "jsr:@cfa/gitignore-parser@^0.1.4",
"@cliffy/command": "jsr:@cliffy/command@^1.0.0-rc.8",
"@std/cli": "jsr:@std/cli@1.0.21",
"@std/cli": "jsr:@std/cli@1.0.22",
"@std/dotenv": "jsr:@std/dotenv@^0.225.5",
"@std/encoding": "jsr:@std/encoding@^1.0.8",
"@std/encoding": "jsr:@std/encoding@^1.0.10",
"@std/fmt": "jsr:@std/fmt@^1.0.8",
"@std/fs": "jsr:@std/fs@^1.0.14",
"@std/jsonc": "jsr:@std/jsonc@^1.0.1",
"@std/path": "jsr:@std/path@^1.0.8",
"@std/fs": "jsr:@std/fs@^1.0.19",
"@std/jsonc": "jsr:@std/jsonc@^1.0.2",
"@std/path": "jsr:@std/path@^1.1.2",
"@std/semver": "jsr:@std/semver@^1.0.5",
"@std/tar": "jsr:@std/tar@^0.1.8",
"@trpc/client": "npm:@trpc/client@^11.0.2",
Expand All @@ -35,7 +35,8 @@
"prompts": "npm:prompts@2.4.2",
"superjson": "npm:superjson@^2.2.2",
"@deno/framework-detect": "jsr:@deno/framework-detect@^0",
"temporal-polyfill": "npm:temporal-polyfill@^0.3.0"
"temporal-polyfill": "npm:temporal-polyfill@^0.3.0",
"prompts": "npm:prompts@2.4.2"
},
"exclude": [
"astro-demo"
Expand Down
70 changes: 5 additions & 65 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 65 additions & 8 deletions env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface EnvVar {
id: string;
key: string;
value: string;
is_secret: boolean;
context_ids: string[];
}

Expand Down Expand Up @@ -346,17 +347,73 @@ export const envLoadCommand = new Command<EnvCommandContext>()

const variables = dotEnvParse(await Deno.readTextFile(file));

// deno-lint-ignore no-explicit-any
const existingEnvVars: EnvVar[] = await (trpcClient.envVarsContexts as any)
.list
.query({
org: orgAndApp.org,
app: orgAndApp.app,
});

const addEnvVars = [];
let updateEnvVars = [];

for (const [key, value] of Object.entries(variables)) {
const existing = existingEnvVars.find((envVar) => envVar.key === key);
if (existing) {
updateEnvVars.push({
id: existing.id,
key,
value,
is_secret: options.secrets?.includes(key) ?? existing.is_secret,
context_ids: existing.context_ids,
});
} else {
addEnvVars.push({
app_id: fullApp.id,
key,
value,
is_secret: options.secrets?.includes(key) ?? false,
context_ids: null,
});
}
}

if (updateEnvVars.length > 0) {
console.log("The following env vars are already defined:");
for (const updateEnvVar of updateEnvVars) {
console.log(` - ${updateEnvVar.key}`);
}
console.log();
outer: while (true) {
const res = prompt(
"Would you like to replace these with your .env file? [y = Yes, n = No, s = Ignore/Skip]",
);
if (res) {
switch (res.toLowerCase()) {
case "y": {
break outer;
}

// deno-lint-ignore no-fallthrough
case "n": {
error(options.debug, "Env vars are already defined, exiting");
}
case "s": {
updateEnvVars = [];
break outer;
}
}
}
}
console.log();
}

// deno-lint-ignore no-explicit-any
await (trpcClient.envVarsContexts as any).updateEnvVars.mutate({
org: orgAndApp.org,
add: Object.entries(variables).map(([key, value]) => ({
app_id: fullApp.id,
key,
value,
is_secret: options.secrets?.includes(key) ?? false,
context_ids: null,
})),
update: [],
add: addEnvVars,
update: updateEnvVars,
remove: [],
});

Expand Down