const path = require('path');
const { execSync } = require('child_process');

const codemodScripts = [
  path.resolve(__dirname, 'remove-sentry-dependency.js'),
  path.resolve(__dirname, 'remove-sentry-configs.js'),
  path.resolve(__dirname, 'replace-error-page.js')
];

const transform = () => {
  const workingDir = path.resolve(process.cwd());

  codemodScripts.forEach((script) => {
    try {
      execSync(
        `jscodeshift --ignore-pattern="**/node_modules/**" -t ${script} ${workingDir} --extensions=json,ts,tsx,js,jsx,properties,md`,
        {
          cwd: workingDir,
          stdio: 'inherit'
        }
      );
    } catch (e) {
      console.error(e);
    }
  });
};

module.exports = {
  transform
};
