-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathinternaltesting-functions-discover.ts
More file actions
56 lines (50 loc) · 2.05 KB
/
internaltesting-functions-discover.ts
File metadata and controls
56 lines (50 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Command } from "../command";
import { Options } from "../options";
import { logger } from "../logger";
import { loadCodebases } from "../deploy/functions/prepare";
import { normalizeAndValidate } from "../functions/projectConfig";
import { getProjectAdminSdkConfigOrCached } from "../emulator/adminSdkConfig";
import { needProjectId } from "../projectUtils";
import { FirebaseError } from "../error";
import * as ensureApiEnabled from "../ensureApiEnabled";
import { runtimeconfigOrigin } from "../api";
import * as experiments from "../experiments";
import { getFunctionsConfig } from "../deploy/functions/prepareFunctionsUpload";
export const command = new Command("internaltesting:functions:discover")
.description("discover function triggers defined in the current project directory")
.action(async (options: Options) => {
const projectId = needProjectId(options);
const fnConfig = normalizeAndValidate(options.config.src.functions);
const firebaseConfig = await getProjectAdminSdkConfigOrCached(projectId);
if (!firebaseConfig) {
throw new FirebaseError(
"Admin SDK config unexpectedly undefined - have you run firebase init?",
);
}
let runtimeConfig: Record<string, unknown> = { firebase: firebaseConfig };
const allowFunctionsConfig = experiments.isEnabled("legacyRuntimeConfigCommands");
if (allowFunctionsConfig) {
try {
const runtimeConfigApiEnabled = await ensureApiEnabled.check(
projectId,
runtimeconfigOrigin(),
"runtimeconfig",
/* silent=*/ true,
);
if (runtimeConfigApiEnabled) {
runtimeConfig = { ...runtimeConfig, ...(await getFunctionsConfig(projectId)) };
}
} catch (err) {
logger.debug("Could not check Runtime Config API status, assuming disabled:", err);
}
}
const wantBuilds = await loadCodebases(
fnConfig,
options,
firebaseConfig,
runtimeConfig,
undefined, // no filters
);
logger.info(JSON.stringify(wantBuilds, null, 2));
return wantBuilds;
});