Skip to content

Instantly share code, notes, and snippets.

@w33ble
Created June 23, 2021 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w33ble/d96da19af5070c2c89395fd54398d3a3 to your computer and use it in GitHub Desktop.
Save w33ble/d96da19af5070c2c89395fd54398d3a3 to your computer and use it in GitHub Desktop.
Generate .ssm-env from your preferences.arc file
/* eslint @typescript-eslint/no-var-requires: 0 */
console.log('WARNING: Make sure you run `yarn arc env` before updating your env file')
const parse = require('@architect/parser')
const fs = require('fs/promises')
const readline = require('readline')
function ask(question) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
return new Promise((resolve) => {
rl.question(`${question} `, (answer) => {
rl.close()
resolve(answer)
})
})
}
async function main() {
const preferences = parse((await fs.readFile('./preferences.arc')).toString())
const config = parse((await fs.readFile('./app.arc')).toString())
const appName = config.app[0]
const output = preferences.env.reduce((acc, obj) => {
const env = Object.keys(obj)[0]
const settings = obj[env]
const output = []
Object.entries(settings).forEach(([name, value]) => {
output.push(`${env},/${appName}/${env}/${name},${value}`)
})
return (acc += `${output.join('\n')}\n\n`)
}, '')
console.log(output)
const answer = await ask('Overwrite your .ssm-env file? [y/N] ')
if (answer === 'y' || answer === 'Y') {
await fs.writeFile('.ssm-env', output)
console.log('.ssm-env file updated!')
}
}
main()
.then(() => {
process.exit()
})
.catch((err) => {
console.error(err)
process.exit(1)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment