Last active
December 11, 2023 21:11
-
-
Save pedro-mass/f2e6b14a4f6728baa67e9eb175657779 to your computer and use it in GitHub Desktop.
Generate commands for setting Heroku ENV from .env
This file contains hidden or 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
// given .env file | |
// generate heroku env set commands to be run in heroku cli | |
// usage: node scripts/create-heroku-env-update.js .env app1,app2 | |
const fs = require("fs"); | |
const envFile = process.argv[2]; | |
const env = fs.readFileSync(envFile, "utf8"); | |
const envVars = env | |
.split("\n") | |
.filter((line) => line.length > 0 && !line.startsWith("#")) // remove empty lines and comments | |
.map((line) => line.split("#")[0]); // remove in-line comments | |
if (envVars.length === 0) { | |
console.error("No env vars found"); | |
process.exit(0); | |
} | |
// support multiple apps | |
const apps = process.argv[3] ? process.argv[3].split(",") : []; | |
if (apps.length === 0) { | |
console.error("No apps specified"); | |
process.exit(0); | |
} | |
apps.forEach((app) => { | |
console.log(`\n# ${app}`); | |
envVars.forEach((envVar) => { | |
console.log(`heroku config:set --app ${app} ${envVar} `); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment