forked from Leverege/deprecated-microchip-avr-iot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getFirebaseConfig.js
40 lines (34 loc) · 1011 Bytes
/
getFirebaseConfig.js
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
const fs = require('fs')
if (process.argv.length < 3) {
console.log('Usage: node ' + process.argv[1] + ' FILENAME');
process.exit(1);
}
let configJson
// read text output of firebase config:web, and copy json portion
try {
const file = process.argv[2]
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
console.error('error reading config.txt (should have been automatically generated', err)
}
const begin = data.indexOf("(") + 1
const end = data.indexOf(")")
configJson = data.slice(begin,end)
});
}
catch(err) {
throw "getFireBaseConfig.js must be called with a txt file as a positional argument"
}
// write json to ui/src/Config.js
try {
fs.readFile('./Config.js', 'utf8', (err,data) => {
if (err) {
return console.error('error reading Config.js:', err);
}
const result = data.replace(/'<fbconfig>'/g, configJson);
fs.writeFileSync('./ui/src/Config.js', result, 'utf8');
});
}
catch(err) {
throw 'error reading Config.js in ui/'
}