11import { Command } from "../command" ;
22import * as args from "../deploy/functions/args" ;
33import { needProjectId } from "../projectUtils" ;
4- import { Options } from "../options" ;
54import { requirePermissions } from "../requirePermissions" ;
65import * as backend from "../deploy/functions/backend" ;
76import { logger } from "../logger" ;
87import * 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
1018export 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