-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathShow-BuildDgml.ps1
144 lines (121 loc) · 3.58 KB
/
Show-BuildDgml.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<#
.Synopsis
Shows Invoke-Build task graph using DGML.
Copyright (c) Roman Kuzmin
.Description
Requires:
- Visual Studio: Individual components \ Code tools \ DGML editor.
- Invoke-Build is in the path or available as the module command.
The script calls Invoke-Build in order to get the tasks, builds the DGML
and invokes the associated application (Visual Studio) in order to show it.
Tasks with code are shown as boxes, tasks without code are shown as ovals.
Safe references are shown with dotted edges, regular calls are shown with
solid edges. Job numbers are not shown by default.
EXAMPLES
# Make and show DGML for the default build script
Show-BuildDgml
# Make Build.dgml with job numbers
Show-BuildDgml -Number -NoShow -Output Build.dgml
.Parameter File
See: help Invoke-Build -Parameter File
.Parameter Output
The output file and the format specified by its extension.
The default is "$env:TEMP\name-xxxxxxxx.dgml".
.Parameter Parameters
Build script parameters needed in special cases when they alter tasks.
.Parameter NoShow
Tells to create the output file without showing it.
In this case Output is normally specified by a caller.
.Parameter Number
Tells to show job numbers on edges connecting tasks.
.Link
https://github.com/nightroman/Invoke-Build
#>
param(
[Parameter(Position=0)]
[string]$File
,
[Parameter(Position=1)]
[string]$Output
,
[hashtable]$Parameters
,
[switch]$NoShow
,
[switch]$Number
)
$ErrorActionPreference = 1
### resolve output
if ($Output) {
$Output = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($Output)
}
else {
$path = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($(if ($File) {$File} else {''}))
$name = [System.IO.Path]::GetFileNameWithoutExtension($path)
$hash = [System.IO.Path]::GetFileName([System.IO.Path]::GetDirectoryName($path))
$Output = [System.IO.Path]::GetTempPath() + "$name-$hash.dgml"
}
### get tasks
if (!$Parameters) {$Parameters = @{}}
$all = Invoke-Build ?? $File @Parameters
### for synopses
$docs = @{}
. Invoke-Build
### make DGML
$xml = [xml]'<?xml version="1.0" encoding="utf-8"?><DirectedGraph/>'
$doc = $xml.DocumentElement
$nodes = $doc.AppendChild($xml.CreateElement('Nodes'))
$links = $doc.AppendChild($xml.CreateElement('Links'))
$styles = $doc.AppendChild($xml.CreateElement('Styles'))
$styles.InnerXml = @'
<Style TargetType="Node">
<Condition Expression="HasCategory('Calls')" />
<Setter Property="NodeRadius" Value="15" />
</Style>
<Style TargetType="Node">
<Condition Expression="HasCategory('Script')" />
<Setter Property="NodeRadius" Value="2" />
</Style>
'@
foreach($it in $all.get_Values()) {
$name = $it.Name
$node = $nodes.AppendChild($xml.CreateElement('Node'))
$node.SetAttribute('Id', $name)
if ($synopsis = Get-BuildSynopsis $it $docs) {
$node.SetAttribute('Synopsis', $synopsis)
}
$jobNumber = 0
$hasScript = $false
foreach($job in $it.Jobs) {
++$jobNumber
if ($job -is [string]) {
$job, $safe = if ($job[0] -eq '?') {$job.Substring(1), 1} else {$job}
$job = $all[$job].Name
$link = $links.AppendChild($xml.CreateElement('Link'))
$link.SetAttribute('Source', $name)
$link.SetAttribute('Target', $job)
if ($Number) {
$link.SetAttribute('Label', $jobNumber)
}
if ($safe) {
$link.SetAttribute('StrokeDashArray', '2 2')
}
}
else {
$hasScript = $true
}
}
if ($hasScript) {
$node.SetAttribute('Category', 'Script')
}
else {
$node.SetAttribute('Category', 'Calls')
}
}
### save DGML
$doc.SetAttribute('xmlns', 'http://schemas.microsoft.com/vs/2009/dgml')
$xml.Save($Output)
### show file
if (!$NoShow) {
Invoke-Item -LiteralPath $Output
}