Created
May 12, 2020 00:56
-
-
Save adrianmcli/66a6a88943641b37ec28d68c5e1659e2 to your computer and use it in GitHub Desktop.
Revisions
-
adrianmcli created this gist
May 12, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ const path = require("path"); const fs = require("fs"); // get JSON artifact files const artifactDir = path.join(__dirname, "build/contracts/"); const files = fs.readdirSync(artifactDir); const jsonFiles = files.filter(x => x.slice(-4) === "json"); console.log(jsonFiles.length, "json files found"); // create abi directory const outDir = "./abi/"; if (!fs.existsSync(outDir)) { fs.mkdirSync(outDir); } // read the files let count = 0; jsonFiles.forEach(filename => { const artifactPath = artifactDir + filename; const rawdata = fs.readFileSync(artifactPath); const json = JSON.parse(rawdata); const abi = json.abi; if (abi.length > 0) { const data = JSON.stringify(abi, null, 2); fs.writeFileSync(`${outDir}${filename}`, data); console.log("success:", filename); count++; } }); console.log(`${count} file(s) produced`);