Giter VIP home page Giter VIP logo

yoshimkd / swift-auto-diagram Goto Github PK

View Code? Open in Web Editor NEW
489.0 29.0 58.0 461 KB

A Ruby script that scans all swift code from the specified folders and files and automatically generates an entity diagram (similar to a class diagram) which can be viewed in a browser.

License: MIT License

Ruby 31.70% CSS 11.93% HTML 4.57% JavaScript 51.80%
diagram swift swift-files ruby-script entity-diagram ruby class-diagram script generator

swift-auto-diagram's Introduction

Swift Auto Diagram

A Ruby script that scans all swift code from the specified folders and files and automatically generates an entity diagram (similar to a class diagram) which can be viewed in a browser.

Usage:

In terminal run:

$ ruby generateEntityDiagram.rb

If you don't specify any command line arguments then the script will search for all swift files in the script's main directory. You can specify any number of command line arguments which should be existing directory or file paths. The directories will be searched in depth for swift files recursively.

Tutorial:

https://martinmitrevski.com/2016/10/12/swift-class-diagrams-and-more/

Notice:

The state of the project is still in a beta version which means it still may not run or may be not accurate for all projects. We hope to see more contributors help make this a wonderful developer tool even better.

Initial creators:

https://github.com/yoshimkd

https://github.com/ZdravkoN

Contributors:

https://github.com/ivanfoong

https://github.com/andreinagy

swift-auto-diagram's People

Contributors

andreinagy avatar aurochscross avatar digitalvisionmax avatar ivanfoong avatar muzib avatar shanecb avatar yoshimkd avatar zdravkon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-auto-diagram's Issues

Generate diagram from frameworks

Is it possible to generate a diagram from Apple APIs? For example, I would like to generate a diagram for HealthKit types. I'm not sure how to proceed.

Not working for RNCryptor ( or maybe it's just .h file )

Hi,

I've had a problem with generating diagram for my app. It was stuck and nothing happened.

After a while I found a culprit, and it was .h file from RNCryptor ( attachment ). So my suggestion is to either try to fix it, or exclude it and put next to diagram a list of excluded files, so user can see what code files were missed.

RNCryptor.zip

Problem zooming big diagram (no way to read it)

I'm looking at a big project and there's no way to actually read what is being generated.
In Chrome and Safari, I try to zoom with +/- keys and it just gets blurry, as in pictures attached.

I poked around the folder and saw that all of it is in diagram.js... Is this any known/standard format or could it be exported into some kind that I can see anything?

entity

zoomed

How to run the ruby script?

I also unable to run the command ruby generateEntityDiagram.rb.

When I run it the browser window opens in safari and simply sits there. There seems to be an error in the browser console

error

Generic classes derived from other generic classes do not draw their relationship

Generic classes derived from other generic classes do not draw their relationship

Example:
protocol ProtocolF {
associatedtype T
var b1: T? { get }
}

class ClassF<Type,TypeB,TypeC> : ProtocolF {
var b1: Type?
var b2: TypeB?
var b3: TypeC?
}

class ClassG<Type,TypeB,TypeC,TypeD>: ClassF<Type,TypeB,TypeC> {
var b5: Type?
var b6: TypeB?
var b7: TypeC?
var b8: TypeD?
}

output-onlinepngtools (1)

How to edit diagram?

Hi,

is there a way to edit and order diagram? I'm not saying that HTML version should have these options, but it would be nice to export diagram to yEd or StarUML or something? Can you recommend a good ( free if possible ) software for editing, if it can be done?

Thanks.

Execution breaks for nested classes/structs

The execution breaks if the project contains nested classes, e.g.:

class MyClass {
    struct MyStruct {
        static let value = 7
    }   
}

The following error is presented:

/Users/x-three/Documents/Repositories/swift-auto-diagram/rubyResources/helpers.rb:64:in `gsub!': wrong argument type nil (expected Regexp) (TypeError)
    from /Users/x-three/Documents/Repositories/swift-auto-diagram/rubyResources/helpers.rb:64:in `block (2 levels) in createEntities'
    from /Users/x-three/Documents/Repositories/swift-auto-diagram/rubyResources/helpers.rb:60:in `each'
    from /Users/x-three/Documents/Repositories/swift-auto-diagram/rubyResources/helpers.rb:60:in `block in createEntities'
    from /Users/x-three/Documents/Repositories/swift-auto-diagram/rubyResources/helpers.rb:55:in `each'
    from /Users/x-three/Documents/Repositories/swift-auto-diagram/rubyResources/helpers.rb:55:in `createEntities'
    from /Users/x-three/Documents/Repositories/swift-auto-diagram/rubyResources/helpers.rb:13:in `block in entitiesFromFiles'
    from /Users/x-three/Documents/Repositories/swift-auto-diagram/rubyResources/helpers.rb:5:in `each'
    from /Users/x-three/Documents/Repositories/swift-auto-diagram/rubyResources/helpers.rb:5:in `entitiesFromFiles'
    from generateEntityDiagram.rb:60:in `<main>'

The extensions are drawn with the name undefined

All the extensions are drawn with the name undefined.

function networkLabel(entity) {
if (entity == undefined) {
return "Undefined";
}

return (
"" +
entity.name + //<------------------- The problem is here, the "entity.name" is undefined
":
" +
entity.typeString +
"
" +
"\n ----------------- \n" +
itemsString(entity.properties) +
"\n ----------------- \n" +
itemsString(entity.methods)
);
}

output-onlinepngtools

Feature request: Sort class hierarchy & multiple selection

Would it be possible to sort the classes on horizontal levels instead? I imagine the diagrams would be easier to read and would require less reordering afterwards. In this context, multiple selection of the ordered groups of classes could also be helpful to move around the whole (already tidy) groups by context.

Here an example of a quite untidy diagram with many dependencies to UIViewController:
image

After reordering in horizontal hierarchy levels, sorted descending by dependency count (not very strictly, just as a quick example):
image

The algorithm could be roughly: find the class with the most inheritances and place it, then place all protocols below them, then place all inherited classes below (maybe also sorted left to right by dependency count), continue until inheritance ends. Then place next unplaced class with the most inheritances randomly somewhere else on the screen (maybe below) with the same algorithm and so on.

Even if this algorithm wouldn't work on some edge cases, it would already help a lot on big projects.

IBOutlet

Hi, first of all, thanks for the idea and this tool, really like it.
As I try to generate my class diagram, I noticed, if I have some IBOutlets in code, like:
@IBOutlet weak var tableview: UITableView! \n @IBOutlet weak var imageView: UIImageView!
the result will be like this:
bildschirmfoto 2017-10-19 um 15 20 13

Two instances with nothing will be generated as you can see, can you pls check it, if you have some time? many thanks!

It fails(

/.../swift-auto-diagram-master/rubyResources/helpers.rb:6:in `read': Is a directory @ io_fread - /...//Pods/R.swift (Errno::EISDIR) from /.../swift-auto-diagram-master/rubyResources/helpers.rb:6:in `block in entitiesFromFiles' from /.../swift-auto-diagram-master/rubyResources/helpers.rb:5:in `each' from /.../swift-auto-diagram-master/rubyResources/helpers.rb:5:in `entitiesFromFiles' from generateEntityDiagram.rb:61:in `<main>'

Expected loading time?

Hi there,
My codebase is about 9000 lines of code. But it has been more than 15mins and I am seeing the grey circle loading and when I scrolled down, I saw this.
image
The network seems to be receiving and getting data from the server, lots of them. I am not sure if it should run that long. Can you please address? Thanks!
image

The script don't show the extensions.

I have created a demo project with a extension of AppDelegate and some other classes and its extensions, and the script don't show the extensions.

extension AppDelegate {

var some : String {
    return "some"
}

}

class ClassA0 {

var a1 : String?
var a2 : String?

func doItInBase() -> Bool {
    return true
}

}

class ClassA1 : ClassA0 {

var ad1 : String?
var ad2 : String?

override func doItInBase() -> Bool {
    return true
}

}

class ClassB1 {

var b1 : String?
var b2 : String?

}

class ClassC1 : ClassA1 {
override func doItInBase() -> Bool {
return super.doItInBase()
}

}

extension ClassA0 {

var ab1 : String? {
    return nil
}
var ab2 : String? {
    return nil
}

func doItInBase2() -> Bool {
    return true
}
func doItInBase3() -> Bool {
    return true
}

}

extension ClassA1 {

var a1ext1 : String? {
    return nil
}
var a1ext2 : String? {
    return nil
}

}

extension ClassA1 {

var a1ext3 : String? {
    return nil
}
var a1ext4 : String? {
    return nil
}
func doIt() -> Bool {
    return true
}

}

extension ClassB1 {

var b1ext1 : String? {
    return nil
}
var b1ext2 : String? {
    return nil
}

}

extension ClassB1 {

var b1ext3 : String? {
    return nil
}
var b1ext4 : String? {
    return nil
}
func doIt() -> Bool {
    return true
}

}

Command used:
ruby generateEntityDiagram.rb -v /swift-auto-diagram_bug/swift-auto-diagram_bug

Output:
output_bug

Generic types are not handled correctly

A type with a generic type annotation is not handled correctly (the generic type is not recognised).

For example:

struct STError<T: ErrorKind>: Error, CustomStringConvertible {
    // ...
}

produces this:

screen shot 2017-02-25 at 14 09 56

Script is failing.

When I try to run the script on my project it fails with the following error. can some help me here
Thanks.

Users/abc/Desktop/swift-auto-diagram/rubyResources/helpers.rb:6:in read': Is a directory @ io_fread - /Users/abc/Desktop/gojekRepo/project/projectName/Pods/GRDB.swift (Errno::EISDIR) from /Users/abc/Desktop/swift-auto-diagram/rubyResources/helpers.rb:6:in block in entitiesFromFiles'
from /Users/abc/Desktop/swift-auto-diagram/rubyResources/helpers.rb:5:in each' from /Users/abc/Desktop/swift-auto-diagram/rubyResources/helpers.rb:5:in entitiesFromFiles'
from generateEntityDiagram.rb:59:in `

'

Unsharp HTML

First of all - I love the idea and really need this tool.
Maybe, I could contribute if you want so and I find the necessary time.
Unfortunately the HTML is completely unsharp when trying to get the diagram for my medium-large project.

Single protocol conformance on a class assumed to be inheritance

A class that conforms to a single protocol only and does not inherit is assumed to inherit from the protocol, which is assumed to be a class.

For example:

class Day: Comparable {
    // ...
}

produces this:

screen shot 2017-02-25 at 14 01 00

Whereas it should say "conforms to" and "protocol Comparable"

is not a directory and does not have a '.swift' extension

try to generate docs for swift 2.3 project

  1. git clone https://github.com/yoshimkd/swift-auto-diagram
  2. cd "docs folder/swift-auto-diagram/"
  3. ruby generateEntityDiagram.rb '/Users/User/Path/To/Root/Project Folder/'

...

result:

The argument '/Users/andrewskrypnik/Concepter\ Apps/Soul/' is not a directory and does not have a '.swift' extension

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.