Skip to content

Commit 27957b3

Browse files
authored
Svn main 001 rem (#6489)
* Change name from stack to backend * Change name from stack to backend * changed file names * changed file names in experiments * changed name * lower case backend * Changed stack to backend * change stack to backend in index file * List stacks in table * Backends for project message * resolve merge conflicts * removed linter errors * changed table head color to green * test method stack to backend * Changed stack to backend (#6488) * Changed stack to backend * change stack to backend in index file * List stacks in table * Backends for project message * Changed file names * removed linter errors * change file names from stack to backend * changed table head color to green * test method stack to backend * changed file name
1 parent c5c872c commit 27957b3

File tree

8 files changed

+109
-83
lines changed

8 files changed

+109
-83
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Command } from "../command";
2+
import { Options } from "../options";
3+
import { needProjectId } from "../projectUtils";
4+
import * as gcp from "../gcp/frameworks";
5+
import { FirebaseError } from "../error";
6+
import { logger } from "../logger";
7+
const Table = require("cli-table");
8+
9+
export const command = new Command("backends:get")
10+
.description("Get backend details of a Firebase project")
11+
.option("-l, --location <location>", "App Backend location", "us-central1")
12+
.option("--s, --backendId <backendId>", "Backend Id", "")
13+
.action(async (options: Options) => {
14+
const projectId = needProjectId(options);
15+
const location = options.location as string;
16+
const backendId = options.backendId as string;
17+
if (!backendId) {
18+
throw new FirebaseError("Backend id can't be empty.");
19+
}
20+
21+
let backend;
22+
try {
23+
backend = await gcp.getBackend(projectId, location, backendId);
24+
const table = new Table({
25+
head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"],
26+
style: { head: ["green"] },
27+
});
28+
table.push([
29+
backend.name,
30+
backend.codebase.repository,
31+
backend.uri,
32+
backend.createTime,
33+
backend.updateTime,
34+
]);
35+
logger.info(table.toString());
36+
} catch (err: any) {
37+
throw new FirebaseError(
38+
`Failed to get backend: ${backendId}. Please check the parameters you have provided.`,
39+
{ original: err }
40+
);
41+
}
42+
43+
return backend;
44+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Command } from "../command";
2+
import { Options } from "../options";
3+
import { needProjectId } from "../projectUtils";
4+
import * as gcp from "../gcp/frameworks";
5+
import { FirebaseError } from "../error";
6+
import { logger } from "../logger";
7+
import { bold } from "colorette";
8+
const Table = require("cli-table");
9+
10+
export const command = new Command("backends:list")
11+
.description("List backends of a Firebase project.")
12+
.option("-l, --location <location>", "App Backend location", "us-central1")
13+
.action(async (options: Options) => {
14+
const projectId = needProjectId(options);
15+
const location = options.location as string;
16+
const table = new Table({
17+
head: ["Backend Id", "Repository Name", "URL", "Location", "Created Date", "Updated Date"],
18+
style: { head: ["green"] },
19+
});
20+
21+
let backendsList;
22+
try {
23+
backendsList = await gcp.listBackends(projectId, location);
24+
for (const backend of backendsList.backends) {
25+
const entry = [
26+
backend.name,
27+
backend.codebase.repository,
28+
backend.uri,
29+
backend.createTime,
30+
backend.updateTime,
31+
];
32+
table.push(entry);
33+
}
34+
logger.info(`Backends for project ${bold(projectId)}`);
35+
logger.info(table.toString());
36+
} catch (err: any) {
37+
throw new FirebaseError(
38+
`Unable to list backends present in project: ${projectId}. Please check the parameters you have provided.`,
39+
{ original: err }
40+
);
41+
}
42+
43+
return backendsList;
44+
});

src/commands/frameworks-stacks-get.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/commands/frameworks-stacks-list.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/commands/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ export function load(client: any): any {
153153
}
154154
if (experiments.isEnabled("internalframeworks")) {
155155
client.frameworks = {};
156-
client.frameworks.stacks = {};
157-
client.frameworks.stacks.list = loadCommand("frameworks-stacks-list");
158-
client.frameworks.stacks.create = loadCommand("frameworks-backends-create");
159-
client.frameworks.stacks.create = loadCommand("frameworks-stacks-get");
160-
client.frameworks.stacks.create = loadCommand("frameworks-backends-delete");
156+
client.frameworks.backends = {};
157+
client.frameworks.backends.list = loadCommand("frameworks-backends-list");
158+
client.frameworks.backends.create = loadCommand("frameworks-backends-create");
159+
client.frameworks.backends.get = loadCommand("frameworks-backends-get");
160+
client.frameworks.backends.delete = loadCommand("frameworks-backends-delete");
161161
}
162162
client.login = loadCommand("login");
163163
client.login.add = loadCommand("login-add");

src/gcp/frameworks.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ export interface Operation {
8181
// end oneof result
8282
}
8383

84-
export interface ListStacksResponse {
85-
stacks: Stack[];
84+
export interface ListBackendsResponse {
85+
backends: Stack[];
8686
}
8787

8888
/**
@@ -104,25 +104,28 @@ export async function createStack(
104104
}
105105

106106
/**
107-
* Gets stack details.
107+
* Gets backend details.
108108
*/
109-
export async function getStack(
109+
export async function getBackend(
110110
projectId: string,
111111
location: string,
112-
stackId: string
112+
backendId: string
113113
): Promise<Stack> {
114-
const name = `projects/${projectId}/locations/${location}/backends/${stackId}`;
114+
const name = `projects/${projectId}/locations/${location}/backends/${backendId}`;
115115
const res = await client.get<Stack>(name);
116116

117117
return res.body;
118118
}
119119

120120
/**
121-
* List all stacks present in a project and region.
121+
* List all backends present in a project and region.
122122
*/
123-
export async function listStack(projectId: string, location: string): Promise<ListStacksResponse> {
123+
export async function listBackends(
124+
projectId: string,
125+
location: string
126+
): Promise<ListBackendsResponse> {
124127
const name = `projects/${projectId}/locations/${location}/backends`;
125-
const res = await client.get<ListStacksResponse>(name);
128+
const res = await client.get<ListBackendsResponse>(name);
126129

127130
return res.body;
128131
}

src/init/features/frameworks/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export async function getOrCreateStack(projectId: string, setup: any): Promise<S
113113
}
114114

115115
async function getExistingStack(projectId: string, setup: any, location: string): Promise<Stack> {
116-
let stack = await gcp.getStack(projectId, location, setup.frameworks.serviceName);
116+
let stack = await gcp.getBackend(projectId, location, setup.frameworks.serviceName);
117117
while (stack) {
118118
setup.frameworks.serviceName = undefined;
119119
await promptOnce(
@@ -139,7 +139,7 @@ async function getExistingStack(projectId: string, setup: any, location: string)
139139
},
140140
setup.frameworks
141141
);
142-
stack = await gcp.getStack(projectId, location, setup.frameworks.serviceName);
142+
stack = await gcp.getBackend(projectId, location, setup.frameworks.serviceName);
143143
setup.frameworks.existingStack = undefined;
144144
}
145145

src/test/init/frameworks/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ describe("operationsConverter", () => {
2020
.stub(poller, "pollOperation")
2121
.throws("Unexpected pollOperation call");
2222
createStackStub = sandbox.stub(gcp, "createStack").throws("Unexpected createStack call");
23-
getStackStub = sandbox.stub(gcp, "getStack").throws("Unexpected getStack call");
23+
getStackStub = sandbox.stub(gcp, "getBackend").throws("Unexpected getBackend call");
2424
linkGitHubRepositoryStub = sandbox
2525
.stub(repo, "linkGitHubRepository")
26-
.throws("Unexpected getStack call");
26+
.throws("Unexpected getBackend call");
2727
});
2828

2929
afterEach(() => {

0 commit comments

Comments
 (0)