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
2 changes: 2 additions & 0 deletions src/commands/frameworks-backends-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import requireInteractive from "../requireInteractive";
import { doSetup } from "../init/features/frameworks";
import { ensureApiEnabled } from "../gcp/frameworks";

export const command = new Command("backends:create")
.description("Create a backend in a Firebase project")
.before(ensureApiEnabled)
.before(requireInteractive)
.action(async (options: Options) => {
const projectId = needProjectId(options);
Expand Down
3 changes: 3 additions & 0 deletions src/commands/frameworks-backends-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { promptOnce } from "../prompt";
import * as utils from "../utils";
import { logger } from "../logger";
import { DEFAULT_REGION, ALLOWED_REGIONS } from "../init/features/frameworks/constants";
import { ensureApiEnabled } from "../gcp/frameworks";

const Table = require("cli-table");

const COLUMN_LENGTH = 20;
Expand All @@ -24,6 +26,7 @@ export const command = new Command("backends:delete")
.option("-l, --location <location>", "App Backend location", "")
.option("-s, --backend <backend>", "Backend Id", "")
.withForce()
.before(ensureApiEnabled)
.action(async (options: Options) => {
const projectId = needProjectId(options);
let location = options.location as string;
Expand Down
3 changes: 3 additions & 0 deletions src/commands/frameworks-backends-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { needProjectId } from "../projectUtils";
import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { ensureApiEnabled } from "../gcp/frameworks";

const Table = require("cli-table");
const COLUMN_LENGTH = 20;
const TABLE_HEAD = [
Expand All @@ -18,6 +20,7 @@ export const command = new Command("backends:get")
.description("Get backend details of a Firebase project")
.option("-l, --location <location>", "App Backend location", "-")
.option("-b, --backend <backend>", "Backend Id", "")
.before(ensureApiEnabled)
.action(async (options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
Expand Down
2 changes: 2 additions & 0 deletions src/commands/frameworks-backends-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import * as gcp from "../gcp/frameworks";
import { FirebaseError } from "../error";
import { logger } from "../logger";
import { bold } from "colorette";
import { ensureApiEnabled } from "../gcp/frameworks";

const Table = require("cli-table");
const COLUMN_LENGTH = 20;
const TABLE_HEAD = ["Backend Id", "Repository", "Location", "URL", "Created Date", "Updated Date"];
export const command = new Command("backends:list")
.description("List backends of a Firebase project.")
.option("-l, --location <location>", "App Backend location", "-")
.before(ensureApiEnabled)
.action(async (options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
Expand Down
11 changes: 11 additions & 0 deletions src/gcp/frameworks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Client } from "../apiv2";
import { needProjectId } from "../projectUtils";
import { frameworksOrigin } from "../api";
import { ensure } from "../ensureApiEnabled";

export const API_HOST = new URL(frameworksOrigin).host;
export const API_VERSION = "v1alpha";

const client = new Client({
Expand Down Expand Up @@ -162,3 +165,11 @@ export async function createBuild(

return res.body;
}

/**
* Ensure that Frameworks API is enabled on the project.
*/
export async function ensureApiEnabled(options: any): Promise<void> {
const projectId = needProjectId(options);
return await ensure(projectId, API_HOST, "frameworks", true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong but didn't we want to ensure all of the dependent APIs as well (in case the user manually toggles any of them off?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah let me tackle that problem in the follow up PR.

}