-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path.abi.js
35 lines (31 loc) · 892 Bytes
/
.abi.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
var fs = require('fs');
var path = require('path');
const OUTPUT_DIR = process.env.OUTPUT || './build/abi/';
if (!fs.existsSync(OUTPUT_DIR)) {
fs.mkdirSync(OUTPUT_DIR);
}
function readFiles(dirname, onFileContent, onError) {
fs.readdir(dirname, function(err, filenames) {
if (err) {
onError(err);
return;
}
filenames.forEach(function(filename) {
fs.readFile(dirname + filename, 'utf-8', function(err, content) {
if (err) {
onError(err);
return;
}
onFileContent(filename, content);
});
});
});
}
let dir = './build/contracts/';
readFiles(dir, function(filename, content) {
if (filename.includes(".abi.")) return;
let abi = JSON.stringify(JSON.parse(content).abi, null, 2);
fs.writeFileSync(`${OUTPUT_DIR}${path.basename(filename, '.json')}.abi.json`, abi);
}, function(err) {
throw err;
});