-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsettings.ts
More file actions
72 lines (64 loc) · 2.65 KB
/
Copy pathsettings.ts
File metadata and controls
72 lines (64 loc) · 2.65 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { ConfigurationTarget, workspace } from "vscode";
import { DATA_CONNECT_EVENT_NAME, AnalyticsLogger } from "../analytics";
export interface Settings {
readonly firebasePath: string;
readonly firebaseBinaryKind: string;
readonly npmPath: string;
readonly useFrameworks: boolean;
readonly shouldShowIdxMetricNotice: boolean;
readonly importPath?: string;
readonly exportPath: string;
readonly exportOnExit: boolean;
readonly debug: boolean;
readonly extraEnv: Record<string, string>;
}
// TODO: Temporary fallback for bashing, this should probably point to the global firebase binary on the system
const DEFAULT_FIREBASE_BINARY = "npx -y firebase-tools@latest";
export function getSettings(): Settings {
const config = workspace.getConfiguration("firebase");
const firebasePath =
config.get<string>("firebasePath") || DEFAULT_FIREBASE_BINARY;
let firebaseBinaryKind = "unknown"; // Used for analytics.
if (firebasePath === DEFAULT_FIREBASE_BINARY) {
firebaseBinaryKind = "npx";
} else if (firebasePath.endsWith("/.local/bin/firebase")) {
// https://firebase.tools/dataconnect defaults to $HOME/.local/bin
firebaseBinaryKind = "firepit-local";
} else if (firebasePath.endsWith("/local/bin/firebase")) {
// https://firebase.tools/ defaults to /usr/local/bin
firebaseBinaryKind = "firepit-global";
}
const extraEnv = config.get<Record<string,string>>("extraEnv", {});
process.env = { ...process.env, ...extraEnv };
return {
firebasePath,
firebaseBinaryKind,
npmPath: config.get<string>("npmPath", "npm"),
useFrameworks: config.get<boolean>("hosting.useFrameworks", false),
shouldShowIdxMetricNotice: config.get<boolean>(
"idx.viewMetricNotice",
true,
),
importPath: config.get<string>("emulators.importPath"),
exportPath: config.get<string>("emulators.exportPath", "./exportedData"),
exportOnExit: config.get<boolean>("emulators.exportOnExit", false),
debug: config.get<boolean>("debug", false),
extraEnv,
};
}
export function updateIdxSetting(shouldShow: boolean) {
const config = workspace.getConfiguration("firebase");
config.update("idx.viewMetricNotice", shouldShow, ConfigurationTarget.Global);
}
// Persist env var as path setting when path setting doesn't exist
export function setupFirebasePath(analyticsLogger: AnalyticsLogger) {
const config = workspace.getConfiguration("firebase");
if (process.env.FIREBASE_BINARY && !config.get<string>("firebasePath")) {
config.update(
"firebasePath",
process.env.FIREBASE_BINARY,
ConfigurationTarget.Global,
);
}
analyticsLogger.logger.logUsage(DATA_CONNECT_EVENT_NAME.SETUP_FIREBASE_BINARY);
}