'use strict';

import path from 'path'
import fs from 'fs'
import eol from 'eol';
import * as tools from '@eui/tools/scripts/utils/tools.js'

(async function () {
  return Promise.resolve()
    .then(() => {
      tools.logTitle('Executing postbuild script');
    })

    // Rewrites eui-scripts EOL for Linux / Macs users
    .then(() => {
      tools.logInfo('Replace eUI scripts EOL');

      const rootPath = path.join(process.cwd(), 'packages', 'eui-automation');
      const euiScriptFile = path.resolve(rootPath, 'bin', 'eui-automation.js');
      const content = fs.readFileSync(euiScriptFile, { encoding: 'utf8' });

      const contentToLF = eol.lf(content);

      fs.writeFileSync(euiScriptFile, contentToLF);

    })


    .then(() => {
      tools.logSuccess();
    })


    .catch((e) => {
      console.log(e);
      process.exit(1);
    })
})();