Last active
February 3, 2021 17:59
-
-
Save jgermade/aa4276998290d08cb17a6374f036aa14 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
process.stdin.resume() | |
process.stdin.setEncoding('utf8') | |
function envsubst (str) { | |
return str | |
.replace(/\${ *([^}]+?) *}/g, (matched, var_name) => { | |
return process.env[var_name] || matched | |
}) | |
} | |
var input = '' | |
process.stdin.on('data', function(chunk) { | |
input += chunk | |
if (/\n/.test(input)) { | |
let lines = input.split('\n') | |
input = lines.pop() | |
lines.forEach(line => process.stdout.write(envsubst(line) + '\n')) | |
} | |
}) | |
process.stdin.on('end', ()=> { | |
process.stdout.write(envsubst(input) + '\n') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment