UNPKG

@moonwall/util

Version:

Testing framework for the Moon family of projects

36 lines 1.33 kB
// src/functions/contracts.ts import fs from "fs"; import path from "path"; function getAllCompiledContracts(contractsDir = "./", recurse = false) { const contractsPath = path.isAbsolute(contractsDir) ? contractsDir : path.join(process.cwd(), contractsDir); const contracts = fs.readdirSync(contractsPath, { withFileTypes: true }); let contractNames = []; for (const dirent of contracts) { const fullDirentPath = path.join(contractsPath, dirent.name); if (dirent.isDirectory() && recurse) { contractNames = contractNames.concat(getAllCompiledContracts(fullDirentPath, recurse)); } else if (dirent.isFile() && path.extname(dirent.name) === ".json") { contractNames.push(path.basename(dirent.name, ".json")); } } return contractNames; } function getCompiled(contractPath) { const filePath = path.join(process.cwd(), `${contractPath}.json`); if (!fs.existsSync(filePath)) { throw new Error(`Contract name (${contractPath}) doesn't exist in test suite`); } try { const json = fs.readFileSync(filePath, "utf8"); return JSON.parse(json); } catch (_error) { throw new Error( `Contract name ${contractPath} is not compiled. Please check compiled json exists` ); } } export { getAllCompiledContracts, getCompiled }; //# sourceMappingURL=contracts.js.map