| 7 | export type FileWithStructs = { fileName: string; structs: Array<AbiStruct | AbiEnum> } |
| 8 | |
| 9 | export const getInputFiles = (argv: { input: string }): FileWithStructs[] => { |
| 10 | if (!fs.existsSync(argv.input)) { |
| 11 | throw new Error(`File or directory not found: ${argv.input}`); |
| 12 | } |
| 13 | const files: FileWithStructs[] = []; |
| 14 | const filePaths: string[] = []; |
| 15 | if (isDir(argv.input)) { |
| 16 | const fileNames = fs.readdirSync(argv.input).filter(isSolFile); |
| 17 | for (const fileName of fileNames) { |
| 18 | const filePath = path.join(argv.input, fileName); |
| 19 | filePaths.push(filePath); |
| 20 | } |
| 21 | } else { |
| 22 | if (!isSolFile(argv.input)) { |
| 23 | throw new Error(`${argv.input} is not a Solidity file`) |
| 24 | } |
| 25 | filePaths.push(argv.input); |
| 26 | } |
| 27 | for (const filePath of filePaths) { |
| 28 | const { name } = path.parse(filePath); |
| 29 | const code = fs.readFileSync(filePath, 'utf8'); |
| 30 | const structs = parseCode(code) as Array<AbiStruct | AbiEnum>; |
| 31 | files.push({ fileName: name, structs }) |
| 32 | } |
| 33 | return files; |
| 34 | } |