Skip to content

Instantly share code, notes, and snippets.

@ekkis
Created January 13, 2020 22:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekkis/1fe8b9ec03afaae1932fea986b4382b8 to your computer and use it in GitHub Desktop.
Save ekkis/1fe8b9ec03afaae1932fea986b4382b8 to your computer and use it in GitHub Desktop.
EOS tools
#!/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');
}
@ekkis
Copy link
Author

ekkis commented Jan 13, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment