UNPKG

dop-stick

Version:

Source control tooling for versionable-upgradeable smart contracts

59 lines 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CompilerService = void 0; const child_process_1 = require("child_process"); const util_1 = require("util"); const logger_1 = require("../logsAndMetrics/core/logger"); const execAsync = (0, util_1.promisify)(child_process_1.exec); class CompilerService { static async ensureCompiled(config) { if (config === null || config === void 0 ? void 0 : config.skip) { logger_1.Logger.info('Compilation skipped via configuration'); return Promise.resolve(); } if (!config) { logger_1.Logger.warning('Compiler specification not found in config. ' + 'Dop-stick will try to use existing compilations and bytecodes.'); return Promise.resolve(); } const compileCommand = config.compileCommand || (config.name && this.getKnownCompilerCommand(config.name)); if (config.name && !compileCommand) { throw new Error(`Unknown compiler "${config.name}". Please provide compileCommand in config.\n` + `Known compilers: ${Object.keys(this.KNOWN_COMPILERS).join(', ')}`); } if (compileCommand) { logger_1.Logger.info(`Compiling contracts using: ${config.name || 'custom compiler'}`); try { const { stdout, stderr } = await execAsync(compileCommand); if (stderr) { logger_1.Logger.info(stderr); // Some compilers use stderr for warnings } if (stdout) { logger_1.Logger.info(stdout); } logger_1.Logger.success('Compilation completed successfully'); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred during compilation'; logger_1.Logger.error(`Compilation failed using command "${compileCommand}"\n` + `Error: ${errorMessage}`); process.exit(1); } } } static getKnownCompilerCommand(name) { const normalizedName = name.toLowerCase(); return this.KNOWN_COMPILERS[normalizedName] || null; } } exports.CompilerService = CompilerService; CompilerService.KNOWN_COMPILERS = { hardhat: 'npx hardhat compile', foundry: 'forge build', truffle: 'truffle compile', brownie: 'brownie compile' }; //# sourceMappingURL=compilerService.js.map