11<#
22 . SYNOPSIS
33 The script to find examples in ".md" and analyze the examples by custom rules.
4+ . PARAMETER MarkdownPaths
5+ Markdown searching paths. Empty for current path. Supports wildcard.
6+ . PARAMETER ScriptPath
7+ PowerShell script searching path.
8+ . PARAMETER RulePaths
9+ PSScriptAnalyzer custom rules paths. Empty for current path. Supports wildcard.
10+ . PARAMETER CodeMapPath
11+ Code map path bound with the PowerShell script.
12+ . PARAMETER Recurse
13+ To search markdowns recursively in the folders.
14+ . PARAMETER IncludeDefaultRules
15+ To analyze default rules provided by PSScriptAnalyzer.
16+ . PARAMETER OutputFolder
17+ Folder path storing output files.
18+ . PARAMETER SkipAnalyzing
19+ To skip analyzing step. Only extracting example codes from markdowns to the temp script.
20+ . PARAMETER CleanScripts
21+ To clean the temp script.
422 . NOTES
523 File Name: Measure-MarkdownOrScript.ps1
624#>
927
1028[CmdletBinding (DefaultParameterSetName = " Markdown" )]
1129param (
12- [Parameter (Mandatory , HelpMessage = " Markdown searching paths. Empty for current path. Supports wildcard. " , ParameterSetName = " Markdown" )]
30+ [Parameter (Mandatory , ParameterSetName = " Markdown" )]
1331 [AllowEmptyString ()]
1432 [string []]$MarkdownPaths ,
15- [Parameter (Mandatory , HelpMessage = " PowerShell scripts searching paths. Empty for current path. Supports wildcard. " , ParameterSetName = " Script" )]
33+ [Parameter (Mandatory , ParameterSetName = " Script" )]
1634 [AllowEmptyString ()]
17- [string []]$ScriptPaths ,
18- [Parameter (HelpMessage = " PSScriptAnalyzer custom rules paths. Empty for current path. Supports wildcard." )]
35+ [string []]$ScriptPath ,
1936 [string []]$RulePaths ,
37+ [Parameter (Mandatory , ParameterSetName = " Script" )]
2038 [string ]$CodeMapPath ,
39+ [Parameter (ParameterSetName = " Markdown" )]
2140 [switch ]$Recurse ,
2241 [switch ]$IncludeDefaultRules ,
2342 [string ]$OutputFolder = " $PSScriptRoot \..\..\..\artifacts\StaticAnalysisResults\ExampleAnalysis" ,
24- [switch ] $AnalyzeScriptsInFile ,
25- [switch ]$OutputScriptsInFile ,
43+ [Parameter ( ParameterSetName = " Markdown " )]
44+ [switch ]$SkipAnalyzing ,
2645 [switch ]$CleanScripts
2746)
2847
@@ -35,12 +54,10 @@ $totalLine = 1
3554# Find examples in "help\*.md", output ".ps1"
3655if ($PSCmdlet.ParameterSetName -eq " Markdown" ) {
3756 # Clean caches, remove files in "output" folder
38- if ($OutputScriptsInFile.IsPresent ) {
39- Remove-Item $OutputFolder \TempScript.ps1 - ErrorAction SilentlyContinue
40- Remove-Item $OutputFolder \TempCodeMap.csv - ErrorAction SilentlyContinue
41- Remove-Item $PSScriptRoot \..\..\..\artifacts\StaticAnalysisResults\ExampleIssues.csv - ErrorAction SilentlyContinue
42- Remove-Item $OutputFolder - ErrorAction SilentlyContinue
43- }
57+ Remove-Item $OutputFolder \TempScript.ps1 - ErrorAction SilentlyContinue
58+ Remove-Item $OutputFolder \TempCodeMap.csv - ErrorAction SilentlyContinue
59+ Remove-Item $PSScriptRoot \..\..\..\artifacts\StaticAnalysisResults\ExampleIssues.csv - ErrorAction SilentlyContinue
60+ Remove-Item $OutputFolder - ErrorAction SilentlyContinue
4461 $null = New-Item - ItemType Directory - Path $OutputFolder - ErrorAction SilentlyContinue
4562 $null = New-Item - ItemType File $OutputFolder \TempScript.ps1
4663 # When the input $MarkdownPaths is the path of txt file
@@ -66,7 +83,6 @@ if ($PSCmdlet.ParameterSetName -eq "Markdown") {
6683 }
6784 $cmdlet = $_.BaseName
6885 $result = Measure-SectionMissingAndOutputScript $module $cmdlet $_.FullName `
69- - OutputScriptsInFile:$OutputScriptsInFile.IsPresent `
7086 - OutputFolder $OutputFolder `
7187 - TotalLine $totalLine
7288 $analysisResultsTable += $result.Errors
@@ -75,19 +91,19 @@ if ($PSCmdlet.ParameterSetName -eq "Markdown") {
7591 }
7692 }
7793 $codeMap | Export-Csv " $OutputFolder \TempCodeMap.csv" - NoTypeInformation
78- if ($AnalyzeScriptsInFile .IsPresent ) {
79- $ScriptPaths = " $OutputFolder \TempScript.ps1"
94+ if (! $SkipAnalyzing .IsPresent ) {
95+ $ScriptPath = " $OutputFolder \TempScript.ps1"
8096 $CodeMapPath = " $OutputFolder \TempCodeMap.csv"
8197 }
8298}
8399
84100# Analyze scripts
85- if ($PSCmdlet.ParameterSetName -eq " Script" -or $AnalyzeScriptsInFile .IsPresent ) {
101+ if ($PSCmdlet.ParameterSetName -eq " Script" -or ! $SkipAnalyzing .IsPresent ) {
86102 # Read code map from file
87103 $codeMap = Import-Csv $CodeMapPath
88104 # Read and analyze ".ps1" in \ScriptsByExample
89105 Write-Output " Analyzing file ..."
90- $analysisResultsTable += Get-ScriptAnalyzerResult (Get-Item - Path $ScriptPaths ) $RulePaths - IncludeDefaultRules:$IncludeDefaultRules.IsPresent $codeMap - ErrorAction Continue
106+ $analysisResultsTable += Get-ScriptAnalyzerResult (Get-Item - Path $ScriptPath ) $RulePaths - IncludeDefaultRules:$IncludeDefaultRules.IsPresent $codeMap - ErrorAction Continue
91107
92108 # Summarize analysis results, output in Result.csv
93109 if ($analysisResultsTable ){
@@ -97,5 +113,5 @@ if ($PSCmdlet.ParameterSetName -eq "Script" -or $AnalyzeScriptsInFile.IsPresent)
97113
98114# Clean caches
99115if ($CleanScripts.IsPresent ) {
100- Remove-Item $ScriptPaths - Exclude * .csv - Recurse - ErrorAction Continue
116+ Remove-Item $ScriptPath - Exclude * .csv - Recurse - ErrorAction Continue
101117}
0 commit comments