"use strict";

const fs = require('fs');

const {
  log
} = require('..');

function addScripts(scripts) {
  fs.readFile('./package.json', 'utf8', (err, configFileString) => {
    if (err) log('[LINT SETUP] No package.json in the current directory');else {
      const configFile = JSON.parse(configFileString); // Still Object destructuring causes issue. 😐
      // configFile.scripts = {
      //   ...configFile.scripts,
      //   ...scripts,
      // };

      configFile.scripts = Object.assign(configFile.scripts || {}, scripts);
      const data = JSON.stringify(configFile, undefined, 2);
      fs.writeFileSync('./package.json', data);
    }
  });
}

module.exports = {
  addScripts
};