Last active
January 20, 2021 10:59
-
-
Save andrelugomes/f5d268873d38de869439cb1b76644de3 to your computer and use it in GitHub Desktop.
firebase functions:config:set from .env.json file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//from https://github.com/firebase/firebase-tools/issues/406 | |
const env = process.argv[2]; | |
const arg = process.argv[3]; | |
const configPath = `./.env.${env}.json`; | |
const collectConfigLines = (o, propPath, configLines) => { | |
propPath = propPath || ''; | |
configLines = configLines || []; | |
for (const key of Object.keys(o)) { | |
const newPropPath = propPath + key; | |
if (typeof o[key] === 'object') { | |
collectConfigLines(o[key], newPropPath + '.', configLines); | |
} else if (o[key] != null && o[key] !== '') { | |
configLines.push(`${newPropPath}=${JSON.stringify(o[key])}`); | |
} | |
} | |
} | |
const config = require(configPath); | |
const configLines = []; | |
collectConfigLines(config, '', configLines); | |
const cp = require('child_process'); | |
const command = `firebase functions:config:set ${configLines.join(' ')}`; | |
if (arg === "--dry-run") { | |
console.log(command); | |
} else { | |
cp.exec(command); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment