Skip to content

Commit 1ab38ca

Browse files
authored
Merge branch 'master' into lazy-load-commands
2 parents d5f256f + 2913444 commit 1ab38ca

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/commands/functions-list.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
11
import { Command } from "../command";
22
import * as args from "../deploy/functions/args";
33
import { needProjectId } from "../projectUtils";
4-
import { Options } from "../options";
54
import { requirePermissions } from "../requirePermissions";
65
import * as backend from "../deploy/functions/backend";
76
import { logger } from "../logger";
87
import * as Table from "cli-table3";
8+
import { Options } from "../options";
9+
import { FunctionsPlatform } from "../deploy/functions/backend";
10+
11+
type PLATFORM_DISPLAY_NAME = "v1" | "v2" | "run";
12+
const PLATFORM_TO_DISPLAY_NAME: Record<FunctionsPlatform, PLATFORM_DISPLAY_NAME> = {
13+
gcfv1: "v1",
14+
gcfv2: "v2",
15+
run: "run",
16+
};
917

1018
export const command = new Command("functions:list")
1119
.description("list all deployed functions in your Firebase project")
12-
.before(requirePermissions, ["cloudfunctions.functions.list"])
20+
.before(requirePermissions, ["cloudfunctions.functions.list", "run.services.list"])
1321
.action(async (options: Options) => {
22+
const projectId = needProjectId(options);
1423
const context = {
15-
projectId: needProjectId(options),
24+
projectId,
1625
} as args.Context;
26+
1727
const existing = await backend.existingBackend(context);
18-
const endpointsList = backend.allEndpoints(existing).sort(backend.compareFunctions);
28+
const endpoints = backend.allEndpoints(existing).sort(backend.compareFunctions);
29+
30+
if (endpoints.length === 0) {
31+
logger.info(`No functions found in project ${projectId}.`);
32+
return [];
33+
}
34+
1935
const table = new Table({
2036
head: ["Function", "Version", "Trigger", "Location", "Memory", "Runtime"],
2137
style: { head: ["yellow"] },
2238
});
23-
for (const endpoint of endpointsList) {
39+
40+
for (const endpoint of endpoints) {
2441
const trigger = backend.endpointTriggerType(endpoint);
2542
const availableMemoryMb = endpoint.availableMemoryMb || "---";
2643
const entry = [
2744
endpoint.id,
28-
endpoint.platform === "gcfv2" ? "v2" : "v1",
45+
PLATFORM_TO_DISPLAY_NAME[endpoint.platform] || "v1",
2946
trigger,
3047
endpoint.region,
3148
availableMemoryMb,
@@ -34,5 +51,5 @@ export const command = new Command("functions:list")
3451
table.push(entry);
3552
}
3653
logger.info(table.toString());
37-
return endpointsList;
54+
return endpoints;
3855
});

0 commit comments

Comments
 (0)