Skip to content

Instantly share code, notes, and snippets.

@vinothpandian
Last active July 20, 2019 15:48
Show Gist options
  • Save vinothpandian/64ded312420a534fcba52f38c072c5fc to your computer and use it in GitHub Desktop.
Save vinothpandian/64ded312420a534fcba52f38c072c5fc to your computer and use it in GitHub Desktop.
Convert firebaseConfig to .env
const firebaseConfigMap = {
apiKey: "REACT_APP_APIKEY",
authDomain: "REACT_APP_AUTH_DOMAIN",
databaseURL: "REACT_APP_DATABASE_URL",
projectId: "REACT_APP_PROJECT_ID",
storageBucket: "REACT_APP_STORAGE_BUCKET",
messagingSenderId: "REACT_APP_MESSAGING_SENDER_ID",
appId: "REACT_APP_APP_ID"
};
// const keyify = key => `REACT_APP_${key.split(/(/W)/)}`
const keyify = key => `REACT_APP_${key.replace(/\.?([A-Z]+)/g, (x,y) => `_${y}`).toUpperCase()}`
const envData = Object.keys(firebaseConfig).reduce((prev, key) => ({
...prev,
[keyify(key)]: firebaseConfig[key]
}), {})
Object.entries(envData).forEach(([key, value]) => {
console.log(`${key}=${value}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment