Skip to content

Instantly share code, notes, and snippets.

@bruno-brant
Last active March 25, 2020 12:02
Show Gist options
  • Save bruno-brant/a3e0cfb96e36aab870eb4a3604d0428b to your computer and use it in GitHub Desktop.
Save bruno-brant/a3e0cfb96e36aab870eb4a3604d0428b to your computer and use it in GitHub Desktop.
PS Script to process all plantuml diagrams in a directory tree
<#
.SYNOPSIS
Use this script to generate all diagrams files in the subdirectory tree
(all files ending with .plantuml)
.DESCRIPTION
This script filters files in the subdirectory three from its location and
call plantuml for each file that was found.
To use the script, plantuml need to be in the path. We suggest you use scoop
(https://scoop.sh/) to install plantuml (and java, which is a dependency for plantuml).
The script identifies the files using, by default, the extension ".plantuml". You
can customize this setting, but this isn't recommended.
We recommend that you name every diagram (just add a string after @startuml). You should
have one .plantuml file for each markdown file, and link directly to the pictures that
you named.
You can use -Verbose to diagnose problems.
#>
[CmdletBinding()]
Param(
[switch] $Monitor,
[Parameter(HelpMessage = "Extension of diagram files.")]
[string] $DiagramExt = "plantuml"
)
ls -Recurse -Filter "*.$DiagramExt" | %{
Write-Verbose $_.FullName
plantuml $_.FullName
}
if ($Monitor) {
Write-Host "Monitoring file changes"
$fsw = New-Object IO.FileSystemWatcher $PWD, "*.$diagramExt" -Property @{IncludeSubdirectories = $true; NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Verbose "The file '$name' was $changeType at $timeStamp"
plantuml $name
}
Register-ObjectEvent $fsw Changed -SourceIdentifier FileChanged -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Verbose "The file '$name' was $changeType at $timeStamp"
plantuml $name
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment