Skip to content

Commit

Permalink
feat: added hideLibraries and hideInterfaces options
Browse files Browse the repository at this point in the history
  • Loading branch information
naddison36 committed Dec 20, 2020
1 parent bf47d32 commit 421188e
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 24 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Options:
-p, --hideOperators hide class and interface operators/functions
-e, --hideEnums hide enum types
-s, --hideStructs hide data structures
-l, --hideLibraries hide libraries
-t, --hideInterfaces hide interfaces
-k, --etherscanApiKey <key> Etherscan API Key
-c, --clusterFolders cluster contracts into source folders
-v, --verbose run with debugging statements
Expand Down
2 changes: 1 addition & 1 deletion lib/converter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export declare type OutputFormats = 'svg' | 'png' | 'dot' | 'all';
export declare const generateFilesFromUmlClasses: (umlClasses: UmlClass[], outputBaseName: string, outputFormat?: OutputFormats, outputFilename?: string, clusterFolders?: boolean, classOptions?: ClassOptions) => Promise<void>;
export declare const convertUmlClassesToSvg: (umlClasses: UmlClass[], clusterFolders?: boolean) => Promise<string>;
export declare function convertUmlClasses2Dot(umlClasses: UmlClass[], clusterFolders?: boolean, classOptions?: ClassOptions): string;
export declare function addAssociationsToDot(umlClasses: UmlClass[]): string;
export declare function addAssociationsToDot(umlClasses: UmlClass[], classOptions?: ClassOptions): string;
export declare function convertDot2Svg(dot: string): any;
export declare function writeDot(dot: string, dotFilename?: string): void;
export declare function writeSVG(svg: any, svgFilename?: string, outputFormats?: OutputFormats): Promise<void>;
Expand Down
25 changes: 16 additions & 9 deletions lib/converter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/dotGenerator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export interface ClassOptions {
hideOperators?: boolean;
hideStructs?: boolean;
hideEnums?: boolean;
hideLibraries?: boolean;
hideInterfaces?: boolean;
}
export declare const dotUmlClass: (umlClass: UmlClass, options?: ClassOptions) => string;
7 changes: 7 additions & 0 deletions lib/dotGenerator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/sol2uml.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 25 additions & 12 deletions src/ts/converter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { ClassOptions, dotUmlClass } from './dotGenerator'

const debug = require('debug')('sol2uml')

import { lstatSync, writeFile } from 'fs'
const path = require('path')
const svg_to_png = require('svg-to-png')
import { VError } from 'verror'
const Viz = require('viz.js')

import { ClassOptions, dotUmlClass } from './dotGenerator'
import {
Association,
ClassStereotype,
ReferenceType,
UmlClass,
} from './umlClass'
import { VError } from 'verror'

const path = require('path')
const Viz = require('viz.js')
const svg_to_png = require('svg-to-png')
const debug = require('debug')('sol2uml')

export type OutputFormats = 'svg' | 'png' | 'dot' | 'all'

Expand Down Expand Up @@ -109,7 +108,7 @@ label="${codeFolder}"`
dotString += '\n}'
}

dotString += addAssociationsToDot(umlClasses)
dotString += addAssociationsToDot(umlClasses, classOptions)

// Need to close off the last the digraph
dotString += '\n}'
Expand Down Expand Up @@ -139,7 +138,10 @@ function sortUmlClassesByCodePath(umlClasses: UmlClass[]): UmlClass[] {
})
}

export function addAssociationsToDot(umlClasses: UmlClass[]): string {
export function addAssociationsToDot(
umlClasses: UmlClass[],
classOptions: ClassOptions = {}
): string {
let dotString: string = ''

// for each class
Expand All @@ -162,7 +164,8 @@ export function addAssociationsToDot(umlClasses: UmlClass[]): string {
dotString += addAssociationToDot(
sourceUmlClass,
targetUmlClass,
association
association,
classOptions
)
}
}
Expand All @@ -174,8 +177,18 @@ export function addAssociationsToDot(umlClasses: UmlClass[]): string {
function addAssociationToDot(
sourceUmlClass: UmlClass,
targetUmlClass: UmlClass,
association: Association
association: Association,
classOptions: ClassOptions = {}
): string {
// do not include library or interface associations if hidden
if (
(classOptions.hideLibraries &&
targetUmlClass.stereotype === ClassStereotype.Library) ||
(classOptions.hideInterfaces &&
targetUmlClass.stereotype === ClassStereotype.Interface)
) {
return ''
}
let dotString = `\n${sourceUmlClass.id} -> ${targetUmlClass.id} [`

if (
Expand Down
11 changes: 11 additions & 0 deletions src/ts/dotGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ export interface ClassOptions {
hideOperators?: boolean
hideStructs?: boolean
hideEnums?: boolean
hideLibraries?: boolean
hideInterfaces?: boolean
}

export const dotUmlClass = (
umlClass: UmlClass,
options: ClassOptions = {}
): string => {
// do not include library or interface classes if hidden
if (
(options.hideLibraries &&
umlClass.stereotype === ClassStereotype.Library) ||
(options.hideInterfaces &&
umlClass.stereotype === ClassStereotype.Interface)
) {
return ''
}
let dotString = `\n${umlClass.id} [label="{${dotClassTitle(umlClass)}`

// Add attributes
Expand Down
3 changes: 2 additions & 1 deletion src/ts/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
TypeName,
VariableDeclaration,
} from '@solidity-parser/parser/dist/ast-types'
import { dirname, join } from 'path'

import {
ClassStereotype,
OperatorStereotype,
Expand All @@ -13,7 +15,6 @@ import {
UmlClass,
Visibility,
} from './umlClass'
import { dirname, join } from 'path'

const debug = require('debug')('sol2uml')

Expand Down
4 changes: 4 additions & 0 deletions src/ts/sol2uml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ If an Ethereum address with a 0x prefix is passed, the verified source code from
)
.option('-e, --hideEnums', 'hide enum types')
.option('-s, --hideStructs ', 'hide data structures')
.option('-l, --hideLibraries ', 'hide libraries')
.option('-t, --hideInterfaces ', 'hide interfaces')
.option('-k, --etherscanApiKey <key>', 'Etherscan API Key')
.option('-c, --clusterFolders', 'cluster contracts into source folders')
.option('-v, --verbose', 'run with debugging statements')
Expand Down Expand Up @@ -129,6 +131,8 @@ async function sol2uml() {
hideOperators: program.hideOperators,
hideEnums: program.hideEnums,
hideStructs: program.hideStructs,
hideLibraries: program.hideLibraries,
hideInterfaces: program.hideInterfaces,
}
).then(() => {
debug(`Finished`)
Expand Down

0 comments on commit 421188e

Please sign in to comment.