-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathextract-abis.js
35 lines (33 loc) · 967 Bytes
/
extract-abis.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
const fs = require('fs');
const path = require('path');
/**
* Extract abis from Arc contracts folder into truffle compatible format
*/
async function extractAbis (base) {
var files = fs.readdirSync(base);
for (var i = 0; i < files.length; i++) {
var filename = path.join(base, files[i]);
var stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
extractAbis(filename); // recurse
} else if (filename.indexOf('.json') >= 0 && filename.indexOf('.dbg') === -1) {
console.log('-- found: ', filename);
const contract = JSON.parse(fs.readFileSync(filename, 'utf-8'));
fs.writeFileSync(
path.join('./build/contracts', files[i]),
JSON.stringify(contract, undefined, 2),
'utf-8'
);
}
}
}
if (require.main === module) {
extractAbis('./build/contracts/contracts').catch(err => {
console.log(err);
process.exit(1);
});
} else {
module.exports = {
extractAbis
};
}