-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcompile-types.js
47 lines (41 loc) · 1.24 KB
/
compile-types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Take the artifacts and generate types.
*/
import fs from "fs";
import path from "path";
import glob from "glob";
import { exec } from "child_process";
import { fileURLToPath } from "url";
// Handle __dirname in ES Modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Define the base folder path
const baseFolderPath = path.resolve(__dirname, "./artifacts");
// Find all .json files in the folder (and subfolders), excluding .dbg.json and build-info
const abiFiles = glob.sync(`${baseFolderPath}/**/*.json`, {
ignore: [
`${baseFolderPath}/**/*.dbg.json`, // Exclude debug files
`${path.resolve(__dirname, "./artifacts/build-info")}/**/*.json`, // Exclude build-info folder
],
});
// If no valid files are found, exit
if (abiFiles.length === 0) {
console.error("No valid ABI files found.");
process.exit(1);
}
// Prepare the TypeChain command for all valid files
const typechainCmd = `npx typechain --target ethers-v6 --out-dir typechain-types ${abiFiles.join(
" "
)}`;
// Run the command
exec(typechainCmd, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Stderr: ${stderr}`);
return;
}
console.log(stdout);
});