'use strict';

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

const tools = require('./scripts/utils/tools');

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-tools');
    const euiScriptFile = path.resolve(rootPath, 'bin', 'eui-scripts.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);
  })
