-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
43 lines (28 loc) · 1.33 KB
/
index.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
var ejs = require('ejs');
var fs = require('fs-sync');
var path = require('path');
var abicodegen = module.exports = {};
abicodegen.generateCode = function(outputAbiJsonFilePath, generatorName) {
var generatorPath = path.join(__dirname, 'templates/' + generatorName + '.ejs');
var outputPathInfo = path.parse(outputAbiJsonFilePath);
var contractName = outputPathInfo.name;
var compilationOutput = JSON.parse(fs.read(outputAbiJsonFilePath, 'utf8'));
var settingsFileName = path.join(outputPathInfo.dir,contractName + '-' + generatorName + '.json');
var settings = {};
if(fs.exists(settingsFileName)){
settings = JSON.parse(fs.read(settingsFileName,'utf8'));
}
var combinedInput={};
for(var key in compilationOutput) combinedInput[key]=compilationOutput[key];
for(var key in settings) combinedInput[key]=settings[key];
combinedInput.abi = JSON.parse(combinedInput.abi.split('\\').join());
if (typeof combinedInput.contractName === "undefined") {
combinedInput.contractName = contractName;
}
var fileNameOutput = path.join(outputPathInfo.dir, combinedInput.contractName + '.cs');
if(fs.exists(fileNameOutput)){
fs.remove(fileNameOutput);
}
var template = ejs.compile(fs.read(generatorPath, 'utf8'));
fs.write(fileNameOutput, template(combinedInput));
}