sol2uml 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -21
- package/lib/sol2uml.js +4 -3
- package/lib/writerFiles.d.ts +1 -1
- package/lib/writerFiles.js +14 -9
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -20,16 +20,19 @@ The following installation assumes [Node.js](https://nodejs.org/en/download/) ha
|
|
|
20
20
|
`sol2uml` works with node 14 or above.
|
|
21
21
|
|
|
22
22
|
To install globally so you can run `sol2uml` from anywhere
|
|
23
|
+
|
|
23
24
|
```bash
|
|
24
25
|
npm link sol2uml --only=production
|
|
25
26
|
```
|
|
26
27
|
|
|
27
28
|
To upgrade run
|
|
29
|
+
|
|
28
30
|
```bash
|
|
29
31
|
npm upgrade sol2uml -g
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
To see which version you are using
|
|
35
|
+
|
|
33
36
|
```bash
|
|
34
37
|
npm ls sol2uml -g
|
|
35
38
|
```
|
|
@@ -139,36 +142,43 @@ Options:
|
|
|
139
142
|
## UML Class diagram examples
|
|
140
143
|
|
|
141
144
|
To generate a diagram of all contracts under the contracts folder and its sub folders
|
|
145
|
+
|
|
142
146
|
```bash
|
|
143
147
|
sol2uml class ./contracts
|
|
144
148
|
```
|
|
145
149
|
|
|
146
150
|
To generate a diagram of EtherDelta's contract from the verified source code on [Etherscan](https://etherscan.io/address/0x8d12A197cB00D4747a1fe03395095ce2A5CC6819#code). The output wil be a svg file `0x8d12A197cB00D4747a1fe03395095ce2A5CC6819.svg` in the working folder.
|
|
151
|
+
|
|
147
152
|
```bash
|
|
148
153
|
sol2uml class 0x8d12A197cB00D4747a1fe03395095ce2A5CC6819
|
|
149
154
|
```
|
|
150
155
|
|
|
151
156
|
To generate a diagram of EtherDelta's contract from the verified source code on [Etherscan Ropsten](https://ropsten.etherscan.io/address/0xa19833bd291b66aB0E17b9C6d46D2Ec5fEC15190#code). The output wil be a svg file `0xa19833bd291b66aB0E17b9C6d46D2Ec5fEC15190.svg` in the working folder.
|
|
157
|
+
|
|
152
158
|
```bash
|
|
153
159
|
sol2uml class 0xa19833bd291b66aB0E17b9C6d46D2Ec5fEC15190 -n ropsten
|
|
154
160
|
```
|
|
155
161
|
|
|
156
162
|
To generate all Solidity files under some root folder and output the svg file to a specific location
|
|
163
|
+
|
|
157
164
|
```bash
|
|
158
165
|
sol2uml class path/to/contracts/root/folder -o ./outputFile.svg
|
|
159
166
|
```
|
|
160
167
|
|
|
161
168
|
To generate a diagram of all contracts in a single Solidity file, the output file in png format to output file `./someFile.png`
|
|
169
|
+
|
|
162
170
|
```bash
|
|
163
171
|
sol2uml class path/to/contracts/root/folder/solidity/file.sol -f png -o ./someFile.png
|
|
164
172
|
```
|
|
165
173
|
|
|
166
|
-
To generate a diagram of all Solidity files under the `contracts` and `node_modules/openzeppelin-solidity` folders.
|
|
174
|
+
To generate a diagram of all Solidity files under the `contracts` and `node_modules/openzeppelin-solidity` folders. The output will be `contracts.svg` and `contracts.png` files in the working folder.
|
|
175
|
+
|
|
167
176
|
```bash
|
|
168
177
|
sol2uml class ./contracts,node_modules/openzeppelin-solidity -f all -v
|
|
169
178
|
```
|
|
170
179
|
|
|
171
180
|
To generate a diagram of all Solidity files under the working folder ignoring and files under the `solparse`, `@solidity-parser` and `ethlint` folders, which will be under the `node_modules` folder.
|
|
181
|
+
|
|
172
182
|
```bash
|
|
173
183
|
sol2uml class -i solparse,@solidity-parser,ethlint
|
|
174
184
|
```
|
|
@@ -176,8 +186,9 @@ sol2uml class -i solparse,@solidity-parser,ethlint
|
|
|
176
186
|
# UML Class Diagram Syntax
|
|
177
187
|
|
|
178
188
|
Good online resources for learning UML
|
|
179
|
-
|
|
180
|
-
|
|
189
|
+
|
|
190
|
+
- [UML 2 Class Diagramming Guidelines](http://www.agilemodeling.com/style/classDiagram.htm)
|
|
191
|
+
- [Creating class diagrams with UML](https://www.ionos.com/digitalguide/websites/web-development/class-diagrams-with-uml/)
|
|
181
192
|
|
|
182
193
|
## Terminology differences
|
|
183
194
|
|
|
@@ -187,33 +198,35 @@ A Solidity variable becomes an attribute in UML and a Solidity function becomes
|
|
|
187
198
|
|
|
188
199
|
### Class stereotypes
|
|
189
200
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
- Interface
|
|
202
|
+
- Abstract - if any of the contract's functions are abstract, the class will have an Abstract stereotype. Child contracts of abstract contracts that do not implement all the abstract functions are currently not marked as Abstract.
|
|
203
|
+
- Library
|
|
193
204
|
|
|
194
205
|
### Operator stereotypes
|
|
195
206
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
207
|
+
- event
|
|
208
|
+
- modifier
|
|
209
|
+
- abstract - if there is no function body on a contract, the operator is marked as abstract. Operators on an Interface do not have an abstract stereotype as all operators are abstract.
|
|
210
|
+
- fallback - abstract fallback functions will just have an abstract stereotype.
|
|
211
|
+
- payable - payable fallback functions will just have a fallback stereotype.
|
|
201
212
|
|
|
202
213
|
## UML Associations
|
|
203
214
|
|
|
204
215
|
Lines:
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
-
|
|
208
|
-
-
|
|
209
|
-
-
|
|
210
|
-
|
|
211
|
-
-
|
|
216
|
+
|
|
217
|
+
- Solid lines for
|
|
218
|
+
- link the contract types of storage (state) variables. This can be linked to contracts, interfaces, libraries or file level structs and enums.
|
|
219
|
+
- generalisations of contracts and abstract contracts.
|
|
220
|
+
- aggregated contract level structs and enums.
|
|
221
|
+
- Dashed lines for
|
|
222
|
+
- generalisations of interfaces.
|
|
223
|
+
- types of memory variables.
|
|
212
224
|
|
|
213
225
|
Heads/Tails:
|
|
214
|
-
|
|
215
|
-
-
|
|
216
|
-
-
|
|
226
|
+
|
|
227
|
+
- An empty triangle head for generalisations of contracts, interfaces and abstract contracts.
|
|
228
|
+
- An open arrow head for storage or memory variable dependencies
|
|
229
|
+
- A diamond tail for aggregations of contract level structs and enums
|
|
217
230
|
|
|
218
231
|
## Storage diagram
|
|
219
232
|
|
package/lib/sol2uml.js
CHANGED
|
@@ -101,15 +101,16 @@ program
|
|
|
101
101
|
...command.parent._optionValues,
|
|
102
102
|
...options,
|
|
103
103
|
};
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
let { umlClasses, contractName } = await (0, parserGeneral_1.parserUmlClasses)(fileFolderAddress, combinedOptions);
|
|
105
|
+
contractName = combinedOptions.contractName || contractName;
|
|
106
|
+
const storageObjects = (0, converterClasses2Storage_1.convertClasses2StorageObjects)(contractName, umlClasses);
|
|
106
107
|
if ((0, regEx_1.isAddress)(fileFolderAddress)) {
|
|
107
108
|
// The first object is the contract
|
|
108
109
|
storageObjects[0].address = fileFolderAddress;
|
|
109
110
|
}
|
|
110
111
|
debug(storageObjects);
|
|
111
112
|
const dotString = (0, converterStorage2Dot_1.convertStorage2Dot)(storageObjects);
|
|
112
|
-
await (0, writerFiles_1.writeOutputFiles)(dotString, fileFolderAddress, combinedOptions.outputFormat, combinedOptions.outputFileName);
|
|
113
|
+
await (0, writerFiles_1.writeOutputFiles)(dotString, fileFolderAddress, contractName, combinedOptions.outputFormat, combinedOptions.outputFileName);
|
|
113
114
|
}
|
|
114
115
|
catch (err) {
|
|
115
116
|
console.error(`Failed to generate storage diagram ${err}`);
|
package/lib/writerFiles.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare type OutputFormats = 'svg' | 'png' | 'dot' | 'all';
|
|
2
|
-
export declare const writeOutputFiles: (dot: string,
|
|
2
|
+
export declare const writeOutputFiles: (dot: string, fileFolderAddress: string, contractName: string, outputFormat?: OutputFormats, outputFilename?: string) => Promise<void>;
|
|
3
3
|
export declare function convertDot2Svg(dot: string): any;
|
|
4
4
|
export declare function writeSolidity(code: string, filename?: string): void;
|
|
5
5
|
export declare function writeDot(dot: string, filename?: string): void;
|
package/lib/writerFiles.js
CHANGED
|
@@ -9,7 +9,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const sync_1 = __importDefault(require("@aduh95/viz.js/sync"));
|
|
10
10
|
const { convert } = require('convert-svg-to-png');
|
|
11
11
|
const debug = require('debug')('sol2uml');
|
|
12
|
-
const writeOutputFiles = async (dot,
|
|
12
|
+
const writeOutputFiles = async (dot, fileFolderAddress, contractName, outputFormat = 'svg', outputFilename) => {
|
|
13
13
|
if (outputFormat === 'dot' || outputFormat === 'all') {
|
|
14
14
|
writeDot(dot, outputFilename);
|
|
15
15
|
// No need to continue if only generating a dot file
|
|
@@ -17,19 +17,24 @@ const writeOutputFiles = async (dot, outputBaseName, outputFormat = 'svg', outpu
|
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
// If all output then extension is svg
|
|
21
|
+
const outputExt = outputFormat === 'all' ? 'svg' : outputFormat;
|
|
20
22
|
if (!outputFilename) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
outputFilename =
|
|
24
|
+
path_1.default.join(process.cwd(), contractName) + '.' + outputExt;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// check if outputFilename is a folder
|
|
24
28
|
try {
|
|
25
|
-
const folderOrFile = (0, fs_1.lstatSync)(
|
|
29
|
+
const folderOrFile = (0, fs_1.lstatSync)(outputFilename);
|
|
26
30
|
if (folderOrFile.isDirectory()) {
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
outputFilename =
|
|
32
|
+
path_1.default.join(process.cwd(), outputFilename, contractName) +
|
|
33
|
+
'.' +
|
|
34
|
+
outputExt;
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
|
-
catch (err) { } // we can ignore errors as it just means
|
|
32
|
-
outputFilename = outputBaseName + '.' + outputExt;
|
|
37
|
+
catch (err) { } // we can ignore errors as it just means outputFilename does not exist yet
|
|
33
38
|
}
|
|
34
39
|
const svg = convertDot2Svg(dot);
|
|
35
40
|
if (outputFormat === 'svg' || outputFormat === 'all') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sol2uml",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Unified Modeling Language (UML) class diagram generator for Solidity contracts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"buildSol": "cd ./src/contracts && solc **/*.sol",
|
|
9
9
|
"build": "tsc --build ./tsconfig.json",
|
|
10
10
|
"clean": "tsc --build --clean ./tsconfig.json",
|
|
11
|
-
"prettier": "prettier --write
|
|
12
|
-
"prettier:check": "prettier --check
|
|
11
|
+
"prettier": "prettier --write src/**/*.ts **/*.md",
|
|
12
|
+
"prettier:check": "prettier --check src/**/*.ts **/*.md",
|
|
13
13
|
"test": "npx jest"
|
|
14
14
|
},
|
|
15
15
|
"preferGlobal": true,
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"commander": "^9.4.0",
|
|
26
26
|
"convert-svg-to-png": "^0.6.4",
|
|
27
27
|
"debug": "^4.3.4",
|
|
28
|
+
"ethers": "^5.6.9",
|
|
28
29
|
"js-graph-algorithms": "^1.0.18",
|
|
29
30
|
"klaw": "^4.0.1"
|
|
30
31
|
},
|