From b9b73753795c5079e5fb9130526221402153cc51 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sat, 5 Aug 2017 14:05:20 -0400 Subject: [PATCH 01/20] add travis --- .travis.yml | 8 ++++++++ README.md | 2 ++ package-lock.json | 15 ++++++++------- package.json | 7 +++++-- 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4efe3dc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: node_js + +node_js: + - "4" + +cache: + directories: + - node_modules diff --git a/README.md b/README.md index 1332289..afa839b 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/package-lock.json b/package-lock.json index 4a256fc..2e538e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -116,7 +116,7 @@ "dev": true, "requires": { "define-properties": "1.1.2", - "es-abstract": "1.7.0" + "es-abstract": "1.8.0" } }, "array-union": { @@ -1224,13 +1224,14 @@ } }, "es-abstract": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.7.0.tgz", - "integrity": "sha1-363ndOAb/Nl/lhgCmMRJyGI/uUw=", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.8.0.tgz", + "integrity": "sha512-Cf9/h5MrXtExM20gSS55YFrGKCyPrRBjIVBtVyy8vmlsDfe0NPKMWj65tPLgzyfPuapWxh5whpXCtW4+AW5mRg==", "dev": true, "requires": { "es-to-primitive": "1.1.1", "function-bind": "1.1.0", + "has": "1.0.1", "is-callable": "1.1.3", "is-regex": "1.0.4" } @@ -1365,9 +1366,9 @@ } }, "eslint-plugin-jsx-a11y": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.0.2.tgz", - "integrity": "sha1-ZZJ3p1iwNsMFp+ShMFfDAc075z8=", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-5.1.1.tgz", + "integrity": "sha512-5I9SpoP7gT4wBFOtXT8/tXNPYohHBVfyVfO17vkbC7r9kEIxYJF12D3pKqhk8+xnk12rfxKClS3WCFpVckFTPQ==", "dev": true, "requires": { "aria-query": "0.7.0", diff --git a/package.json b/package.json index 0ab505e..a96aca3 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,14 @@ "name": "solmd", "version": "0.1.2", "description": "Markdown documentation generator for Solidity", + "engines": { + "node": ">=4" + }, "main": "lib/index.js", "scripts": { "dev": "./node_modules/.bin/babel src -w -d lib", "compile": "rm -rf lib/* && ./node_modules/.bin/babel src -d lib", - "prepublish": "npm run compile", + "prepublishOnly": "npm run compile", "lint": "./node_modules/.bin/eslint src/", "precommit": "npm run lint" }, @@ -35,7 +38,7 @@ "eslint-config-airbnb": "^15.1.0", "eslint-config-airbnb-base": "^11.3.1", "eslint-plugin-import": "^2.7.0", - "eslint-plugin-jsx-a11y": "^6.0.2", + "eslint-plugin-jsx-a11y": "^5.1.1", "eslint-plugin-react": "^7.1.0", "pre-commit": "^1.2.2" }, From 30e44868319a47c2a5b2d3c7ab4ced69e0f48ad8 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sat, 5 Aug 2017 14:24:21 -0400 Subject: [PATCH 02/20] add option --no-toc --- src/bin/solmd.js | 1 + src/constants.js | 3 ++- src/index.js | 6 +++++- src/markdown.js | 22 +++++++++++++++------- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/bin/solmd.js b/src/bin/solmd.js index 87b8640..d0d3553 100755 --- a/src/bin/solmd.js +++ b/src/bin/solmd.js @@ -16,6 +16,7 @@ parameters: --src Folder that contains the contracts you want to compile --dest Destination of markdown output +--no-toc Do not generate table of contents, defaults false `); process.exit(); diff --git a/src/constants.js b/src/constants.js index 0138a91..afd185a 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1 +1,2 @@ -export default 'sol.md'; +export const DEFAULT_DEST = 'sol.md'; +export const DEFAULT_NO_TOC = false; diff --git a/src/index.js b/src/index.js index 8f6ed6e..6bc8c72 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,7 @@ -import DEFAULT_DEST from './constants'; +import { + DEFAULT_DEST, + DEFAULT_NO_TOC, +} from './constants'; import build from './build'; const methods = { @@ -11,6 +14,7 @@ function populateArguments(passed) { const defaults = { dest: DEFAULT_DEST, + 'no-toc': DEFAULT_NO_TOC, }; return { ...defaults, ...modified }; diff --git a/src/markdown.js b/src/markdown.js index 7926905..b2f23a2 100644 --- a/src/markdown.js +++ b/src/markdown.js @@ -3,21 +3,29 @@ import fs from 'fs'; import template from './template'; export default function ({ args, data }) { + // write to dest stream const writeStream = fs.createWriteStream(args.dest, { flags: 'w' }); return new Promise((resolve) => { - data.forEach((contract) => { - writeStream.write(`* [${contract.name}](#${contract.name.toLowerCase()})\n`); - contract.abiDocs.forEach((docItem) => { - if (typeof docItem.name !== 'undefined') { - writeStream.write(` * [${docItem.name}](#${docItem.type}-${docItem.name.toLowerCase()})\n`); - } + // build the table of contents + if (args.notoc) { + data.forEach((contract) => { + // contract name + writeStream.write(`* [${contract.name}](#${contract.name.toLowerCase()})\n`); + // methods (sub-bullets) + contract.abiDocs.forEach((docItem) => { + if (typeof docItem.name !== 'undefined') { + writeStream.write(` * [${docItem.name}](#${docItem.type}-${docItem.name.toLowerCase()})\n`); + } + }); }); - }); + } + // create docs for each contract from template data.forEach((contract) => { const md = template(contract); writeStream.write(md); }); + resolve(writeStream.end()); }); } From 630db5679625108dd608ec64c5c97144c0a2c168 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sat, 5 Aug 2017 15:37:23 -0400 Subject: [PATCH 03/20] add error handling --- src/bin/solmd.js | 6 +++++- src/build.js | 9 ++++++--- src/compile/index.js | 20 ++++++++++++++++---- src/compile/solc.js | 3 ++- src/markdown.js | 17 +++++++++++++---- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/bin/solmd.js b/src/bin/solmd.js index d0d3553..d168877 100755 --- a/src/bin/solmd.js +++ b/src/bin/solmd.js @@ -21,5 +21,9 @@ parameters: `); process.exit(); } else { - Solmd.default.build(args); + Solmd.default.build(args) + .catch((err) => { + console.error(err); // eslint-disable-line no-console + process.exit(1); + }); } diff --git a/src/build.js b/src/build.js index 98e64d8..f54d09d 100644 --- a/src/build.js +++ b/src/build.js @@ -2,7 +2,10 @@ import compile from './compile'; import markdown from './markdown'; export default function (args) { - compile(args).then((data) => { - markdown({ args, data }).then(succ => succ); - }); + return compile(args) + .then(data => markdown({ args, data })) + .catch((err) => { + console.error(err); // eslint-disable-line no-console + process.exit(1); + }); } diff --git a/src/compile/index.js b/src/compile/index.js index c5752d6..a3bc17d 100644 --- a/src/compile/index.js +++ b/src/compile/index.js @@ -1,3 +1,4 @@ +import fs from 'fs'; import parseAbi from './parse-abi'; import solc from './solc'; @@ -20,9 +21,20 @@ function compile({ contracts }) { return data; } - export default function (opts) { - return solc(opts._).then(({ contracts }) => ( - compile({ ...opts, contracts }) - )); + opts._.split(' ').forEach((file) => { + if (!fs.existsSync(file)) { + process.stderr.write(`${file}: No such file or directory +`); + process.exit(1); + } + }); + return solc(opts._) + .then(({ contracts }) => ( + compile({ ...opts, contracts }) + )) + .catch(() => { + console.error(`solmd: Failed to compile contracts at ${opts._}`); // eslint-disable-line no-console + process.exit(1); + }); } diff --git a/src/compile/solc.js b/src/compile/solc.js index 09b57c8..5c5ef30 100644 --- a/src/compile/solc.js +++ b/src/compile/solc.js @@ -3,7 +3,8 @@ import childProcess from 'child_process'; export default function (src) { return new Promise((resolve) => { const exec = `solc --combined-json abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,srcmap,srcmap-runtime,userdoc ${src}`; - const res = JSON.parse(childProcess.execSync(exec)); + const rawRes = childProcess.execSync(exec); + const res = JSON.parse(rawRes); resolve({ contracts: Object.keys(res.contracts).reduce((o, k) => { const file = k.split(':')[0]; diff --git a/src/markdown.js b/src/markdown.js index b2f23a2..5a43223 100644 --- a/src/markdown.js +++ b/src/markdown.js @@ -3,9 +3,17 @@ import fs from 'fs'; import template from './template'; export default function ({ args, data }) { - // write to dest stream - const writeStream = fs.createWriteStream(args.dest, { flags: 'w' }); - return new Promise((resolve) => { + return new Promise((resolve, reject) => { + // write to dest stream + let writeStream; + try { + writeStream = fs.createWriteStream(args.dest, { flags: 'w' }); + } catch (err) { + reject(err); + } + writeStream.on('error', (err) => { + reject(err); + }); // build the table of contents if (args.notoc) { data.forEach((contract) => { @@ -26,6 +34,7 @@ export default function ({ args, data }) { writeStream.write(md); }); - resolve(writeStream.end()); + writeStream.end(); + resolve(); }); } From e58d1f24ecdf966617e294281a304a04f54b3a66 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 6 Aug 2017 15:02:56 -0400 Subject: [PATCH 04/20] fix ouputs --- src/compile/parse-abi.js | 7 +------ src/template.js | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/compile/parse-abi.js b/src/compile/parse-abi.js index e0b75f4..9297d19 100644 --- a/src/compile/parse-abi.js +++ b/src/compile/parse-abi.js @@ -2,7 +2,6 @@ import { getFunctionSignature } from '../helpers'; export default function (contract) { return contract.abi.map((method) => { - // get find relevent docs const inputParams = method.inputs || []; const signature = method.name && `${method.name}(${inputParams.map(i => i.type).join(',')})`; const devDocs = (contract.devdoc.methods || {})[signature] || {}; @@ -14,18 +13,14 @@ export default function (contract) { // don't write this delete devDocs.params; - // START HACK workaround pending https://github.com/ethereum/solidity/issues/1277 - // TODO map outputs properly once compiler splits them out - // in the meantime, use json array - // parse devDocs.return as a json object let outputs; try { const outputParams = JSON.parse(devDocs.return); outputs = method.outputs.map(param => ({ ...param, description: outputParams[param.name] })); } catch (e) { + process.stderr.write(`warning: invalid @return for ${method.name} - output may be effected\n`); outputs = method.outputs; } - // END HACK return { ...method, diff --git a/src/template.js b/src/template.js index b86caa6..9cddede 100644 --- a/src/template.js +++ b/src/template.js @@ -22,7 +22,7 @@ const template = ` | | | | |-|-|-|{{~docItem.outputs :output}} -| {{=output.type}} | {{=output.name}} | {{=output.description}} |{{~}}{{?}}{{?}} +| *{{=output.type}}* | {{=output.name}} | {{=output.description}} |{{~}}{{?}}{{?}} {{~}} ---`; From 2e6ab6c93a75ec67cc5e1adb0cfcf9eff8b554f3 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 6 Aug 2017 15:03:06 -0400 Subject: [PATCH 05/20] update readme --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index afa839b..40fc4e8 100644 --- a/README.md +++ b/README.md @@ -33,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. ``` @@ -53,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()** @@ -68,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 | + --- ``` From 9d7bc43365054b79cbdd0bb7aa44c49ef2305391 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 6 Aug 2017 15:11:27 -0400 Subject: [PATCH 06/20] add dummy test --- test/solmd.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/solmd.test.js diff --git a/test/solmd.test.js b/test/solmd.test.js new file mode 100644 index 0000000..91a5529 --- /dev/null +++ b/test/solmd.test.js @@ -0,0 +1,8 @@ +/* eslint-env node, mocha */ +const assert = require('assert'); + +describe('solmd', () => { + it('dummy tests', () => { + assert.equal(0, 0, 'true'); + }); +}); From 9c039ac47eca0c16e3689d833ddf07771e3e1ac8 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 6 Aug 2017 15:11:54 -0400 Subject: [PATCH 07/20] add mocha --- package-lock.json | 218 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 + 2 files changed, 221 insertions(+) diff --git a/package-lock.json b/package-lock.json index 2e538e2..e90406e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -147,6 +147,12 @@ "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", "dev": true }, + "assertion-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.2.tgz", + "integrity": "sha1-E8pRXYYgbaC6xm6DTdOX2HWBCUw=", + "dev": true + }, "ast-types-flow": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/ast-types-flow/-/ast-types-flow-0.0.7.tgz", @@ -979,6 +985,12 @@ "repeat-element": "1.1.2" } }, + "browser-stdout": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz", + "integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=", + "dev": true + }, "browserify-sha3": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/browserify-sha3/-/browserify-sha3-0.0.1.tgz", @@ -1008,6 +1020,20 @@ "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=", "dev": true }, + "chai": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.1.1.tgz", + "integrity": "sha1-ZuISeebzxkFf+CMYeCJ5AOIXGzk=", + "dev": true, + "requires": { + "assertion-error": "1.0.2", + "check-error": "1.0.2", + "deep-eql": "2.0.2", + "get-func-name": "2.0.0", + "pathval": "1.1.0", + "type-detect": "4.0.3" + } + }, "chalk": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", @@ -1021,6 +1047,12 @@ "supports-color": "2.0.0" } }, + "check-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "dev": true + }, "chokidar": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-1.7.0.tgz", @@ -1153,6 +1185,23 @@ "ms": "2.0.0" } }, + "deep-eql": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-2.0.2.tgz", + "integrity": "sha1-sbrAblbwp2d3aG1Qyf63XC7XZ5o=", + "dev": true, + "requires": { + "type-detect": "3.0.0" + }, + "dependencies": { + "type-detect": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-3.0.0.tgz", + "integrity": "sha1-RtDMhVOrt7E6NSsNbeov1Y8tm1U=", + "dev": true + } + } + }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", @@ -1193,6 +1242,12 @@ "repeating": "2.0.1" } }, + "diff": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz", + "integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=", + "dev": true + }, "doctrine": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.0.0.tgz", @@ -2514,6 +2569,12 @@ "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, + "get-func-name": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "dev": true + }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", @@ -2573,6 +2634,18 @@ "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", "dev": true }, + "graceful-readlink": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", + "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=", + "dev": true + }, + "growl": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz", + "integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=", + "dev": true + }, "has": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/has/-/has-1.0.1.tgz", @@ -2966,6 +3039,12 @@ "jsonify": "0.0.0" } }, + "json3": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz", + "integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE=", + "dev": true + }, "json5": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz", @@ -3048,12 +3127,80 @@ "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=", "dev": true }, + "lodash._baseassign": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz", + "integrity": "sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4=", + "dev": true, + "requires": { + "lodash._basecopy": "3.0.1", + "lodash.keys": "3.1.2" + } + }, + "lodash._basecopy": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz", + "integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=", + "dev": true + }, + "lodash._basecreate": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz", + "integrity": "sha1-G8ZhYU2qf8MRt9A78WgGoCE8+CE=", + "dev": true + }, + "lodash._getnative": { + "version": "3.9.1", + "resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz", + "integrity": "sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=", + "dev": true + }, + "lodash._isiterateecall": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz", + "integrity": "sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw=", + "dev": true + }, "lodash.cond": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/lodash.cond/-/lodash.cond-4.5.2.tgz", "integrity": "sha1-9HGh2khr5g9quVXRcRVSPdHSVdU=", "dev": true }, + "lodash.create": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/lodash.create/-/lodash.create-3.1.1.tgz", + "integrity": "sha1-1/KEnw29p+BGgruM1yqwIkYd6+c=", + "dev": true, + "requires": { + "lodash._baseassign": "3.2.0", + "lodash._basecreate": "3.0.3", + "lodash._isiterateecall": "3.0.9" + } + }, + "lodash.isarguments": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz", + "integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=", + "dev": true + }, + "lodash.isarray": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz", + "integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=", + "dev": true + }, + "lodash.keys": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz", + "integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=", + "dev": true, + "requires": { + "lodash._getnative": "3.9.1", + "lodash.isarguments": "3.1.0", + "lodash.isarray": "3.0.4" + } + }, "loose-envify": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz", @@ -3129,6 +3276,65 @@ } } }, + "mocha": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-3.5.0.tgz", + "integrity": "sha512-pIU2PJjrPYvYRqVpjXzj76qltO9uBYI7woYAMoxbSefsa+vqAfptjoeevd6bUgwD0mPIO+hv9f7ltvsNreL2PA==", + "dev": true, + "requires": { + "browser-stdout": "1.3.0", + "commander": "2.9.0", + "debug": "2.6.8", + "diff": "3.2.0", + "escape-string-regexp": "1.0.5", + "glob": "7.1.1", + "growl": "1.9.2", + "json3": "3.3.2", + "lodash.create": "3.1.1", + "mkdirp": "0.5.1", + "supports-color": "3.1.2" + }, + "dependencies": { + "commander": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", + "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=", + "dev": true, + "requires": { + "graceful-readlink": "1.0.1" + } + }, + "glob": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz", + "integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=", + "dev": true, + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "has-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-1.0.0.tgz", + "integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=", + "dev": true + }, + "supports-color": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.1.2.tgz", + "integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=", + "dev": true, + "requires": { + "has-flag": "1.0.0" + } + } + } + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -3334,6 +3540,12 @@ "pify": "2.3.0" } }, + "pathval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", + "dev": true + }, "pify": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", @@ -3935,6 +4147,12 @@ "prelude-ls": "1.1.2" } }, + "type-detect": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.3.tgz", + "integrity": "sha1-Dj8mcLRAmbC0bChNE2p+9Jx0wuo=", + "dev": true + }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", diff --git a/package.json b/package.json index a96aca3..298dd3d 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "main": "lib/index.js", "scripts": { "dev": "./node_modules/.bin/babel src -w -d lib", + "test": "./node_modules/.bin/mocha", "compile": "rm -rf lib/* && ./node_modules/.bin/babel src -d lib", "prepublishOnly": "npm run compile", "lint": "./node_modules/.bin/eslint src/", @@ -34,12 +35,14 @@ "babel-eslint": "^7.2.3", "babel-preset-es2015": "^6.24.1", "babel-preset-stage-2": "^6.24.1", + "chai": "^4.1.1", "eslint": "^4.3.0", "eslint-config-airbnb": "^15.1.0", "eslint-config-airbnb-base": "^11.3.1", "eslint-plugin-import": "^2.7.0", "eslint-plugin-jsx-a11y": "^5.1.1", "eslint-plugin-react": "^7.1.0", + "mocha": "^3.5.0", "pre-commit": "^1.2.2" }, "dependencies": { From 2f76788e23f2a918c65eb21b39b14140d0bcdc83 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 6 Aug 2017 15:13:39 -0400 Subject: [PATCH 08/20] add precommit --- package-lock.json | 219 +++++++++++++++++++++++++++++++++++++++++++++- package.json | 8 +- 2 files changed, 222 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index e90406e..cc565f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -159,6 +159,12 @@ "integrity": "sha1-9wtzXGvKGlycItmCw+Oef+ujva0=", "dev": true }, + "async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=", + "dev": true + }, "async-each": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.1.tgz", @@ -1092,6 +1098,33 @@ "integrity": "sha1-sjTKIJsp72b8UY2bmNWEewDt8Ao=", "dev": true }, + "clix": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/clix/-/clix-2.2.1.tgz", + "integrity": "sha1-E8A4lBTfUZR6rphYBE/emC3dlS4=", + "dev": true, + "requires": { + "clix-logger": "1.0.0", + "extend": "3.0.0", + "glob-expand": "0.2.1", + "jq-trim": "0.1.2", + "optionator": "0.8.2", + "os-homedir": "1.0.2", + "path-is-absolute": "1.0.1", + "read-json-sync": "1.1.1" + } + }, + "clix-logger": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/clix-logger/-/clix-logger-1.0.0.tgz", + "integrity": "sha1-HljPpNCXTSHXSaOjfM93W+b71aU=", + "dev": true, + "requires": { + "chalk": "1.1.3", + "extend": "3.0.0", + "moment": "2.17.1" + } + }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -1263,6 +1296,24 @@ "resolved": "https://registry.npmjs.org/dot/-/dot-1.1.2.tgz", "integrity": "sha1-xzdwGfxOVQeYkosrmv62ar+h8vk=" }, + "each-async": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/each-async/-/each-async-1.1.1.tgz", + "integrity": "sha1-3uUim98KtrogEqOV4bhpq/iBNHM=", + "dev": true, + "requires": { + "onetime": "1.1.0", + "set-immediate-shim": "1.0.1" + }, + "dependencies": { + "onetime": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", + "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", + "dev": true + } + } + }, "emoji-regex": { "version": "6.5.1", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-6.5.1.tgz", @@ -1302,6 +1353,12 @@ "is-symbol": "1.0.1" } }, + "es6-promise": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz", + "integrity": "sha1-oIzd6EzNvzTQJ6FFG8kdS80ophM=", + "dev": true + }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -1529,6 +1586,12 @@ "fill-range": "2.2.3" } }, + "extend": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.0.tgz", + "integrity": "sha1-WkdDU7nzNT3dgXbf03uRyDpG8dQ=", + "dev": true + }, "external-editor": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.0.4.tgz", @@ -2575,6 +2638,16 @@ "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", "dev": true }, + "git-toplevel": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/git-toplevel/-/git-toplevel-1.1.1.tgz", + "integrity": "sha1-04ecbKYSDIyxgMUoQglMDMnq2so=", + "dev": true, + "requires": { + "es6-promise": "3.3.1", + "jq-trim": "0.1.2" + } + }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", @@ -2599,6 +2672,45 @@ "is-glob": "2.0.1" } }, + "glob-expand": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/glob-expand/-/glob-expand-0.2.1.tgz", + "integrity": "sha1-GwiKwnK1cViHC3aBYRHaRhimag8=", + "dev": true, + "requires": { + "glob": "4.5.3", + "lodash": "4.13.1" + }, + "dependencies": { + "glob": { + "version": "4.5.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-4.5.3.tgz", + "integrity": "sha1-xstz0yJsHv7wTePFbQEvAzd+4V8=", + "dev": true, + "requires": { + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "2.0.10", + "once": "1.4.0" + } + }, + "lodash": { + "version": "4.13.1", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.13.1.tgz", + "integrity": "sha1-g+SxCRP0hJbU0W/sSlYK8u50S2g=", + "dev": true + }, + "minimatch": { + "version": "2.0.10", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-2.0.10.tgz", + "integrity": "sha1-jQh8OcazjAAbl/ynzm0OHoCvusc=", + "dev": true, + "requires": { + "brace-expansion": "1.1.8" + } + } + } + }, "glob-parent": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-2.0.0.tgz", @@ -2991,6 +3103,12 @@ "isarray": "1.0.0" } }, + "jq-trim": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/jq-trim/-/jq-trim-0.1.2.tgz", + "integrity": "sha1-h9km2UTTm9S0mcuDfDV2qRC1hhg=", + "dev": true + }, "js-sha3": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.3.1.tgz", @@ -3335,6 +3453,12 @@ } } }, + "moment": { + "version": "2.17.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.17.1.tgz", + "integrity": "sha1-/tlQYGPzaxDwZsi1mhRNf66+HYI=", + "dev": true + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -3593,6 +3717,77 @@ "which": "1.2.14" } }, + "precommit": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/precommit/-/precommit-1.2.2.tgz", + "integrity": "sha1-1SeE7kcJcgGu1pd4g7EycTZLkxU=", + "dev": true, + "requires": { + "clix": "2.2.1", + "del": "1.2.1", + "es6-promise": "3.3.1", + "git-toplevel": "1.1.1", + "read-file": "0.2.0", + "stringformat": "0.0.5", + "write": "0.1.1" + }, + "dependencies": { + "del": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/del/-/del-1.2.1.tgz", + "integrity": "sha1-rtblvNfLcyXfNPVjEl+iZbLBoBQ=", + "dev": true, + "requires": { + "each-async": "1.1.1", + "globby": "2.1.0", + "is-path-cwd": "1.0.0", + "is-path-in-cwd": "1.0.0", + "object-assign": "3.0.0", + "rimraf": "2.6.1" + } + }, + "glob": { + "version": "5.0.15", + "resolved": "https://registry.npmjs.org/glob/-/glob-5.0.15.tgz", + "integrity": "sha1-G8k2ueAvSmA/zCIuz3Yz0wuLk7E=", + "dev": true, + "requires": { + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "globby": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-2.1.0.tgz", + "integrity": "sha1-npGSvNM/Srak+JTl5+qLcTITxII=", + "dev": true, + "requires": { + "array-union": "1.0.2", + "async": "1.5.2", + "glob": "5.0.15", + "object-assign": "3.0.0" + } + }, + "object-assign": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", + "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", + "dev": true + }, + "write": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/write/-/write-0.1.1.tgz", + "integrity": "sha1-6pZcx0R8SCGUuNhLu3ua37gCAqg=", + "dev": true, + "requires": { + "mkdirp": "0.5.1" + } + } + } + }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", @@ -3675,6 +3870,21 @@ } } }, + "read-file": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/read-file/-/read-file-0.2.0.tgz", + "integrity": "sha1-cMa6+IQux9FUD5gf0Oau1Mgb1UU=", + "dev": true + }, + "read-json-sync": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/read-json-sync/-/read-json-sync-1.1.1.tgz", + "integrity": "sha1-Q8ZproZKrjCN+7snIaZ+KV7I//Y=", + "dev": true, + "requires": { + "graceful-fs": "4.1.11" + } + }, "read-pkg": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", @@ -3914,8 +4124,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz", "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=", - "dev": true, - "optional": true + "dev": true }, "sha3": { "version": "1.2.0", @@ -4046,6 +4255,12 @@ } } }, + "stringformat": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/stringformat/-/stringformat-0.0.5.tgz", + "integrity": "sha1-g8L+y9dm3UVvlC5PavgGG//YfxI=", + "dev": true + }, "strip-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", diff --git a/package.json b/package.json index 298dd3d..c9a2c08 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "compile": "rm -rf lib/* && ./node_modules/.bin/babel src -d lib", "prepublishOnly": "npm run compile", "lint": "./node_modules/.bin/eslint src/", - "precommit": "npm run lint" + "precommit": "npm run lint && npm run test" }, "bin": { "solmd": "./lib/bin/solmd.js" @@ -43,7 +43,8 @@ "eslint-plugin-jsx-a11y": "^5.1.1", "eslint-plugin-react": "^7.1.0", "mocha": "^3.5.0", - "pre-commit": "^1.2.2" + "pre-commit": "^1.2.2", + "precommit": "^1.2.2" }, "dependencies": { "dot": "^1.1.2", @@ -53,6 +54,7 @@ "rimraf": "^2.6.1" }, "pre-commit": [ - "lint" + "lint", + "test" ] } From 4532e10f5bd01a16e81d593225c1b84eb1736509 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 12:28:52 -0400 Subject: [PATCH 09/20] resolve promise when write stream done --- src/markdown.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/markdown.js b/src/markdown.js index 5a43223..013c819 100644 --- a/src/markdown.js +++ b/src/markdown.js @@ -14,6 +14,9 @@ export default function ({ args, data }) { writeStream.on('error', (err) => { reject(err); }); + writeStream.on('finish', () => { + resolve(); + }); // build the table of contents if (args.notoc) { data.forEach((contract) => { @@ -35,6 +38,5 @@ export default function ({ args, data }) { }); writeStream.end(); - resolve(); }); } From dbfb38f358f33c5d0a78d2c4a71f99a407b219c2 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 12:29:31 -0400 Subject: [PATCH 10/20] add GavCoin test --- .gitignore | 3 ++- test/contracts/GavCoin.sol | 30 ++++++++++++++++++++++++++++ test/expected.js | 41 ++++++++++++++++++++++++++++++++++++++ test/solmd.test.js | 14 +++++++++++-- 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 test/contracts/GavCoin.sol create mode 100644 test/expected.js diff --git a/.gitignore b/.gitignore index 105add8..79c172e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *~ node_modules lib -contracts +/contracts .solmd sol.md +test/output.md diff --git a/test/contracts/GavCoin.sol b/test/contracts/GavCoin.sol new file mode 100644 index 0000000..55fc1e8 --- /dev/null +++ b/test/contracts/GavCoin.sol @@ -0,0 +1,30 @@ +pragma solidity ^0.4.13; + + +// natspec example +/** +@title GavCoin +@author Gavin Wood +*/ +contract GavCoin { + mapping (address => uint256) public balances; + address owner; + + function GavCoin() { + owner = msg.sender; + } + + /** + @notice Send `(valueInmGAV / 1000).fixed(0,3)` GAV from the account of + `message.caller.address()`, to an account accessible only by `to.address() + @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 + */ + function send(address to, uint256 valueInmGAV) { + if (balances[msg.sender] >= valueInmGAV) { + balances[to] += valueInmGAV; + balances[msg.sender] -= valueInmGAV; + } + } +} diff --git a/test/expected.js b/test/expected.js new file mode 100644 index 0000000..ad4e9eb --- /dev/null +++ b/test/expected.js @@ -0,0 +1,41 @@ +const GavCoin = ` +# GavCoin + +Gavin Wood + +## *function* balances + +GavCoin.balances() \`27e235e3\` + + +Inputs + +| | | | +|-|-|-| +| *address* | | undefined | +Outputs + +| | | | +|-|-|-| +| *uint256* | | undefined | + +## *function* send + +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()** + +> This should be the documentation of the function for the developer docs + +Inputs + +| | | | +|-|-|-| +| *address* | to | The address of the recipient of the GavCoin | +| *uint256* | valueInmGAV | The GavCoin value to send | + + + +---`; + +module.exports = { GavCoin }; diff --git a/test/solmd.test.js b/test/solmd.test.js index 91a5529..ad9cbb2 100644 --- a/test/solmd.test.js +++ b/test/solmd.test.js @@ -1,8 +1,18 @@ /* eslint-env node, mocha */ const assert = require('assert'); +const minimist = require('minimist'); +const fs = require('fs'); +const Solmd = require('../lib'); +const expected = require('./expected'); describe('solmd', () => { - it('dummy tests', () => { - assert.equal(0, 0, 'true'); + it('GavCoin', () => { + const args = minimist(['test/contracts/GavCoin.sol', '--dest', 'test/output.md']); + return Solmd.default.build(args) + .then(() => fs.readFileSync('./test/output.md', 'utf8')) + .then((res) => { + console.log(res); + assert.equal(res, expected.GavCoin, 'did not produce the correct output'); + }); }); }); From 759c4e011a37057eb76a65956da6bfc6911544ef Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 12:32:26 -0400 Subject: [PATCH 11/20] fix package and lint --- package.json | 10 +++++----- test/solmd.test.js | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index c9a2c08..d600b4d 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,12 @@ }, "main": "lib/index.js", "scripts": { - "dev": "./node_modules/.bin/babel src -w -d lib", - "test": "./node_modules/.bin/mocha", - "compile": "rm -rf lib/* && ./node_modules/.bin/babel src -d lib", + "dev": "$(npm bin)/babel src -w -d lib", + "test": "$(npm bin)/mocha", + "compile": "rm -rf lib/* && $(npm bin)/babel src -d lib", "prepublishOnly": "npm run compile", - "lint": "./node_modules/.bin/eslint src/", - "precommit": "npm run lint && npm run test" + "lint": "$(npm bin)/eslint src/ test/", + "precommit": "./node_modules/pre-commit/hook" }, "bin": { "solmd": "./lib/bin/solmd.js" diff --git a/test/solmd.test.js b/test/solmd.test.js index ad9cbb2..faae05a 100644 --- a/test/solmd.test.js +++ b/test/solmd.test.js @@ -11,7 +11,6 @@ describe('solmd', () => { return Solmd.default.build(args) .then(() => fs.readFileSync('./test/output.md', 'utf8')) .then((res) => { - console.log(res); assert.equal(res, expected.GavCoin, 'did not produce the correct output'); }); }); From efa0fc8446b26f8f2293529e2c96e60c9013b0a6 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 12:35:40 -0400 Subject: [PATCH 12/20] remove chai --- package-lock.json | 280 +--------------------------------------------- package.json | 4 +- 2 files changed, 3 insertions(+), 281 deletions(-) diff --git a/package-lock.json b/package-lock.json index cc565f8..363ab2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -147,24 +147,12 @@ "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", "dev": true }, - "assertion-error": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.2.tgz", - "integrity": "sha1-E8pRXYYgbaC6xm6DTdOX2HWBCUw=", - "dev": true - }, "ast-types-flow": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/ast-types-flow/-/ast-types-flow-0.0.7.tgz", "integrity": "sha1-9wtzXGvKGlycItmCw+Oef+ujva0=", "dev": true }, - "async": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", - "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=", - "dev": true - }, "async-each": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.1.tgz", @@ -1026,20 +1014,6 @@ "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=", "dev": true }, - "chai": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.1.1.tgz", - "integrity": "sha1-ZuISeebzxkFf+CMYeCJ5AOIXGzk=", - "dev": true, - "requires": { - "assertion-error": "1.0.2", - "check-error": "1.0.2", - "deep-eql": "2.0.2", - "get-func-name": "2.0.0", - "pathval": "1.1.0", - "type-detect": "4.0.3" - } - }, "chalk": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", @@ -1053,12 +1027,6 @@ "supports-color": "2.0.0" } }, - "check-error": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", - "dev": true - }, "chokidar": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-1.7.0.tgz", @@ -1098,33 +1066,6 @@ "integrity": "sha1-sjTKIJsp72b8UY2bmNWEewDt8Ao=", "dev": true }, - "clix": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/clix/-/clix-2.2.1.tgz", - "integrity": "sha1-E8A4lBTfUZR6rphYBE/emC3dlS4=", - "dev": true, - "requires": { - "clix-logger": "1.0.0", - "extend": "3.0.0", - "glob-expand": "0.2.1", - "jq-trim": "0.1.2", - "optionator": "0.8.2", - "os-homedir": "1.0.2", - "path-is-absolute": "1.0.1", - "read-json-sync": "1.1.1" - } - }, - "clix-logger": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/clix-logger/-/clix-logger-1.0.0.tgz", - "integrity": "sha1-HljPpNCXTSHXSaOjfM93W+b71aU=", - "dev": true, - "requires": { - "chalk": "1.1.3", - "extend": "3.0.0", - "moment": "2.17.1" - } - }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -1218,23 +1159,6 @@ "ms": "2.0.0" } }, - "deep-eql": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-2.0.2.tgz", - "integrity": "sha1-sbrAblbwp2d3aG1Qyf63XC7XZ5o=", - "dev": true, - "requires": { - "type-detect": "3.0.0" - }, - "dependencies": { - "type-detect": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-3.0.0.tgz", - "integrity": "sha1-RtDMhVOrt7E6NSsNbeov1Y8tm1U=", - "dev": true - } - } - }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", @@ -1296,24 +1220,6 @@ "resolved": "https://registry.npmjs.org/dot/-/dot-1.1.2.tgz", "integrity": "sha1-xzdwGfxOVQeYkosrmv62ar+h8vk=" }, - "each-async": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/each-async/-/each-async-1.1.1.tgz", - "integrity": "sha1-3uUim98KtrogEqOV4bhpq/iBNHM=", - "dev": true, - "requires": { - "onetime": "1.1.0", - "set-immediate-shim": "1.0.1" - }, - "dependencies": { - "onetime": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz", - "integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=", - "dev": true - } - } - }, "emoji-regex": { "version": "6.5.1", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-6.5.1.tgz", @@ -1353,12 +1259,6 @@ "is-symbol": "1.0.1" } }, - "es6-promise": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz", - "integrity": "sha1-oIzd6EzNvzTQJ6FFG8kdS80ophM=", - "dev": true - }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -1586,12 +1486,6 @@ "fill-range": "2.2.3" } }, - "extend": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.0.tgz", - "integrity": "sha1-WkdDU7nzNT3dgXbf03uRyDpG8dQ=", - "dev": true - }, "external-editor": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.0.4.tgz", @@ -2632,22 +2526,6 @@ "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, - "get-func-name": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", - "dev": true - }, - "git-toplevel": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/git-toplevel/-/git-toplevel-1.1.1.tgz", - "integrity": "sha1-04ecbKYSDIyxgMUoQglMDMnq2so=", - "dev": true, - "requires": { - "es6-promise": "3.3.1", - "jq-trim": "0.1.2" - } - }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", @@ -2672,45 +2550,6 @@ "is-glob": "2.0.1" } }, - "glob-expand": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/glob-expand/-/glob-expand-0.2.1.tgz", - "integrity": "sha1-GwiKwnK1cViHC3aBYRHaRhimag8=", - "dev": true, - "requires": { - "glob": "4.5.3", - "lodash": "4.13.1" - }, - "dependencies": { - "glob": { - "version": "4.5.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-4.5.3.tgz", - "integrity": "sha1-xstz0yJsHv7wTePFbQEvAzd+4V8=", - "dev": true, - "requires": { - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "2.0.10", - "once": "1.4.0" - } - }, - "lodash": { - "version": "4.13.1", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.13.1.tgz", - "integrity": "sha1-g+SxCRP0hJbU0W/sSlYK8u50S2g=", - "dev": true - }, - "minimatch": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-2.0.10.tgz", - "integrity": "sha1-jQh8OcazjAAbl/ynzm0OHoCvusc=", - "dev": true, - "requires": { - "brace-expansion": "1.1.8" - } - } - } - }, "glob-parent": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-2.0.0.tgz", @@ -3103,12 +2942,6 @@ "isarray": "1.0.0" } }, - "jq-trim": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/jq-trim/-/jq-trim-0.1.2.tgz", - "integrity": "sha1-h9km2UTTm9S0mcuDfDV2qRC1hhg=", - "dev": true - }, "js-sha3": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.3.1.tgz", @@ -3453,12 +3286,6 @@ } } }, - "moment": { - "version": "2.17.1", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.17.1.tgz", - "integrity": "sha1-/tlQYGPzaxDwZsi1mhRNf66+HYI=", - "dev": true - }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -3664,12 +3491,6 @@ "pify": "2.3.0" } }, - "pathval": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", - "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", - "dev": true - }, "pify": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", @@ -3717,77 +3538,6 @@ "which": "1.2.14" } }, - "precommit": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/precommit/-/precommit-1.2.2.tgz", - "integrity": "sha1-1SeE7kcJcgGu1pd4g7EycTZLkxU=", - "dev": true, - "requires": { - "clix": "2.2.1", - "del": "1.2.1", - "es6-promise": "3.3.1", - "git-toplevel": "1.1.1", - "read-file": "0.2.0", - "stringformat": "0.0.5", - "write": "0.1.1" - }, - "dependencies": { - "del": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/del/-/del-1.2.1.tgz", - "integrity": "sha1-rtblvNfLcyXfNPVjEl+iZbLBoBQ=", - "dev": true, - "requires": { - "each-async": "1.1.1", - "globby": "2.1.0", - "is-path-cwd": "1.0.0", - "is-path-in-cwd": "1.0.0", - "object-assign": "3.0.0", - "rimraf": "2.6.1" - } - }, - "glob": { - "version": "5.0.15", - "resolved": "https://registry.npmjs.org/glob/-/glob-5.0.15.tgz", - "integrity": "sha1-G8k2ueAvSmA/zCIuz3Yz0wuLk7E=", - "dev": true, - "requires": { - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - }, - "globby": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-2.1.0.tgz", - "integrity": "sha1-npGSvNM/Srak+JTl5+qLcTITxII=", - "dev": true, - "requires": { - "array-union": "1.0.2", - "async": "1.5.2", - "glob": "5.0.15", - "object-assign": "3.0.0" - } - }, - "object-assign": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", - "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", - "dev": true - }, - "write": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/write/-/write-0.1.1.tgz", - "integrity": "sha1-6pZcx0R8SCGUuNhLu3ua37gCAqg=", - "dev": true, - "requires": { - "mkdirp": "0.5.1" - } - } - } - }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", @@ -3870,21 +3620,6 @@ } } }, - "read-file": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/read-file/-/read-file-0.2.0.tgz", - "integrity": "sha1-cMa6+IQux9FUD5gf0Oau1Mgb1UU=", - "dev": true - }, - "read-json-sync": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/read-json-sync/-/read-json-sync-1.1.1.tgz", - "integrity": "sha1-Q8ZproZKrjCN+7snIaZ+KV7I//Y=", - "dev": true, - "requires": { - "graceful-fs": "4.1.11" - } - }, "read-pkg": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", @@ -4124,7 +3859,8 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz", "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=", - "dev": true + "dev": true, + "optional": true }, "sha3": { "version": "1.2.0", @@ -4255,12 +3991,6 @@ } } }, - "stringformat": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/stringformat/-/stringformat-0.0.5.tgz", - "integrity": "sha1-g8L+y9dm3UVvlC5PavgGG//YfxI=", - "dev": true - }, "strip-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", @@ -4362,12 +4092,6 @@ "prelude-ls": "1.1.2" } }, - "type-detect": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.3.tgz", - "integrity": "sha1-Dj8mcLRAmbC0bChNE2p+9Jx0wuo=", - "dev": true - }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", diff --git a/package.json b/package.json index d600b4d..1ed85cc 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "babel-eslint": "^7.2.3", "babel-preset-es2015": "^6.24.1", "babel-preset-stage-2": "^6.24.1", - "chai": "^4.1.1", "eslint": "^4.3.0", "eslint-config-airbnb": "^15.1.0", "eslint-config-airbnb-base": "^11.3.1", @@ -43,8 +42,7 @@ "eslint-plugin-jsx-a11y": "^5.1.1", "eslint-plugin-react": "^7.1.0", "mocha": "^3.5.0", - "pre-commit": "^1.2.2", - "precommit": "^1.2.2" + "pre-commit": "^1.2.2" }, "dependencies": { "dot": "^1.1.2", From ffb46b0747b41e8323fd18bd2363892b98591c2f Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 12:55:11 -0400 Subject: [PATCH 13/20] update packages --- package-lock.json | 25 ++++++++++++++++++------- package.json | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 363ab2b..4ee6f83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1378,9 +1378,9 @@ } }, "eslint-plugin-jsx-a11y": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-5.1.1.tgz", - "integrity": "sha512-5I9SpoP7gT4wBFOtXT8/tXNPYohHBVfyVfO17vkbC7r9kEIxYJF12D3pKqhk8+xnk12rfxKClS3WCFpVckFTPQ==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.0.2.tgz", + "integrity": "sha1-ZZJ3p1iwNsMFp+ShMFfDAc075z8=", "dev": true, "requires": { "aria-query": "0.7.0", @@ -1393,14 +1393,25 @@ } }, "eslint-plugin-react": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.1.0.tgz", - "integrity": "sha1-J3cKzzn1/UnNCvQIPOWBBOs5DUw=", + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.2.1.tgz", + "integrity": "sha512-7hN8YJO7bkxPdPfuSRz+xWKC0xk1BBp8yn8ehXaxklcMFdIoIQnhtBXc3iv042CGQH4LbKFMgDdOAjoAnnqr7Q==", "dev": true, "requires": { "doctrine": "2.0.0", "has": "1.0.1", - "jsx-ast-utils": "1.4.1" + "jsx-ast-utils": "2.0.0" + }, + "dependencies": { + "jsx-ast-utils": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.0.0.tgz", + "integrity": "sha1-7Aaj1gzzB+XhGdrHutgeifCW8Pg=", + "dev": true, + "requires": { + "array-includes": "3.0.3" + } + } } }, "eslint-restricted-globals": { diff --git a/package.json b/package.json index 1ed85cc..d20eb2a 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "eslint-config-airbnb": "^15.1.0", "eslint-config-airbnb-base": "^11.3.1", "eslint-plugin-import": "^2.7.0", - "eslint-plugin-jsx-a11y": "^5.1.1", + "eslint-plugin-jsx-a11y": "^6.0.2", "eslint-plugin-react": "^7.1.0", "mocha": "^3.5.0", "pre-commit": "^1.2.2" From 4db42a9a5827206f6710d6de94399f323373998b Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 13:03:58 -0400 Subject: [PATCH 14/20] add lib to tracking --- .gitignore | 4 --- .npmignore | 4 --- lib/bin/solmd.js | 37 +++++++++++++++++++++++++ lib/build.js | 24 ++++++++++++++++ lib/compile/index.js | 60 ++++++++++++++++++++++++++++++++++++++++ lib/compile/parse-abi.js | 49 ++++++++++++++++++++++++++++++++ lib/compile/solc.js | 38 +++++++++++++++++++++++++ lib/constants.js | 7 +++++ lib/helpers.js | 38 +++++++++++++++++++++++++ lib/index.js | 41 +++++++++++++++++++++++++++ lib/markdown.js | 57 ++++++++++++++++++++++++++++++++++++++ lib/template.js | 17 ++++++++++++ package.json | 4 +-- 13 files changed, 370 insertions(+), 10 deletions(-) create mode 100755 lib/bin/solmd.js create mode 100644 lib/build.js create mode 100644 lib/compile/index.js create mode 100644 lib/compile/parse-abi.js create mode 100644 lib/compile/solc.js create mode 100644 lib/constants.js create mode 100644 lib/helpers.js create mode 100644 lib/index.js create mode 100644 lib/markdown.js create mode 100644 lib/template.js diff --git a/.gitignore b/.gitignore index 79c172e..940fe46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ *~ node_modules -lib -/contracts -.solmd sol.md -test/output.md diff --git a/.npmignore b/.npmignore index cd0a5d6..85de9cf 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1 @@ -*~ src -contracts -.solmd -sol.md diff --git a/lib/bin/solmd.js b/lib/bin/solmd.js new file mode 100755 index 0000000..a0b5b7a --- /dev/null +++ b/lib/bin/solmd.js @@ -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 ] [--dest ]\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); + }); +} \ No newline at end of file diff --git a/lib/build.js b/lib/build.js new file mode 100644 index 0000000..26a4489 --- /dev/null +++ b/lib/build.js @@ -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 }; } \ No newline at end of file diff --git a/lib/compile/index.js b/lib/compile/index.js new file mode 100644 index 0000000..d512282 --- /dev/null +++ b/lib/compile/index.js @@ -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; +} \ No newline at end of file diff --git a/lib/compile/parse-abi.js b/lib/compile/parse-abi.js new file mode 100644 index 0000000..694eeea --- /dev/null +++ b/lib/compile/parse-abi.js @@ -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'); \ No newline at end of file diff --git a/lib/compile/solc.js b/lib/compile/solc.js new file mode 100644 index 0000000..84610c1 --- /dev/null +++ b/lib/compile/solc.js @@ -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; } \ No newline at end of file diff --git a/lib/constants.js b/lib/constants.js new file mode 100644 index 0000000..53c6bb7 --- /dev/null +++ b/lib/constants.js @@ -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; \ No newline at end of file diff --git a/lib/helpers.js b/lib/helpers.js new file mode 100644 index 0000000..7a6a342 --- /dev/null +++ b/lib/helpers.js @@ -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); +} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..cdbf7a4 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,41 @@ +'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; }; + +var _constants = require('./constants'); + +var _build = require('./build'); + +var _build2 = _interopRequireDefault(_build); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var methods = { + build: _build2.default +}; + +function populateArguments(passed) { + var modified = passed; + modified._ = modified._.join(' '); + + var defaults = { + dest: _constants.DEFAULT_DEST, + 'no-toc': _constants.DEFAULT_NO_TOC + }; + + return _extends({}, defaults, modified); +} + +var wrappedMethods = {}; +Object.keys(methods).forEach(function (key) { + wrappedMethods[key] = function (args) { + var newArgs = populateArguments(args); + return methods[key](newArgs); + }; +}); + +exports.default = wrappedMethods; \ No newline at end of file diff --git a/lib/markdown.js b/lib/markdown.js new file mode 100644 index 0000000..447bd1f --- /dev/null +++ b/lib/markdown.js @@ -0,0 +1,57 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +exports.default = function (_ref) { + var args = _ref.args, + data = _ref.data; + + return new Promise(function (resolve, reject) { + // write to dest stream + var writeStream = void 0; + try { + writeStream = _fs2.default.createWriteStream(args.dest, { flags: 'w' }); + } catch (err) { + reject(err); + } + writeStream.on('error', function (err) { + reject(err); + }); + writeStream.on('finish', function () { + resolve(); + }); + // build the table of contents + if (args.notoc) { + data.forEach(function (contract) { + // contract name + writeStream.write('* [' + contract.name + '](#' + contract.name.toLowerCase() + ')\n'); + // methods (sub-bullets) + contract.abiDocs.forEach(function (docItem) { + if (typeof docItem.name !== 'undefined') { + writeStream.write(' * [' + docItem.name + '](#' + docItem.type + '-' + docItem.name.toLowerCase() + ')\n'); + } + }); + }); + } + + // create docs for each contract from template + data.forEach(function (contract) { + var md = (0, _template2.default)(contract); + writeStream.write(md); + }); + + writeStream.end(); + }); +}; + +var _fs = require('fs'); + +var _fs2 = _interopRequireDefault(_fs); + +var _template = require('./template'); + +var _template2 = _interopRequireDefault(_template); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } \ No newline at end of file diff --git a/lib/template.js b/lib/template.js new file mode 100644 index 0000000..d63d57c --- /dev/null +++ b/lib/template.js @@ -0,0 +1,17 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _dot = require('dot'); + +var _dot2 = _interopRequireDefault(_dot); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var template = '\n# {{=it.name}}\n{{? it.author }}\n{{=it.author}}{{?}}\n{{~it.abiDocs :docItem:index}}{{? docItem.type === \'function\'}}\n## *{{=docItem.type}}* {{=docItem.name}}\n\n{{=it.name}}.{{=docItem.name}}({{=docItem.argumentList}}){{?docItem.payable}}`payable`{{?}} `{{=docItem.signatureHash}}`\n{{?docItem.notice}}\n**{{=docItem.notice}}**\n{{?}}\n{{?docItem.details}}> {{=docItem.details}}\n{{?}}\n{{? docItem.inputs.length > 0 }}Inputs\n\n| | | |\n|-|-|-|{{~docItem.inputs :input}}\n| *{{=input.type}}* | {{=input.name}} | {{=input.description}} |{{~}}{{?}}\n{{? docItem.outputs.length > 0 }}Outputs\n\n| | | |\n|-|-|-|{{~docItem.outputs :output}}\n| *{{=output.type}}* | {{=output.name}} | {{=output.description}} |{{~}}{{?}}{{?}}\n{{~}}\n---'; + +_dot2.default.templateSettings.strip = false; + +exports.default = _dot2.default.template(template); \ No newline at end of file diff --git a/package.json b/package.json index d20eb2a..b11e9e9 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "scripts": { "dev": "$(npm bin)/babel src -w -d lib", "test": "$(npm bin)/mocha", - "compile": "rm -rf lib/* && $(npm bin)/babel src -d lib", - "prepublishOnly": "npm run compile", + "build": "rm -rf lib/* && $(npm bin)/babel src -d lib", + "prepublishOnly": "npm run build", "lint": "$(npm bin)/eslint src/ test/", "precommit": "./node_modules/pre-commit/hook" }, From 50024ef5f0f4d2e8da526d3810b0281abd3a0f37 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 13:10:45 -0400 Subject: [PATCH 15/20] fix eslint-plugin version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4ee6f83..8148d59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1378,9 +1378,9 @@ } }, "eslint-plugin-jsx-a11y": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.0.2.tgz", - "integrity": "sha1-ZZJ3p1iwNsMFp+ShMFfDAc075z8=", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-5.1.1.tgz", + "integrity": "sha512-5I9SpoP7gT4wBFOtXT8/tXNPYohHBVfyVfO17vkbC7r9kEIxYJF12D3pKqhk8+xnk12rfxKClS3WCFpVckFTPQ==", "dev": true, "requires": { "aria-query": "0.7.0", diff --git a/package.json b/package.json index b11e9e9..b39e3fa 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "eslint-config-airbnb": "^15.1.0", "eslint-config-airbnb-base": "^11.3.1", "eslint-plugin-import": "^2.7.0", - "eslint-plugin-jsx-a11y": "^6.0.2", + "eslint-plugin-jsx-a11y": "^5.1.1", "eslint-plugin-react": "^7.1.0", "mocha": "^3.5.0", "pre-commit": "^1.2.2" From 2ca8fc885bc1410eaef811b3cfb6e7d9a64ab5ed Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 13:29:42 -0400 Subject: [PATCH 16/20] install solc before tests --- .travis.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4efe3dc..c945c96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,19 @@ language: node_js - node_js: - - "4" - +- '4' cache: directories: - - node_modules + - node_modules +before_script: + - "sudo add-apt-repository ppa:ethereum/ethereum" + - "sudo apt-get update" + - "sudo apt-get install solc" + +deploy: + provider: npm + email: danepilch@gmail.com + 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 From 146fc30f3039927b2f363148d46b13671326e487 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 13:36:10 -0400 Subject: [PATCH 17/20] add -y to apt --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c945c96..f331ac0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,9 @@ cache: directories: - node_modules before_script: - - "sudo add-apt-repository ppa:ethereum/ethereum" - - "sudo apt-get update" - - "sudo apt-get install solc" + - "sudo add-apt-repository ppa:ethereum/ethereum -y" + - "sudo apt-get update -y" + - "sudo apt-get install solc -y" deploy: provider: npm From fb68e4524b08c236e91aba9ae8242b2f5e608c72 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 13:54:32 -0400 Subject: [PATCH 18/20] update packages --- .gitignore | 1 + .travis.yml | 2 +- package-lock.json | 21 --------------------- package.json | 2 -- 4 files changed, 2 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 940fe46..ce22e6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ node_modules sol.md +test/output.md diff --git a/.travis.yml b/.travis.yml index f331ac0..7a94907 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ cache: - node_modules before_script: - "sudo add-apt-repository ppa:ethereum/ethereum -y" - - "sudo apt-get update -y" + - "sudo apt-get update" - "sudo apt-get install solc -y" deploy: diff --git a/package-lock.json b/package-lock.json index 8148d59..3d031a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -230,18 +230,6 @@ "source-map": "0.5.6" } }, - "babel-eslint": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-7.2.3.tgz", - "integrity": "sha1-sv4tgBJkcPXBlELcdXJTqJdxCCc=", - "dev": true, - "requires": { - "babel-code-frame": "6.22.0", - "babel-traverse": "6.25.0", - "babel-types": "6.25.0", - "babylon": "6.17.4" - } - }, "babel-generator": { "version": "6.25.0", "resolved": "https://registry.npmjs.org/babel-generator/-/babel-generator-6.25.0.tgz", @@ -1309,15 +1297,6 @@ "text-table": "0.2.0" } }, - "eslint-config-airbnb": { - "version": "15.1.0", - "resolved": "https://registry.npmjs.org/eslint-config-airbnb/-/eslint-config-airbnb-15.1.0.tgz", - "integrity": "sha512-m0q9fiMBzDAIbirlGnpJNWToIhdhJmXXnMG+IFflYzzod9231ZhtmGKegKg8E9T8F1YuVaDSU1FnCm5b9iXVhQ==", - "dev": true, - "requires": { - "eslint-config-airbnb-base": "11.3.1" - } - }, "eslint-config-airbnb-base": { "version": "11.3.1", "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-11.3.1.tgz", diff --git a/package.json b/package.json index b39e3fa..9eac399 100644 --- a/package.json +++ b/package.json @@ -32,11 +32,9 @@ "license": "MIT", "devDependencies": { "babel-cli": "^6.24.1", - "babel-eslint": "^7.2.3", "babel-preset-es2015": "^6.24.1", "babel-preset-stage-2": "^6.24.1", "eslint": "^4.3.0", - "eslint-config-airbnb": "^15.1.0", "eslint-config-airbnb-base": "^11.3.1", "eslint-plugin-import": "^2.7.0", "eslint-plugin-jsx-a11y": "^5.1.1", From c0746e0383307bf4367a3f5e4a47943a9b60a8f2 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 13:55:41 -0400 Subject: [PATCH 19/20] add -y back --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7a94907..f331ac0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ cache: - node_modules before_script: - "sudo add-apt-repository ppa:ethereum/ethereum -y" - - "sudo apt-get update" + - "sudo apt-get update -y" - "sudo apt-get install solc -y" deploy: From 25a7114a1c97f0bd1bc6e97f8ba31433d3fac2e9 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Sun, 20 Aug 2017 13:59:19 -0400 Subject: [PATCH 20/20] v0.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9eac399..7e6e716 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "solmd", - "version": "0.1.2", + "version": "0.1.3", "description": "Markdown documentation generator for Solidity", "engines": { "node": ">=4"