Skip to content

Instantly share code, notes, and snippets.

@delphyne
Created January 30, 2024 14:27
Show Gist options
  • Save delphyne/5061f7cd8760574e7ae6cc2f4a2379f3 to your computer and use it in GitHub Desktop.
Save delphyne/5061f7cd8760574e7ae6cc2f4a2379f3 to your computer and use it in GitHub Desktop.
Structurizr scripts
/**
* Auto generate diagrams for anything that wasn't already created manually.
* Be sure to create your manually adjusted diagrams before this script is invoked, or you'll have duplicates.
*/
!script groovy {
import com.structurizr.view.AutomaticLayout; \
def sysctxviews = workspace.views.systemContextViews.collect { \
it.softwareSystem; \
} as Set; \
def containerviews = workspace.views.containerViews.collect { \
it.softwareSystem; \
} as Set; \
def componentviews = workspace.views.componentViews.collect { \
it.container;
} as Set; \
workspace.model.softwareSystems.each { \
if (it !in sysctxviews) { \
def sysctx = workspace.views.createSystemContextView(it, "${it.name} System Context View", null); \
sysctx.addDefaultElements(); \
sysctx.automaticLayout = new AutomaticLayout(AutomaticLayout.Implementation.Graphviz, AutomaticLayout.RankDirection.TopBottom, 150, 150, 0, true); \
}; \
if (it.containers && it !in containerviews) { \
def container = workspace.views.createContainerView(it, "${it.name} Container View", null); \
container.addDefaultElements(); \
container.automaticLayout = new AutomaticLayout(AutomaticLayout.Implementation.Graphviz, AutomaticLayout.RankDirection.TopBottom, 150, 150, 0, true); \
};
it.containers.each { \
if (it.components && it !in componentviews) { \
def component = workspace.views.createComponentView(it, "${it.name} Component View", null); \
component.addDefaultElements(); \
component.automaticLayout = new AutomaticLayout(AutomaticLayout.Implementation.Graphviz, AutomaticLayout.RankDirection.TopBottom, 150, 150, 0, true); \
}; \
}; \
};
}
/**
* Fix for the example script that copies tech to tags.
*/
!script groovy {
workspace.model.elements.findAll { it.hasProperty("technology") && it.hasProperty("tags") }.each { it.addTags(it.technology) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment