import exec from '../helpers/exec';

import Deployment from '../types/Deployment';

/**
 * Get the deployment configuration of an app
 * @author Gabe Abrams
 * @param deployment the deployment entry to check
 * @returns parsed JSON of the deployment config
 */
const getDeploymentConfig = (deployment: Deployment) => {
  let output: { [k: string]: any };
  let text: string;
  try {
    text = exec(`./node_modules/.bin/caccl-deploy show --app ${deployment.app} --profile ${deployment.profile}`);
    output = JSON.parse(text);
  } catch (err) {
    console.log('An error occurred while trying to get the current deployment configuration:');
    console.log(err);
    console.log('\nText returned:');
    console.log(text);
    process.exit(0);
  }

  return output;
};

export default getDeploymentConfig;
