-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-firebase-remote-config.js
More file actions
33 lines (29 loc) · 1.06 KB
/
Copy pathget-firebase-remote-config.js
File metadata and controls
33 lines (29 loc) · 1.06 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
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const firebaseDir = path.resolve(__dirname, '..');
try {
// Fetch remote config as JSON
const output = execSync('npx firebase remoteconfig:get --json --project default', {
encoding: 'utf-8',
cwd: firebaseDir,
});
const config = JSON.parse(output);
const parameters = config?.result?.parameters;
// Extract default values from parameters
const defaults = {};
if (parameters) {
for (const [key, paramObj] of Object.entries(parameters)) {
if (paramObj.defaultValue && paramObj.defaultValue.value !== undefined) {
defaults[key] = paramObj.defaultValue.value;
}
}
}
// Write to JSON file
const outputPath = path.join(firebaseDir, '..', 'public', 'remote-config-defaults.json');
fs.writeFileSync(outputPath, `${JSON.stringify(defaults, null, 2)}\n`, 'utf-8');
console.log(`Successfully wrote ${outputPath}`);
} catch (error) {
console.error('Error fetching or parsing remote config:', error.message);
process.exit(1);
}