const path = require('path');
const chalk = require('chalk');
const fs = require('fs');

/**
 * Loads `dev.private.json` file from project root.
 * File must contain `cert` and `key` properties pointing to
 * proper files in the dev's filesystem.
 */
function loadCertSettings(rootPath) {
  const filePath = path.join(rootPath, 'dev.private.json');
  try {
    return JSON.parse(fs.readFileSync(filePath, 'utf8'));
  } catch (e) {
    console.error(`Error finding/parsing ${chalk.default.yellow(filePath)}`);
    throw e;
  }
}

module.exports = loadCertSettings;
