From b746c2b6c894db1791629b77c4a08de30333650c Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 1 Nov 2023 15:32:24 +0000 Subject: [PATCH 01/10] Changed stack to backend --- src/commands/frameworks-stacks-get.ts | 37 ++++++++++++++++---------- src/commands/frameworks-stacks-list.ts | 14 +++++----- src/gcp/frameworks.ts | 12 ++++----- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-stacks-get.ts index 91059921654..4c6a25e166e 100644 --- a/src/commands/frameworks-stacks-get.ts +++ b/src/commands/frameworks-stacks-get.ts @@ -4,32 +4,41 @@ import { needProjectId } from "../projectUtils"; import * as gcp from "../gcp/frameworks"; import { FirebaseError } from "../error"; import { logger } from "../logger"; +const Table = require("cli-table"); -export const command = new Command("stacks:get") - .description("Get stack details of a Firebase project") +export const command = new Command("backends:get") + .description("Get backend details of a Firebase project") .option("-l, --location ", "App Backend location", "us-central1") - .option("--s, --stackId ", "Stack Id", "") + .option("--s, --backendId ", "Backend Id", "") .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; - const stackId = options.stackId as string; - if (!stackId) { - throw new FirebaseError("Stack id can't be empty."); + const backendId = options.backendId as string; + if (!backendId) { + throw new FirebaseError("Backend id can't be empty."); } - let stack; + let backend; try { - stack = await gcp.getStack(projectId, location, stackId); - /** - * TODO print this in a prettier way. - */ - logger.info(stack); + backend = await gcp.getBackend(projectId, location, backendId); + const table = new Table({ + head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"], + style: { head: ["yellow"] }, + }); + table.push([ + backend.name, + backend.codebase.repository, + backend.uri, + backend.createTime, + backend.updateTime, + ]); + logger.info(table.toString()); } catch (err: any) { throw new FirebaseError( - `Failed to get stack: ${stackId}. Please check the parameters you have provided.`, + `Failed to get backend: ${backendId}. Please check the parameters you have provided.`, { original: err } ); } - return stack; + return backend; }); diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index 61ccd6bbb16..1c0d2016d1b 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -5,26 +5,26 @@ import * as gcp from "../gcp/frameworks"; import { FirebaseError } from "../error"; import { logger } from "../logger"; -export const command = new Command("stacks:list") - .description("List stacks of a Firebase project.") +export const command = new Command("backends:list") + .description("List backends of a Firebase project.") .option("-l, --location ", "App Backend location", "us-central1") .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; - let stacks; + let backends; try { - stacks = await gcp.listStack(projectId, location); + backends = await gcp.listBackend(projectId, location); /** * TODO print this in a prettier way. */ - logger.info(stacks); + logger.info(backends); } catch (err: any) { throw new FirebaseError( - `Unable to list stacks present in project: ${projectId}. Please check the parameters you have provided.`, + `Unable to list backends present in project: ${projectId}. Please check the parameters you have provided.`, { original: err } ); } - return stacks; + return backends; }); diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index 1523ba36cba..66324fcc72f 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -104,23 +104,23 @@ export async function createStack( } /** - * Gets stack details. + * Gets backend details. */ -export async function getStack( +export async function getBackend( projectId: string, location: string, - stackId: string + backendId: string ): Promise { - const name = `projects/${projectId}/locations/${location}/backends/${stackId}`; + const name = `projects/${projectId}/locations/${location}/backends/${backendId}`; const res = await client.get(name); return res.body; } /** - * List all stacks present in a project and region. + * List all backends present in a project and region. */ -export async function listStack(projectId: string, location: string): Promise { +export async function listBackend(projectId: string, location: string): Promise { const name = `projects/${projectId}/locations/${location}/backends`; const res = await client.get(name); From d6a699e4fc3404319b56360912004ebc7cd48e37 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 1 Nov 2023 16:09:29 +0000 Subject: [PATCH 02/10] change stack to backend in index file --- src/init/features/frameworks/index.ts | 4 ++-- src/test/init/frameworks/index.spec.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/init/features/frameworks/index.ts b/src/init/features/frameworks/index.ts index 52be59193d6..f92b7054290 100644 --- a/src/init/features/frameworks/index.ts +++ b/src/init/features/frameworks/index.ts @@ -113,7 +113,7 @@ export async function getOrCreateStack(projectId: string, setup: any): Promise { - let stack = await gcp.getStack(projectId, location, setup.frameworks.serviceName); + let stack = await gcp.getBackend(projectId, location, setup.frameworks.serviceName); while (stack) { setup.frameworks.serviceName = undefined; await promptOnce( @@ -139,7 +139,7 @@ async function getExistingStack(projectId: string, setup: any, location: string) }, setup.frameworks ); - stack = await gcp.getStack(projectId, location, setup.frameworks.serviceName); + stack = await gcp.getBackend(projectId, location, setup.frameworks.serviceName); setup.frameworks.existingStack = undefined; } diff --git a/src/test/init/frameworks/index.spec.ts b/src/test/init/frameworks/index.spec.ts index 28ea17f0fd3..e01197c3393 100644 --- a/src/test/init/frameworks/index.spec.ts +++ b/src/test/init/frameworks/index.spec.ts @@ -20,7 +20,7 @@ describe("operationsConverter", () => { .stub(poller, "pollOperation") .throws("Unexpected pollOperation call"); createStackStub = sandbox.stub(gcp, "createStack").throws("Unexpected createStack call"); - getStackStub = sandbox.stub(gcp, "getStack").throws("Unexpected getStack call"); + getStackStub = sandbox.stub(gcp, "getBackend").throws("Unexpected getStack call"); linkGitHubRepositoryStub = sandbox .stub(repo, "linkGitHubRepository") .throws("Unexpected getStack call"); From 7a0d1298691c53c850bb75f4a4fab96fd0c5607d Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 1 Nov 2023 16:13:17 +0000 Subject: [PATCH 03/10] List stacks in table --- src/commands/frameworks-stacks-list.ts | 26 +++++++++++++++++++------- src/gcp/frameworks.ts | 8 ++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index 1c0d2016d1b..866ad625f01 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -4,6 +4,7 @@ import { needProjectId } from "../projectUtils"; import * as gcp from "../gcp/frameworks"; import { FirebaseError } from "../error"; import { logger } from "../logger"; +const Table = require("cli-table"); export const command = new Command("backends:list") .description("List backends of a Firebase project.") @@ -11,14 +12,25 @@ export const command = new Command("backends:list") .action(async (options: Options) => { const projectId = needProjectId(options); const location = options.location as string; + const table = new Table({ + head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"], + style: { head: ["yellow"] }, + }); - let backends; + let backendsList; try { - backends = await gcp.listBackend(projectId, location); - /** - * TODO print this in a prettier way. - */ - logger.info(backends); + backendsList = await gcp.listBackend(projectId, location); + for (const backend of backendsList.backends) { + const entry = [ + backend.name, + backend.codebase.repository, + backend.uri, + backend.createTime, + backend.updateTime, + ]; + table.push(entry); + } + logger.info(table.toString()); } catch (err: any) { throw new FirebaseError( `Unable to list backends present in project: ${projectId}. Please check the parameters you have provided.`, @@ -26,5 +38,5 @@ export const command = new Command("backends:list") ); } - return backends; + return backendsList; }); diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index 66324fcc72f..83a13b3af22 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -81,8 +81,8 @@ export interface Operation { // end oneof result } -export interface ListStacksResponse { - stacks: Stack[]; +export interface ListBackendsResponse { + backends: Stack[]; } /** @@ -120,9 +120,9 @@ export async function getBackend( /** * List all backends present in a project and region. */ -export async function listBackend(projectId: string, location: string): Promise { +export async function listBackend(projectId: string, location: string): Promise { const name = `projects/${projectId}/locations/${location}/backends`; - const res = await client.get(name); + const res = await client.get(name); return res.body; } From 8589d07be6f4415118216b5238a35e73b5fb915a Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 1 Nov 2023 16:24:28 +0000 Subject: [PATCH 04/10] Backends for project message --- src/commands/frameworks-stacks-list.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-stacks-list.ts index 866ad625f01..2baf824dbc3 100644 --- a/src/commands/frameworks-stacks-list.ts +++ b/src/commands/frameworks-stacks-list.ts @@ -4,6 +4,7 @@ import { needProjectId } from "../projectUtils"; import * as gcp from "../gcp/frameworks"; import { FirebaseError } from "../error"; import { logger } from "../logger"; +import { bold } from "colorette"; const Table = require("cli-table"); export const command = new Command("backends:list") @@ -30,6 +31,7 @@ export const command = new Command("backends:list") ]; table.push(entry); } + logger.info(`Backends for project ${bold(projectId)}`); logger.info(table.toString()); } catch (err: any) { throw new FirebaseError( From 7ead0b7672c0cab523e1ace44172cad976328aaf Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 1 Nov 2023 16:29:09 +0000 Subject: [PATCH 05/10] Changed file names --- .../{frameworks-stacks-get.ts => frameworks-backend-get.ts} | 0 .../{frameworks-stacks-list.ts => frameworks-backend-list.ts} | 0 src/commands/index.ts | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename src/commands/{frameworks-stacks-get.ts => frameworks-backend-get.ts} (100%) rename src/commands/{frameworks-stacks-list.ts => frameworks-backend-list.ts} (100%) diff --git a/src/commands/frameworks-stacks-get.ts b/src/commands/frameworks-backend-get.ts similarity index 100% rename from src/commands/frameworks-stacks-get.ts rename to src/commands/frameworks-backend-get.ts diff --git a/src/commands/frameworks-stacks-list.ts b/src/commands/frameworks-backend-list.ts similarity index 100% rename from src/commands/frameworks-stacks-list.ts rename to src/commands/frameworks-backend-list.ts diff --git a/src/commands/index.ts b/src/commands/index.ts index 4814d4f66fe..add413ae21e 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -154,9 +154,9 @@ export function load(client: any): any { if (experiments.isEnabled("internalframeworks")) { client.frameworks = {}; client.frameworks.stacks = {}; - client.frameworks.stacks.list = loadCommand("frameworks-stacks-list"); + client.frameworks.stacks.list = loadCommand("frameworks-backends-list"); client.frameworks.stacks.create = loadCommand("frameworks-stacks-create"); - client.frameworks.stacks.create = loadCommand("frameworks-stacks-get"); + client.frameworks.stacks.create = loadCommand("frameworks-backends-get"); client.frameworks.stacks.create = loadCommand("frameworks-stacks-delete"); } client.login = loadCommand("login"); From fb62bf581ed0b5fd37c0db3faf804381dec6cdac Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 1 Nov 2023 19:13:03 +0000 Subject: [PATCH 06/10] removed linter errors --- src/gcp/frameworks.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index 83a13b3af22..c872880994f 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -120,7 +120,10 @@ export async function getBackend( /** * List all backends present in a project and region. */ -export async function listBackend(projectId: string, location: string): Promise { +export async function listBackend( + projectId: string, + location: string +): Promise { const name = `projects/${projectId}/locations/${location}/backends`; const res = await client.get(name); From cc6eb0916ab0b1f3dade4829fae03b9520407445 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 1 Nov 2023 19:18:24 +0000 Subject: [PATCH 07/10] change file names from stack to backend --- src/commands/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commands/index.ts b/src/commands/index.ts index add413ae21e..90e12e99ea2 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -153,11 +153,11 @@ export function load(client: any): any { } if (experiments.isEnabled("internalframeworks")) { client.frameworks = {}; - client.frameworks.stacks = {}; - client.frameworks.stacks.list = loadCommand("frameworks-backends-list"); - client.frameworks.stacks.create = loadCommand("frameworks-stacks-create"); - client.frameworks.stacks.create = loadCommand("frameworks-backends-get"); - client.frameworks.stacks.create = loadCommand("frameworks-stacks-delete"); + client.frameworks.backends = {}; + client.frameworks.backends.list = loadCommand("frameworks-backends-list"); + client.frameworks.backends.create = loadCommand("frameworks-stacks-create"); + client.frameworks.backends.create = loadCommand("frameworks-backends-get"); + client.frameworks.backends.create = loadCommand("frameworks-stacks-delete"); } client.login = loadCommand("login"); client.login.add = loadCommand("login-add"); From 9880240a418ae39b8c98a8b1fba45df81e6cd525 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 1 Nov 2023 19:26:15 +0000 Subject: [PATCH 08/10] changed table head color to green --- src/commands/frameworks-backend-get.ts | 2 +- src/commands/frameworks-backend-list.ts | 4 ++-- src/gcp/frameworks.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/frameworks-backend-get.ts b/src/commands/frameworks-backend-get.ts index 4c6a25e166e..f7a79359a33 100644 --- a/src/commands/frameworks-backend-get.ts +++ b/src/commands/frameworks-backend-get.ts @@ -23,7 +23,7 @@ export const command = new Command("backends:get") backend = await gcp.getBackend(projectId, location, backendId); const table = new Table({ head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"], - style: { head: ["yellow"] }, + style: { head: ["green"] }, }); table.push([ backend.name, diff --git a/src/commands/frameworks-backend-list.ts b/src/commands/frameworks-backend-list.ts index 2baf824dbc3..c5f72961888 100644 --- a/src/commands/frameworks-backend-list.ts +++ b/src/commands/frameworks-backend-list.ts @@ -15,12 +15,12 @@ export const command = new Command("backends:list") const location = options.location as string; const table = new Table({ head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"], - style: { head: ["yellow"] }, + style: { head: ["green"] }, }); let backendsList; try { - backendsList = await gcp.listBackend(projectId, location); + backendsList = await gcp.listBackends(projectId, location); for (const backend of backendsList.backends) { const entry = [ backend.name, diff --git a/src/gcp/frameworks.ts b/src/gcp/frameworks.ts index c872880994f..a005c2d39a0 100644 --- a/src/gcp/frameworks.ts +++ b/src/gcp/frameworks.ts @@ -120,7 +120,7 @@ export async function getBackend( /** * List all backends present in a project and region. */ -export async function listBackend( +export async function listBackends( projectId: string, location: string ): Promise { From d110c0b0a1a6958bc808c44403aeeca304bd9ea2 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 1 Nov 2023 19:32:01 +0000 Subject: [PATCH 09/10] test method stack to backend --- src/test/init/frameworks/index.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/init/frameworks/index.spec.ts b/src/test/init/frameworks/index.spec.ts index e01197c3393..01096de69cd 100644 --- a/src/test/init/frameworks/index.spec.ts +++ b/src/test/init/frameworks/index.spec.ts @@ -20,10 +20,10 @@ describe("operationsConverter", () => { .stub(poller, "pollOperation") .throws("Unexpected pollOperation call"); createStackStub = sandbox.stub(gcp, "createStack").throws("Unexpected createStack call"); - getStackStub = sandbox.stub(gcp, "getBackend").throws("Unexpected getStack call"); + getStackStub = sandbox.stub(gcp, "getBackend").throws("Unexpected getBackend call"); linkGitHubRepositoryStub = sandbox .stub(repo, "linkGitHubRepository") - .throws("Unexpected getStack call"); + .throws("Unexpected getBackend call"); }); afterEach(() => { From cb7b816d152a8bdd3cf1259244ddbcae4229fec4 Mon Sep 17 00:00:00 2001 From: Sairam Sakhamuri Date: Wed, 1 Nov 2023 21:01:09 +0000 Subject: [PATCH 10/10] changed file name --- .../{frameworks-backend-get.ts => frameworks-backends-get.ts} | 0 .../{frameworks-backend-list.ts => frameworks-backends-list.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/commands/{frameworks-backend-get.ts => frameworks-backends-get.ts} (100%) rename src/commands/{frameworks-backend-list.ts => frameworks-backends-list.ts} (100%) diff --git a/src/commands/frameworks-backend-get.ts b/src/commands/frameworks-backends-get.ts similarity index 100% rename from src/commands/frameworks-backend-get.ts rename to src/commands/frameworks-backends-get.ts diff --git a/src/commands/frameworks-backend-list.ts b/src/commands/frameworks-backends-list.ts similarity index 100% rename from src/commands/frameworks-backend-list.ts rename to src/commands/frameworks-backends-list.ts