maephisto666 / puppeteer

Code samples for scripting Structurizr with Puppeteer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Structurizr Puppeteer

This repo contains some Node.js examples of how to script and automate parts of the Structurizr web application using Puppeteer (and headless Chrome) from the command line, perhaps as a part of your build process. Examples of what you can do include:

  • Export diagrams and keys to PNG or SVG formats.
  • Export all diagrams to a single HTML page for offline use.

See Structurizr - Help - Scripting - Diagrams for more details.

Examples

The command line examples that follow assume that you have Puppeteer installed. Please see Puppeteer for details of how to install Puppeteer on your platform.

Exporting diagrams from a public workspace

The export-public-diagrams.js script will export diagrams and keys from a public Structurizr workspace, creating a number of PNG or SVG (HTML) files in the current directory.

node export-public-diagrams.js <structurizrUrl> <png|svg> <workspace ID> [diagram key]

For example, to export all diagrams (and keys) from the Big Bank plc example workspace:

node export-public-diagrams.js https://structurizr.com png 36141

And to export a single diagram:

node export-public-diagrams.js https://structurizr.com png 36141 SystemContext

Exporting diagrams from a private workspace

The export-private-diagrams.js script will export diagrams and keys from a private Structurizr workspace (on the cloud service), creating a number of PNG or SVG (HTML) files in the current directory.

node export-private-diagrams.js <structurizrUrl> <username> <password> <png|svg> <workspaceId> [diagramKey]

For example, to export all diagrams (and keys) from a private workspace, with ID 123456:

node export-private-diagrams.js https://structurizr.com username password png 123456

Auto-layout

By default, Structurizr will only apply an auto-layout algorithm if the diagram definition doesn't include any layouting information; i.e. there are no x,y coordinates specified for any of the elements on the diagram. To force an auto-layout algorithm, call the structurizr.scripting.setAutoLayout(bool) function with true or false before changing the view. Alternatively, you can set a query string parameter named autoLayout to true when opening the workspace diagrams or Express page. You can do this by modifying the URL used by Puppeteer in the above scripts.

About

Code samples for scripting Structurizr with Puppeteer.

License:Apache License 2.0


Languages

Language:JavaScript 100.0%