Scripting support added to the Structurizr DSL

The Structurizr DSL now provides a way to run scripts written in Groovy, Kotlin, Ruby, and JavaScript, via the new !script keyword. This gives you access to the underlying Structurizr for Java workspace, for when you need to do something not supported …


This content originally appeared on DEV Community and was authored by Simon Brown

The Structurizr DSL now provides a way to run scripts written in Groovy, Kotlin, Ruby, and JavaScript, via the new !script keyword. This gives you access to the underlying Structurizr for Java workspace, for when you need to do something not supported by the DSL.

For example, you could use a script to create the default set of views, without automatic layout enabled:

workspace {

    model {
        user = person "User"
        softwareSystem = softwareSystem "Software System"

        user -> softwareSystem "Uses"
    }

    !script groovy {
        workspace.views.createDefaultViews()
        workspace.views.views.each { it.disableAutomaticLayout() }
    }   

}

You could also use a script to programmatically add elements to a view, using more complicated logic than is possible via the DSL alone.

workspace {

    model {
        group "Group 1" {
            a = softwareSystem "A" {
                tags "Tag 1"
            }
            b = softwareSystem "B" {
                tags "Tag 2"
            }
        }
        group "Group 2" {
            c = softwareSystem "C" {
                tags "Tag 1"
            }
            d = softwareSystem "D" {
                tags "Tag 2"
            }
        }
    }

    views {
        systemLandscape "key" {
            !script groovy {
                view = workspace.views.getViewWithKey("key");
                workspace.model.softwareSystems.findAll { it.group == "Group 1" && it.hasTag("Tag 1") }.each{ view.add(it); };
            }

            autolayout
        }
    }

}

Scripting support is available now, via the open source Structurizr CLI and the free Structurizr Lite. See the Structurizr DSL language reference - Scripts and the Structurizr DSL cookbook - Scripts for more details.


This content originally appeared on DEV Community and was authored by Simon Brown


Print Share Comment Cite Upload Translate Updates
APA

Simon Brown | Sciencx (2021-09-10T16:10:41+00:00) Scripting support added to the Structurizr DSL. Retrieved from https://www.scien.cx/2021/09/10/scripting-support-added-to-the-structurizr-dsl/

MLA
" » Scripting support added to the Structurizr DSL." Simon Brown | Sciencx - Friday September 10, 2021, https://www.scien.cx/2021/09/10/scripting-support-added-to-the-structurizr-dsl/
HARVARD
Simon Brown | Sciencx Friday September 10, 2021 » Scripting support added to the Structurizr DSL., viewed ,<https://www.scien.cx/2021/09/10/scripting-support-added-to-the-structurizr-dsl/>
VANCOUVER
Simon Brown | Sciencx - » Scripting support added to the Structurizr DSL. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/10/scripting-support-added-to-the-structurizr-dsl/
CHICAGO
" » Scripting support added to the Structurizr DSL." Simon Brown | Sciencx - Accessed . https://www.scien.cx/2021/09/10/scripting-support-added-to-the-structurizr-dsl/
IEEE
" » Scripting support added to the Structurizr DSL." Simon Brown | Sciencx [Online]. Available: https://www.scien.cx/2021/09/10/scripting-support-added-to-the-structurizr-dsl/. [Accessed: ]
rf:citation
» Scripting support added to the Structurizr DSL | Simon Brown | Sciencx | https://www.scien.cx/2021/09/10/scripting-support-added-to-the-structurizr-dsl/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.