-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathParseWorkflowAnalyzerOutput.ps1
More file actions
40 lines (32 loc) · 1.57 KB
/
ParseWorkflowAnalyzerOutput.ps1
File metadata and controls
40 lines (32 loc) · 1.57 KB
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
param
(
[string]$projectFile = $(throw "projectFile is required."),
[string]$outFile = $(throw "outFile is required.")
)
if (-not [System.IO.File]::Exists($projectFile))
{
throw "Project File doesn't exist"
}
# Default Path for MSI installation
$workflowAnalyzerExe = "c:\Program Files (x86)\UiPath\Studio\UiPath.Studio.CommandLine.exe"
$output = & $workflowAnalyzerExe analyze -p $projectFile 2>$null
# extract just the json output
$jsonOutput = ConvertFrom-Json ([regex]::match($output, "(?<=\#json)(.|\n)*(?=\#json)").Groups[0].Value)
$rules = New-Object System.Collections.ArrayList
$uniqueRuleIds = ($jsonOutput | Get-Member | Where-Object {$_.Name.Length -ge 37}).Name.Substring(0,36) | Unique
ForEach ($ruleId in $uniqueRuleIds)
{
$ruleObject = New-Object PSObject
$ruleProperties = ($jsonOutput | Get-Member | Where-Object {$_.Name -and ($_.Name.Length -gt 36) -and ($_.Name.Substring(0,36) -eq $ruleId)}).Name.Substring(37)
$ruleObject | Add-Member -NotePropertyName Id -NotePropertyValue $ruleId
$ruleProperties | % {$ruleObject | Add-Member -NotePropertyName $_ -NotePropertyValue $jsonOutput."$ruleId-$_"}
$rules.Add($ruleObject) >$null
}
$rules | ConvertTo-Json | Out-File $outFile
if ($rules.ErrorSeverity.Contains("Error"))
{
$errorSummary = ($rules | Where-Object {$_.ErrorSeverity -eq "Error"} | Select ErrorCode, Description, FilePath) | ConvertTo-Json
$exceptionMessage = "1 or more Errors were found in the project. Check $outFile for more details. Summary: " + $errorSummary
$Host.UI.WriteErrorLine($exceptionMessage)
Exit 1
}