(abiPath: string, rootPath: string)
| 62 | * Copies the provided ABI file to the default ABI directory in the project root. |
| 63 | */ |
| 64 | export async function prepareAbiDirectory(abiPath: string, rootPath: string): Promise<void> { |
| 65 | const abiDirPath = path.join(rootPath, DEFAULT_ABI_DIR); |
| 66 | |
| 67 | if (!fs.existsSync(abiDirPath)) { |
| 68 | await fs.promises.mkdir(abiDirPath, {recursive: true}); |
| 69 | } |
| 70 | |
| 71 | if (fs.existsSync(path.join(abiDirPath, abiPath))) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | // Ensure abiPath is an absolute path |
| 76 | const ensuredAbiPath = resolveToAbsolutePath(abiPath); |
| 77 | |
| 78 | try { |
| 79 | await fs.promises.copyFile(ensuredAbiPath, path.join(abiDirPath, path.basename(ensuredAbiPath))); |
| 80 | } catch (e: any) { |
| 81 | if (e.code === 'ENOENT') { |
| 82 | throw new Error(`Unable to find abi at: ${abiPath}`); |
| 83 | } |
| 84 | throw new Error(`Unable to copy abi file: ${e.message}`); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Saves the provided ABI to a file in the default ABI directory. |
no test coverage detected