const { chalk, log, getRegistryUrl } = require('./common');
async function main() {
  try {
    const path = require('path');
    const fs = require('fs');
    await log('postpack.js for ' + process.env.npm_package_name + ' started...', 'green')

    const ORIG_PKG_PATH = path.resolve(__dirname, '../../package.json');
    const TEMP_PKG_PATH = path.resolve(__dirname, '../../packagetemp.json');
    await log('package: ' + ORIG_PKG_PATH)
    await log('packagetemp: ' + TEMP_PKG_PATH)

    const fileExists = fs.existsSync(TEMP_PKG_PATH);
    if (fileExists) {
      await log(`${TEMP_PKG_PATH} exists.`);
      const tempPkgData = require(TEMP_PKG_PATH);
      var tempPkgDataString = JSON.stringify(tempPkgData, null, 2)
      fs.writeFileSync(ORIG_PKG_PATH, tempPkgDataString);
      await log('package.json updated with packagetemp.json data...')
      fs.unlinkSync(TEMP_PKG_PATH);
      await log('packagetemp.json deleted...')
    } else {
      await log(`${TEMP_PKG_PATH} does not exist.`);
    }
    log('postpack.js for ' + process.env.npm_package_name + ' completed...\n', 'green')
  }
  catch (e) {
    console.log('* ReExt: - error: ' + e.toString())
  }
}
main();

