-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2a6140
commit 54abf39
Showing
8 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { spawn } = require('node:child_process'); | ||
|
||
function runCommand(command, args) { | ||
return new Promise((resolve, reject) => { | ||
const cmd = spawn(command, args, { stdio: 'inherit' }); | ||
|
||
cmd.on('close', (code) => { | ||
if (code !== 0) { | ||
reject( | ||
new Error(`"${command} ${args.join(' ')}" failed with code ${code}`) | ||
); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { runCommand }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env node | ||
|
||
const os = require('os'); | ||
const { lookpath } = require('lookpath'); | ||
|
||
const { runCommand } = require('./lib/runCommand'); | ||
|
||
const ENV_STAGE = process.argv[2]; | ||
const AWS_VAULT_PROFILE = process.env.AWS_VAULT_PROFILE; | ||
|
||
function getCmd() { | ||
if (os.platform() === 'win32') { | ||
return 'cmd.exe'; | ||
} | ||
return process.env.SHELL; | ||
} | ||
|
||
(async () => { | ||
try { | ||
if (!ENV_STAGE || ENV_STAGE === 'undefined' || ENV_STAGE === 'local') { | ||
console.error('Please set --env argument'); | ||
process.exit(1); | ||
} | ||
|
||
process.env.ENV_STAGE = ENV_STAGE; | ||
|
||
const cmd = getCmd(); | ||
if (await lookpath('aws-vault')) { | ||
await runCommand('aws-vault', ['exec', AWS_VAULT_PROFILE, '--', cmd]); | ||
} else { | ||
await runCommand(cmd, []); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
})(); |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.