diff --git a/src/commands/local/lib/connect.js b/src/commands/local/lib/connect.js index 1e9c771..6f788a4 100644 --- a/src/commands/local/lib/connect.js +++ b/src/commands/local/lib/connect.js @@ -21,7 +21,6 @@ const mac = getMac(); let targetConfig = {}; if (fs.existsSync(`samconfig.toml`)) { targetConfig = samConfigParser.parse(); - console.log(targetConfig); } else { targetConfig = { stack_name: process.env.SAMP_STACKNAME, diff --git a/src/shared/samConfigParser.js b/src/shared/samConfigParser.js new file mode 100644 index 0000000..822b47c --- /dev/null +++ b/src/shared/samConfigParser.js @@ -0,0 +1,19 @@ +const toml = require('toml'); +const fs = require('fs'); +function parse() { + if (!fs.existsSync(`samconfig.toml`)) { + return {}; + } + const configEnv = 'default'; + const config = toml.parse(fs.readFileSync(`samconfig.toml`, 'utf-8')); + const envConfig = config[configEnv].deploy.parameters; + envConfig.configEnv = process.env.configEnv || 'default'; + envConfig.stack_name = envConfig.stack_name || config[configEnv].global.parameters.stack_name + envConfig.region = envConfig.region || config[configEnv].global.parameters.region || process.env.AWS_REGION; + envConfig.profile = envConfig.profile || config[configEnv].global.parameters.profile || process.env.AWS_PROFILE; + return envConfig; +} + +module.exports = { + parse +} \ No newline at end of file