"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * This script is used to keep only required data in contracts ABI files
 * and remove anything added by Truffle or other building systems.
 *
 * The file can be called directly with `yarn abi:cleanup`
 */
const path_1 = __importDefault(require("path"));
const files_1 = require("./files");
const fs = require('fs-extra');
const keysToKeep = [
    'contractName',
    'abi',
    'bytecode',
    'deployedBytecode',
    'compiler',
    'schemaVersion',
    'updatedAt',
];
async function main() {
    const paths = await (0, files_1.getAbiPaths)();
    paths.flat().forEach((abiPath) => {
        const abiFullPath = path_1.default.resolve('src', abiPath);
        const manifest = fs.readJsonSync(abiFullPath);
        if (Object.keys(manifest).length !== keysToKeep.length) {
            const { contractName, abi, bytecode, deployedBytecode, compiler, schemaVersion, updatedAt, } = manifest;
            const lighter = {
                contractName,
                abi,
                bytecode,
                deployedBytecode,
                compiler,
                schemaVersion,
                updatedAt,
            };
            console.log('Replacing by a smaller ', abiPath);
            fs.writeJsonSync(abiFullPath, lighter, { spaces: 2 });
        }
    });
}
main()
    .then(() => process.exit(0))
    .catch((error) => {
    console.error(error);
    process.exit(1);
});
