Created
January 13, 2020 22:37
-
-
Save ekkis/1fe8b9ec03afaae1932fea986b4382b8 to your computer and use it in GitHub Desktop.
EOS tools
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 characters
#!/usr/bin/env node | |
const fs = require('fs'); | |
const d = 'ricardian'; | |
if (!fs.existsSync(d)) fs.mkdirSync(d); | |
args().forEach(fn => doc(fn)); | |
function args() { | |
var ret = process.argv.slice(2); | |
return ret.length > 0 ? ret | |
: fs.readdirSync('.').filter(fn => fn.match(/\.cpp$/)); | |
} | |
function doc(fn) { | |
var s = fs.readFileSync(fn, 'utf8'); | |
var r = s.split('\n'); | |
var dapp = ''; | |
var actions = []; | |
for (var i = 0; i< r.length; i++) { | |
var m = r[i].match(/eosio::contract\("(.*)"\)/); | |
if (m) dapp = m[1]; | |
m = r[i].match(/eosio::action(?:\("(.*)"\))?/); | |
if (m) { | |
if (m[1]) actions.push(m[1]); | |
else { | |
m = r[++i].match(/.*?\s+(\w+)\s*\(/); | |
if (m) actions.push(m[1]); | |
} | |
} | |
} | |
var fn = d + '/' + dapp + '.contracts.md'; | |
var data = actions.map(nm => { | |
return `<h1 class="contract">${nm}</h1>\n\n## Description\n\nThis action...`; | |
}); | |
if (!fs.existsSync(fn)) | |
fs.writeFileSync(fn, data.join('\n\n')) | |
fn = d + '/' + dapp + '.clauses.md'; | |
if (!fs.existsSync(fn)) | |
fs.writeFileSync(fn, '<h1 class="clause">First Clause</h1>\n\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run this tool in the directory where the *.cpp files exist. it will create a directory called
ricardian
and put the contracts in it. when compiling, pass-R ricardian
to eosio-cpp to pick up the content. Warnings will disappear