structurizr / cli

A command line utility for Structurizr.
https://docs.structurizr.com/cli
Apache License 2.0
491 stars 75 forks source link

Apply autolayout to workspace's JSON #62

Closed souliane closed 2 years ago

souliane commented 2 years ago

Hello,

I have a JSON representation of a workspace and I would like to automatically fill the x and y attributes of the view's components (for example with Graphviz). Is it possible to do that with the cli or do I need to use https://github.com/structurizr/java-extensions/tree/master/structurizr-graphviz directly?

(Ideally, an option to the export command could do this)

simonbrowndotje commented 2 years ago

You could do something like this:

  1. Create yourself a new DSL file (e.g. graphviz.dsl), that extends your JSON workspace, and applies graphviz.
workspace extends workspace.json {

    !script groovy {
        new com.structurizr.graphviz.GraphvizAutomaticLayout().apply(workspace);
    }

}
  1. Use the CLI to export to a new JSON file.
./structurizr.sh export -workspace graphviz.dsl -format json
souliane commented 2 years ago

Awesome! Thank you.