Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
27 changes: 18 additions & 9 deletions auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "@trpc/client";
import { observable } from "@trpc/server/observable";
import { Spinner } from "@std/cli/unstable-spinner";
import { error } from "./util.ts";
import { error, isInteractive } from "./util.ts";
import { EventSourcePolyfill } from "event-source-polyfill";
import type { GlobalContext } from "./main.ts";

Expand Down Expand Up @@ -180,15 +180,25 @@ export async function getAuth(
return storedAuth;
}

if (!isInteractive()) {
error(
context,
"Authentication required but stdin is not a terminal.\nSet the DENO_DEPLOY_TOKEN environment variable or use --token.",
);
}
Comment thread
crowlKats marked this conversation as resolved.
Outdated

const { code, exchangeToken, verifier } = await interactive(context);

const authUrl = `${context.endpoint}/auth?code=${code}`;

const spinner = new Spinner({
message: `Visit ${authUrl} to authorize deploying your project.`,
message: "",
color: "yellow",
});
spinner.start();
console.log(`Visit ${authUrl} to authorize deploying your project.`);
if (!quiet) {
spinner.start();
}

await open(authUrl);

Expand All @@ -215,12 +225,11 @@ export async function interactive(context: GlobalContext): Promise<
});

if (!res.ok) {
console.error("An error occurred during authentication, exiting...");
if (context.debug) {
console.log(res);
console.log(await res.json());
}
Deno.exit(1);
error(
context,
"An error occurred during authentication, exiting...",
res,
);
}

const body = await res.json();
Expand Down
13 changes: 10 additions & 3 deletions config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTrpcClient, getAuth } from "./auth.ts";
import type { GlobalContext } from "./main.ts";
import { error } from "./util.ts";
import { error, requireInteractive } from "./util.ts";
import {
type PromptEntry,
promptSelect,
Expand Down Expand Up @@ -42,6 +42,10 @@ export async function getOrg(
} else if (orgs.length === 1) {
org = orgs[0].slug;
} else {
requireInteractive(
context,
"Use --org to specify the organization.",
);
const selectedOrg = promptSelect(
"Select an organization:",
orgs.map((org) => ({ label: `${org.name} (${org.slug})`, value: org })),
Expand Down Expand Up @@ -109,6 +113,10 @@ export async function getApp(
name: string;
slug: string;
}>;
requireInteractive(
context,
"Use --app to specify the application.",
);
const appStrings: PromptEntry<{ name: string; slug: string } | null>[] =
apps.map((app) => ({ label: app.slug, value: app }));
if (canCreate) {
Expand All @@ -118,8 +126,7 @@ export async function getApp(
clear: true,
});
if (!selectedApp) {
console.error("No application was selected.");
Deno.exit(1);
error(context, "No application was selected.");
}

if (selectedApp.value === null) {
Expand Down
118 changes: 114 additions & 4 deletions deno.lock

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

5 changes: 5 additions & 0 deletions deploy/create/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from "@deno/framework-detect";
import type { GlobalContext } from "../../main.ts";
import type { CreateApp, Repo } from "./mod.ts";
import { requireInteractive } from "../../util.ts";

export const AVAILABLE_BUILD_TIMEOUTS = [5, 10, 15, 20, 25, 30];
export const AVAILABLE_BUILD_MEMORY_LIMITS = [1024, 2048, 3072, 4096];
Expand Down Expand Up @@ -63,6 +64,10 @@ export async function createFlow(
rootPath: string,
preselectedOrg?: string,
): Promise<CreateApp> {
requireInteractive(
context,
"Use explicit flags (--org, --app, --source, etc.) to create an app non-interactively.",
);
const trpcClient = createTrpcClient(context);

let org;
Expand Down
7 changes: 5 additions & 2 deletions deploy/create/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { publish, waitForRevision } from "../publish.ts";
import { resolve } from "@std/path";
import { error } from "../../util.ts";
import { green } from "@std/fmt/colors";

export const createCommand = new Command<GlobalContext>()
.description(
Expand Down Expand Up @@ -238,7 +239,7 @@ export const createCommand = new Command<GlobalContext>()
buildDirectory = member?.path ??
required(options.appDirectory, "app-directory");
} else {
buildDirectory = options.appDirectory || "/";
buildDirectory = options.appDirectory || "";
}

let buildConfig;
Expand Down Expand Up @@ -399,7 +400,9 @@ export async function createApp(
});

console.log(
`Created app, view it at ${context.endpoint}/${data.org}/${data.app}`,
`${
green("✔")
} Created app, view it at ${context.endpoint}/${data.org}/${data.app}`,
);

if (data.repo === undefined) {
Expand Down
Loading
Loading