Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
v0.1.3
Browse files Browse the repository at this point in the history
v0.1.3
  • Loading branch information
dpilch authored Aug 20, 2017
2 parents 51a79ac + 25a7114 commit 70b1c76
Show file tree
Hide file tree
Showing 28 changed files with 755 additions and 80 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
*~
node_modules
lib
contracts
.solmd
sol.md
test/output.md
4 changes: 0 additions & 4 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
*~
src
contracts
.solmd
sol.md
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: node_js
node_js:
- '4'
cache:
directories:
- node_modules
before_script:
- "sudo add-apt-repository ppa:ethereum/ethereum -y"
- "sudo apt-get update -y"
- "sudo apt-get install solc -y"

deploy:
provider: npm
email: [email protected]
api_key:
secure: QBcfNa5MXhPTGv9pnqpcex4jD0mb5UtLUrXyDLNU1cKLEU6nQ+XDqoHrrplGWCbMbc+LjTLOX7z9vzwaeSJxGDno6CmNvMo358uiwWv9Kh+CV4521/VOJuzNXs7xGsVuMOJdFvOtp0oY0+R1T27ddW9mxEeGadAjfUOLYiopA3eyYHk38b6sKUyL2fn4Pq277P4F5EXzHNzYZxnzNGlhafxrTgB1dVRxjS/Gt7OD7SL7eqzTyr20GRH4LSxFzkERDlVUxA/W07NftnsbYaY8SNdg5YsrZxZPaPFD1XtZgCF1IN8+248VytcQnriQMgQ2vKua0XM2UfGp5sci6CEZkIWtu4n9GnpjNS9EOYOKAuHbqJTXbkV1vHKWzZJPpF5KtjJU1h1sGzmcA5ax+Wze3YI8+9tNZ16NDATGw+iXKEAhpLR6+66O/OSum4Ez9GFcLDtHAL7wttkVdHZrpsOL5qGkGodcmh8qKrKqHNKAHkfnIeaROIPv+ZAyVVh3DXw9lrqZOMfq1hL3ahrdHfQipOUZlzWUZFBxiTdCUdnuiNL7NTfRdnCWNH//PfyTVGqbbxqC2ru40FwWNM7bzBVrVWu1QbexKvGBfjhJHXlDW9MO/KEuiInCFsDJKga3lbjDwxSSaHWnlKqPfnHqoGV4Z1moomPPakc5tQtz8nnA1OE=
on:
tags: true
branch: master
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Generate lightweight markdown documentation for Solidity contracts.

[![Build Status](https://travis-ci.org/dpilch/solmd.svg?branch=master)](https://travis-ci.org/dpilch/solmd)

## Installation

```
Expand Down Expand Up @@ -31,16 +33,22 @@ contract GavCoin {
@dev This should be the documentation of the function for the developer docs
@param to The address of the recipient of the GavCoin
@param valueInmGAV The GavCoin value to send
@return {
"done": "if done"
}
*/
function send(address to, uint256 valueInmGAV) {
function send(address to, uint256 valueInmGAV) returns (bool done) {
if (balances[msg.sender] >= valueInmGAV) {
balances[to] += valueInmGAV;
balances[msg.sender] -= valueInmGAV;
done = true;
}
}
}
```

Return params must be a single `@param` formatted as an object as shown above.

The above example will produce the following result as raw markdown.

```
Expand All @@ -51,9 +59,9 @@ The above example will produce the following result as raw markdown.
Gavin Wood
## function send
## *function* send
`d0679d34`
GavCoin.Send(to, valueInmGAV) `d0679d34`
**Send `(valueInmGAV / 1000).fixed(0,3)` GAV from the account of `message.caller.address()`, to an account accessible only by `to.address()**
Expand All @@ -66,6 +74,12 @@ Inputs
| *address* | to | The address of the recipient of the GavCoin |
| *uint256* | valueInmGAV | The GavCoin value to send |
Outputs
| | | |
|-|-|-|
| *bool* | done | if done |
---
```

Expand Down
37 changes: 37 additions & 0 deletions lib/bin/solmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env node
'use strict';

var _fs = require('fs');

var _fs2 = _interopRequireDefault(_fs);

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _minimist = require('minimist');

var _minimist2 = _interopRequireDefault(_minimist);

var _index = require('../index');

var Solmd = _interopRequireWildcard(_index);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var args = (0, _minimist2.default)(process.argv.slice(2));

if (typeof args.help !== 'undefined') {
var _JSON$parse = JSON.parse(_fs2.default.readFileSync(_path2.default.join(__dirname, '../../package.json')).toString()),
version = _JSON$parse.version;

process.stdout.write('solmd v' + version + '\n\nusage: solmd [--src <solidity>] [--dest <target>]\n\nparameters:\n\n--src Folder that contains the contracts you want to compile\n--dest Destination of markdown output\n--no-toc Do not generate table of contents, defaults false\n\n ');
process.exit();
} else {
Solmd.default.build(args).catch(function (err) {
console.error(err); // eslint-disable-line no-console
process.exit(1);
});
}
24 changes: 24 additions & 0 deletions lib/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (args) {
return (0, _compile2.default)(args).then(function (data) {
return (0, _markdown2.default)({ args: args, data: data });
}).catch(function (err) {
console.error(err); // eslint-disable-line no-console
process.exit(1);
});
};

var _compile = require('./compile');

var _compile2 = _interopRequireDefault(_compile);

var _markdown = require('./markdown');

var _markdown2 = _interopRequireDefault(_markdown);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
60 changes: 60 additions & 0 deletions lib/compile/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.default = function (opts) {
opts._.split(' ').forEach(function (file) {
if (!_fs2.default.existsSync(file)) {
process.stderr.write(file + ': No such file or directory\n');
process.exit(1);
}
});
return (0, _solc2.default)(opts._).then(function (_ref2) {
var contracts = _ref2.contracts;
return compile(_extends({}, opts, { contracts: contracts }));
}).catch(function () {
console.error('solmd: Failed to compile contracts at ' + opts._); // eslint-disable-line no-console
process.exit(1);
});
};

var _fs = require('fs');

var _fs2 = _interopRequireDefault(_fs);

var _parseAbi = require('./parse-abi');

var _parseAbi2 = _interopRequireDefault(_parseAbi);

var _solc = require('./solc');

var _solc2 = _interopRequireDefault(_solc);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function compile(_ref) {
var contracts = _ref.contracts;

var data = [];
Object.keys(contracts).forEach(function (contractName) {
var contract = contracts[contractName];
var fileName = contract.fileName;
var devdoc = contract.devdoc;
var author = devdoc.author,
title = devdoc.title;

data.push({
author: author,
title: title,
fileName: fileName.replace(process.env.PWD, ''),
name: contractName,
abiDocs: (0, _parseAbi2.default)(contract)
});
});

return data;
}
49 changes: 49 additions & 0 deletions lib/compile/parse-abi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.default = function (contract) {
return contract.abi.map(function (method) {
var inputParams = method.inputs || [];
var signature = method.name && method.name + '(' + inputParams.map(function (i) {
return i.type;
}).join(',') + ')';
var devDocs = (contract.devdoc.methods || {})[signature] || {};
var userDocs = (contract.userdoc.methods || {})[signature] || {};
// map abi inputs to devdoc inputs
var params = devDocs.params || {};
var inputs = inputParams.map(function (param) {
return _extends({}, param, { description: params[param.name] });
});
var argumentList = inputParams.reduce(function (inputString, param) {
return '' + inputString + param.name + ', ';
}, '').slice(0, -2);
// don't write this
delete devDocs.params;

var outputs = void 0;
try {
var outputParams = JSON.parse(devDocs.return);
outputs = method.outputs.map(function (param) {
return _extends({}, param, { description: outputParams[param.name] });
});
} catch (e) {
process.stderr.write('warning: invalid @return for ' + method.name + ' - output may be effected\n');
outputs = method.outputs;
}

return _extends({}, method, devDocs, userDocs, {
inputs: inputs,
argumentList: argumentList,
outputs: outputs,
signature: signature,
signatureHash: signature && (0, _helpers.getFunctionSignature)(signature)
});
});
};

var _helpers = require('../helpers');
38 changes: 38 additions & 0 deletions lib/compile/solc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.default = function (src) {
return new Promise(function (resolve) {
var exec = 'solc --combined-json abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,srcmap,srcmap-runtime,userdoc ' + src;
var rawRes = _child_process2.default.execSync(exec);
var res = JSON.parse(rawRes);
resolve({
contracts: Object.keys(res.contracts).reduce(function (o, k) {
var file = k.split(':')[0];
var fileFragments = file.split('/');
var contractName = fileFragments[fileFragments.length - 1].split('.sol')[0];
var contract = res.contracts[k];
var fileName = process.env.PWD + '/' + k.split(':')[0];
return _extends({}, o, _defineProperty({}, contractName, _extends({}, contract, {
fileName: fileName,
abi: JSON.parse(contract.abi),
devdoc: JSON.parse(contract.devdoc),
userdoc: JSON.parse(contract.userdoc)
})));
}, {})
});
});
};

var _child_process = require('child_process');

var _child_process2 = _interopRequireDefault(_child_process);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7 changes: 7 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
var DEFAULT_DEST = exports.DEFAULT_DEST = 'sol.md';
var DEFAULT_NO_TOC = exports.DEFAULT_NO_TOC = false;
38 changes: 38 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.clearDirectory = clearDirectory;
exports.getFunctionSignature = getFunctionSignature;

var _rimraf = require('rimraf');

var _rimraf2 = _interopRequireDefault(_rimraf);

var _mkdirp = require('mkdirp');

var _mkdirp2 = _interopRequireDefault(_mkdirp);

var _keccakjs = require('keccakjs');

var _keccakjs2 = _interopRequireDefault(_keccakjs);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function clearDirectory(target) {
return new Promise(function (resolve, reject) {
(0, _mkdirp2.default)(target, function () {
(0, _rimraf2.default)(target, function (err) {
if (err) {
return reject(err);
}
return resolve();
});
});
});
}

function getFunctionSignature(signature) {
return new _keccakjs2.default(256).update(signature).digest('hex').substr(0, 8);
}
Loading

0 comments on commit 70b1c76

Please sign in to comment.