const { chalk, log, getRegistryUrl } = require('./common');
async function main() {
    try {
        // const { execSync } = require('child_process');
        const path = require('path');
        const fs = require('fs');
        // const { default: chalk } = await import("chalk");
        await log('postinstall.js for ' + process.env.npm_package_name + ' started...', 'green')

        const currentWorkingDirectory = process.cwd();
        await log('Current working directory: ' + currentWorkingDirectory);
        //return;
        if (currentWorkingDirectory === '/Users/marcgusmano/@/ReExt/publish/ReExt') {
            await log('not touching package.json');
        }
        else {
            const ORIG_PKG_PATH = path.resolve(__dirname, '../../package.json');
            await log('package - ' + ORIG_PKG_PATH)
            const pkgData = require(ORIG_PKG_PATH);
            delete pkgData.scripts;
            await log('remove scripts from package.json')

            fs.writeFileSync(ORIG_PKG_PATH, JSON.stringify(pkgData, null, 2));
            const scriptPaths = [
                './dist/scripts/postpack.js',
                './dist/scripts/preinstall.js',
                './dist/scripts/common.js',
                './dist/scripts/postinstall.js',
                './dist/scripts'
            ];
            scriptPaths.forEach(scriptPath => {
                fs.rmSync(scriptPath, { force: true, recursive: true });
            });
            await log('remove ./dist/scripts folder')
        }
        await log('postinstall.js for ' + process.env.npm_package_name + ' completed...\n', 'green')
    } catch (e) {
        console.log('* ReExt: - error: ' + e.toString())
    }
}
main();
