Comparing version 1.1.6 to 1.1.7
import { UmlClass } from './umlClass'; | ||
export declare type OutputFormats = 'svg' | 'png' | 'dot' | 'all'; | ||
export declare const convertUmlClasses: (umlClasses: UmlClass[], outputBaseName: string, outputFormat?: OutputFormats, outputFilename?: string, clusterFolders?: boolean) => Promise<void>; | ||
export declare const generateFilesFromUmlClasses: (umlClasses: UmlClass[], outputBaseName: string, outputFormat?: OutputFormats, outputFilename?: string, clusterFolders?: boolean) => Promise<void>; | ||
export declare const convertUmlClassesToSvg: (umlClasses: UmlClass[], clusterFolders?: boolean) => Promise<string>; | ||
export declare function convertUmlClasses2Dot(umlClasses: UmlClass[], clusterFolders?: boolean): string; | ||
@@ -5,0 +6,0 @@ export declare function addAssociationsToDot(umlClasses: UmlClass[]): string; |
@@ -10,3 +10,3 @@ "use strict"; | ||
const svg_to_png = require('svg-to-png'); | ||
exports.convertUmlClasses = async (umlClasses, outputBaseName, outputFormat = 'svg', outputFilename, clusterFolders = false) => { | ||
exports.generateFilesFromUmlClasses = async (umlClasses, outputBaseName, outputFormat = 'svg', outputFilename, clusterFolders = false) => { | ||
const dot = convertUmlClasses2Dot(umlClasses, clusterFolders); | ||
@@ -35,3 +35,3 @@ if (outputFormat === 'dot' || outputFormat === 'all') { | ||
const svg = convertDot2Svg(dot); | ||
// write svg file even if only wanting png file as we convertUmlClasses svg files to png | ||
// write svg file even if only wanting png file as we generateFilesFromUmlClasses svg files to png | ||
await writeSVG(svg, outputFilename, outputFormat); | ||
@@ -42,2 +42,6 @@ if (outputFormat === 'png' || outputFormat === 'all') { | ||
}; | ||
exports.convertUmlClassesToSvg = async (umlClasses, clusterFolders = false) => { | ||
const dot = convertUmlClasses2Dot(umlClasses, clusterFolders); | ||
return convertDot2Svg(dot); | ||
}; | ||
function convertUmlClasses2Dot(umlClasses, clusterFolders = false) { | ||
@@ -44,0 +48,0 @@ let dotString = ` |
@@ -5,7 +5,7 @@ import { ASTNode } from 'solidity-parser-antlr'; | ||
declare type Network = typeof networks[number]; | ||
export default class EtherscanParser { | ||
export declare class EtherscanParser { | ||
protected apikey: string; | ||
network: Network; | ||
readonly url: string; | ||
constructor(apikey: string, network?: Network); | ||
constructor(apikey?: string, network?: Network); | ||
/** | ||
@@ -12,0 +12,0 @@ * Parses the verified source code files from Etherscan |
@@ -12,3 +12,3 @@ "use strict"; | ||
class EtherscanParser { | ||
constructor(apikey, network = 'mainnet') { | ||
constructor(apikey = 'ZAD4UI2RCXCQTP38EXS3UY2MPHFU5H9KB1', network = 'mainnet') { | ||
this.apikey = apikey; | ||
@@ -94,3 +94,3 @@ this.network = network; | ||
} | ||
exports.default = EtherscanParser; | ||
exports.EtherscanParser = EtherscanParser; | ||
//# sourceMappingURL=etherscanParser.js.map |
#! /usr/bin/env node | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const etherscanParser_1 = __importDefault(require("./etherscanParser")); | ||
const etherscanParser_1 = require("./etherscanParser"); | ||
const fileParser_1 = require("./fileParser"); | ||
@@ -43,3 +40,3 @@ const debug = require('debug')('sol2uml'); | ||
const etherscanApiKey = program.etherscanApiKey || 'ZAD4UI2RCXCQTP38EXS3UY2MPHFU5H9KB1'; | ||
const etherscanParser = new etherscanParser_1.default(etherscanApiKey, program.network); | ||
const etherscanParser = new etherscanParser_1.EtherscanParser(etherscanApiKey, program.network); | ||
umlClasses = await etherscanParser.getUmlClasses(fileFolderAddress); | ||
@@ -55,3 +52,3 @@ } | ||
} | ||
converter_1.convertUmlClasses(umlClasses, fileFolderAddress, program.outputFormat, program.outputFileName, program.clusterFolders).then(() => { | ||
converter_1.generateFilesFromUmlClasses(umlClasses, fileFolderAddress, program.outputFormat, program.outputFileName, program.clusterFolders).then(() => { | ||
debug(`Finished`); | ||
@@ -58,0 +55,0 @@ }); |
{ | ||
"name": "sol2uml", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"description": "Unified Modeling Language (UML) class diagram generator for Solidity contracts", | ||
"main": "./lib/sol2uml.js", | ||
"types": "./lib/sol2uml.d.ts", | ||
"main": "./lib/index.js", | ||
"types": "./lib/index.d.ts", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "buildSol": "cd ./src/contracts && solc *", |
@@ -12,3 +12,3 @@ # Solidity 2 UML | ||
## Install | ||
# Install | ||
@@ -27,4 +27,6 @@ The following installation assumes [Node.js](https://nodejs.org/en/download/) has already been installed which comes with [Node Package Manager (NPM)](https://www.npmjs.com/). | ||
## Usage | ||
# Usage | ||
## Command Line Interface (CLI) | ||
To see the usage options | ||
@@ -82,4 +84,26 @@ ``` | ||
## UML Syntax | ||
## Application Programming Interface (API) | ||
The main function that parses Solidity source code from files or files in folders is [parseUmlClassesFromFiles](./lib/fileParser.d.ts#L3). This returns an array of UML class objects. | ||
[EtherscanParser](./lib/etherscanParser.d.ts#L5) is a class that parses Etherscan's verified Solidity source code for a contract. For example | ||
```ts | ||
import { convertUmlClassesToSvg, EtherscanParser } from 'sol2uml' | ||
async function generateSvg() { | ||
const etherscanParser = new EtherscanParser() | ||
// get the verified source code from Etherscan for the contract address and | ||
// parse Solidity into UML class objects | ||
const umlClasses = await etherscanParser.getUmlClasses('0xf5dce57282a584d2746faf1593d3121fcac444dc') | ||
// Convert UML classes to a svg string | ||
const svg = await convertUmlClassesToSvg(umlClasses) | ||
} | ||
``` | ||
[generateFilesFromUmlClasses](./lib/converter.d.ts#L3) is used to write the dot, svg and png files from an array of UML class objects. | ||
# UML Syntax | ||
Good online resources for learning UML | ||
@@ -89,9 +113,9 @@ * [UML 2 Class Diagramming Guidelines](http://www.agilemodeling.com/style/classDiagram.htm) | ||
### Terminology differences | ||
## Terminology differences | ||
A Solidity variable becomes an attribute in UML and a Solidity function becomes an operation in UML. | ||
### Stereotypes | ||
## Stereotypes | ||
#### Class stereotypes | ||
### Class stereotypes | ||
@@ -102,3 +126,3 @@ * Interface | ||
#### Operator stereotypes | ||
### Operator stereotypes | ||
@@ -111,3 +135,3 @@ * event | ||
### UML Associations | ||
## UML Associations | ||
@@ -126,3 +150,3 @@ Lines: | ||
## About | ||
# About | ||
@@ -129,0 +153,0 @@ This is a rewrite of the Richard Ramos's [solidity-diagram-gen](https://github.com/richard-ramos/solidity-diagram-gen) tool which no longer works as it uses [solidity-parser](https://www.npmjs.com/package/solidity-parser/v/0.4.0) which cannot handle newer Solidity syntax like `constructor`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59552
17
1218
151