UNPKG

@nomyx/hardhat-adminui

Version:

A comprehensive Hardhat plugin providing a web-based admin UI for deployed smart contracts with Diamond proxy support, contract interaction, event monitoring, and deployment dashboard.

56 lines (55 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isPortAvailable = isPortAvailable; exports.findAvailablePort = findAvailablePort; exports.getConfiguredPort = getConfiguredPort; const net_1 = require("net"); /** * Check if a port is available */ function isPortAvailable(port) { return new Promise((resolve) => { const server = (0, net_1.createServer)(); server.listen(port, () => { server.once('close', () => { resolve(true); }); server.close(); }); server.on('error', () => { resolve(false); }); }); } /** * Find the next available port starting from the given port */ async function findAvailablePort(startPort, maxPort = 65535) { for (let port = startPort; port <= maxPort; port++) { if (await isPortAvailable(port)) { return port; } } throw new Error(`No available port found between ${startPort} and ${maxPort}`); } /** * Get the configured port from environment or hardhat config */ function getConfiguredPort(hre) { // Check environment variable first if (process.env.HARDHAT_ADMINUI_PORT) { const envPort = parseInt(process.env.HARDHAT_ADMINUI_PORT, 10); if (!isNaN(envPort) && envPort > 0 && envPort <= 65535) { return envPort; } } // Check hardhat config if (hre.config?.adminUI?.port) { const configPort = parseInt(hre.config.adminUI.port, 10); if (!isNaN(configPort) && configPort > 0 && configPort <= 65535) { return configPort; } } // Default port return 3000; }