aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-doc/src
diff options
context:
space:
mode:
authorF. Eugene Aumson <gene@aumson.org>2018-08-24 02:00:34 +0800
committerF. Eugene Aumson <gene@aumson.org>2018-08-29 20:50:55 +0800
commit775d1efd4607a4097704fe3c4f7ae1156b2c1a6f (patch)
tree4e3890609606bfff6548a841106807f6bcc76795 /packages/sol-doc/src
parent849e203812aacff453228a372143600b05155a2c (diff)
downloaddexon-sol-tools-775d1efd4607a4097704fe3c4f7ae1156b2c1a6f.tar
dexon-sol-tools-775d1efd4607a4097704fe3c4f7ae1156b2c1a6f.tar.gz
dexon-sol-tools-775d1efd4607a4097704fe3c4f7ae1156b2c1a6f.tar.bz2
dexon-sol-tools-775d1efd4607a4097704fe3c4f7ae1156b2c1a6f.tar.lz
dexon-sol-tools-775d1efd4607a4097704fe3c4f7ae1156b2c1a6f.tar.xz
dexon-sol-tools-775d1efd4607a4097704fe3c4f7ae1156b2c1a6f.tar.zst
dexon-sol-tools-775d1efd4607a4097704fe3c4f7ae1156b2c1a6f.zip
add package sol-doc
Diffstat (limited to 'packages/sol-doc/src')
-rw-r--r--packages/sol-doc/src/index.ts2
-rw-r--r--packages/sol-doc/src/solidity_doc_format.ts5
-rw-r--r--packages/sol-doc/src/solidity_doc_generator.ts60
3 files changed, 67 insertions, 0 deletions
diff --git a/packages/sol-doc/src/index.ts b/packages/sol-doc/src/index.ts
new file mode 100644
index 000000000..f8f55c569
--- /dev/null
+++ b/packages/sol-doc/src/index.ts
@@ -0,0 +1,2 @@
+export { SolidityDocGenerator } from './solidity_doc_generator';
+export { SolidityDocFormat } from './solidity_doc_format';
diff --git a/packages/sol-doc/src/solidity_doc_format.ts b/packages/sol-doc/src/solidity_doc_format.ts
new file mode 100644
index 000000000..edfd5c5b7
--- /dev/null
+++ b/packages/sol-doc/src/solidity_doc_format.ts
@@ -0,0 +1,5 @@
+import { DocAgnosticFormat, DocSection } from '@0xproject/react-docs';
+
+export class SolidityDocFormat implements DocAgnosticFormat {
+ [sectionName: string]: DocSection;
+}
diff --git a/packages/sol-doc/src/solidity_doc_generator.ts b/packages/sol-doc/src/solidity_doc_generator.ts
new file mode 100644
index 000000000..c57a4779c
--- /dev/null
+++ b/packages/sol-doc/src/solidity_doc_generator.ts
@@ -0,0 +1,60 @@
+import * as _ from 'lodash';
+
+import { MethodAbi } from 'ethereum-types';
+
+import { Compiler, CompilerOptions } from '@0xproject/sol-compiler';
+import { logUtils } from '@0xproject/utils';
+
+import { SolidityDocFormat } from './solidity_doc_format';
+
+export class SolidityDocGenerator {
+ private readonly _compilerOptions: CompilerOptions;
+ constructor(contractsDir: string, artifactsDir: string) {
+ // instantiate sol-compiler, passing in options to say we want abi and devdoc
+ this._compilerOptions = {
+ contractsDir,
+ artifactsDir,
+ contracts: '*',
+ compilerSettings: {
+ outputSelection: {
+ ['*']: {
+ ['*']: ['abi', 'devdoc'],
+ },
+ },
+ },
+ };
+ }
+ /// run `contractsToCompile` through compiler, gathering output
+ public async generateAsync(contractsToCompile: string[]): Promise<SolidityDocFormat> {
+ if (!_.isUndefined(contractsToCompile)) {
+ this._compilerOptions.contracts = contractsToCompile;
+ }
+
+ const compiler = new Compiler(this._compilerOptions);
+
+ const doc = new SolidityDocFormat();
+
+ const compilerOutputs = await compiler.getCompilerOutputsAsync();
+ for (const compilerOutput of compilerOutputs) {
+ const solidityModules = _.keys(compilerOutput.contracts);
+ for (const solidityModule of solidityModules) {
+ const compiledSolidityModule = compilerOutput.contracts[solidityModule];
+
+ const contracts = _.keys(compiledSolidityModule);
+ for (const contract of contracts) {
+ const compiledContract = compiledSolidityModule[contract];
+
+ // TODO: modify typescript-typings/types/solc/index.d.ts... it doesn't currently support devdoc!
+ // tslint:disable-next-line:no-unnecessary-type-assertion tsc says abi[0] has no property `name` and won't compile without the `as`, but tslint says the `as` is unnecssary.
+ logUtils.log(
+ `TODO: extract data from ${contract}'s abi (eg ${
+ (compiledContract.abi[0] as MethodAbi).name
+ }, etc) and devdoc outputs, and insert it into \`doc\``,
+ );
+ }
+ }
+ }
+
+ return doc;
+ }
+}