Skip to content

Commit 45c33a8

Browse files
Merge pull request #40 from PowershellFrameworkCollective/development
2.2.5.26
2 parents ae4451d + c180c83 commit 45c33a8

File tree

106 files changed

+618
-753
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+618
-753
lines changed

PSModuleDevelopment.psprojs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<ProjectState>
2+
<Version>1.0</Version>
3+
<FileID>ee06e6d7-dec0-4ce5-a609-25ceb3954c83</FileID>
4+
<OpenFolders>
5+
<Folder>templates</Folder>
6+
<Folder>templates\PSFTests</Folder>
7+
<Folder>templates\PSFTests\functions</Folder>
8+
<Folder>templates\PSFTests\general</Folder>
9+
</OpenFolders>
10+
<OpenFiles>
11+
<File>templates\PSFTests\pester.ps1</File>
12+
<File>templates\PSFTests\functions\readme.md</File>
13+
<File>templates\PSFTests\general\FileIntegrity.Exceptions.ps1</File>
14+
<File>templates\PSFTests\general\FileIntegrity.Tests.ps1</File>
15+
<File>templates\PSFTests\general\Help.Exceptions.ps1</File>
16+
<File>templates\PSFTests\general\Help.Tests.ps1</File>
17+
<File>templates\PSFTests\general\Manifest.Tests.ps1</File>
18+
<File>templates\PSFTests\general\PSScriptAnalyzer.Tests.ps1</File>
19+
</OpenFiles>
20+
</ProjectState>

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
RootModule = 'PSModuleDevelopment.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '2.2.4.18'
7+
ModuleVersion = '2.2.5.26'
88

99
# ID used to uniquely identify this module
1010
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'
@@ -41,7 +41,7 @@
4141

4242
# Modules that must be imported into the global environment prior to importing
4343
# this module
44-
RequiredModules = @(@{ ModuleName='PSFramework'; ModuleVersion= '0.9.16.44' })
44+
RequiredModules = @(@{ ModuleName='PSFramework'; ModuleVersion= '0.9.25.112' })
4545

4646
# Assemblies that must be loaded prior to importing this module
4747
RequiredAssemblies = @('bin\PSModuleDevelopment.dll')
@@ -79,10 +79,12 @@
7979
'New-PSMDModuleNugetPackage',
8080
'New-PSMDTemplate',
8181
'New-PssModuleProject',
82+
'Read-PSMDScript',
8283
'Remove-PSMDModuleDebug',
8384
'Remove-PSMDTemplate',
8485
'Rename-PSMDParameter',
8586
'Restart-PSMDShell',
87+
'Set-PSMDEncoding',
8688
'Set-PSMDModuleDebug',
8789
'Set-PSMDCmdletBinding',
8890
'Set-PSMDModulePath',
@@ -102,9 +104,10 @@
102104
'find',
103105
'hex',
104106
'imt',
107+
'ipmod',
108+
'parse',
105109
'Restart-Shell',
106110
'rss',
107-
'ipmod',
108111
'smd'
109112
)
110113

PSModuleDevelopment/PSModuleDevelopment.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
$script:PSModuleRoot = $PSScriptRoot
2-
$script:PSModuleVersion = "2.2.4.18"
2+
$script:PSModuleVersion = "2.2.5.26"
33

44
$script:doDotSource = $false
55
if (Get-PSFConfigValue -FullName PSModuleDevelopment.Import.DoDotSource) { $script:doDotSource = $true }

PSModuleDevelopment/changelog.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
# Changelog
1+
# Changelog
2+
## 2.2.5.26 (September 06th, 2018)
3+
- New: Command Read-PSMDScript (Alias: parse)
4+
- New: Command Set-PSMDEncoding
5+
- New: Template PSFTests - Default module tests
6+
- New: Template CommandTest - A tempalte that generate a test from an already existing command.
7+
- Upd: Template PSFModule - some fixes
8+
- Upd: Template PSFProject - some fixes and improvements to the installer
9+
- Fix: Template function - encoding error
10+
- Fix: New-PSMDTemplate - now properly selects scriptblocks across multiple lines
11+
212
## 2.2.4.18 (May 04rd, 2018)
313
- Upd: New-PSMDFormatTableDefinition - Update to add parameters `-IncludePropertyAttribute` and `-ExcludePropertyAttribute`
414

PSModuleDevelopment/functions/assembly/Find-PSMDType.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
3030
.PARAMETER Enum
3131
Whether the type to find must be an enumeration.
32+
33+
.PARAMETER Static
34+
Whether the type to find must be static.
3235
3336
.PARAMETER Implements
3437
Whether the type to find must implement this interface
@@ -70,6 +73,9 @@
7073
[switch]
7174
$Enum,
7275

76+
[switch]
77+
$Static,
78+
7379
[string]
7480
$Implements,
7581

@@ -84,6 +90,7 @@
8490
{
8591
$boundEnum = Test-PSFParameterBinding -ParameterName Enum
8692
$boundPublic = Test-PSFParameterBinding -ParameterName Public
93+
$boundStatic = Test-PSFParameterBinding -ParameterName Static
8794
}
8895
process
8996
{
@@ -114,6 +121,7 @@
114121
if ($boundEnum -and ($Enum -ne $type.IsEnum)) { continue }
115122
if ($InheritsFrom -and ($type.BaseType.FullName -notlike $InheritsFrom)) { continue }
116123
if ($Attribute -and ($type.CustomAttributes.AttributeType.Name -notlike $Attribute)) { continue }
124+
if ($boundStatic -and ($Static -ne ($type.IsAbstract -and $type.IsSealed))) { continue }
117125

118126
$type
119127
}
@@ -123,4 +131,4 @@
123131
{
124132

125133
}
126-
}
134+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
function Read-PSMDScript
2+
{
3+
<#
4+
.SYNOPSIS
5+
Parse the content of a script
6+
7+
.DESCRIPTION
8+
Uses the powershell parser to parse the content of a script or scriptfile.
9+
10+
.PARAMETER ScriptCode
11+
The scriptblock to parse.
12+
13+
.PARAMETER Path
14+
Path to the scriptfile to parse.
15+
Silently ignores folder objects.
16+
17+
.EXAMPLE
18+
PS C:\> Read-PSMDScript -ScriptCode $ScriptCode
19+
20+
Parses the code in $ScriptCode
21+
22+
.EXAMPLE
23+
PS C:\> Get-ChildItem | Read-PSMDScript
24+
25+
Parses all script files in the current directory
26+
#>
27+
[CmdletBinding()]
28+
param (
29+
[Parameter(Position = 0, ParameterSetName = 'Script', Mandatory = $true)]
30+
[System.Management.Automation.ScriptBlock]
31+
$ScriptCode,
32+
33+
[Parameter(Mandatory = $true, ParameterSetName = 'File', ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
34+
[Alias('FullName')]
35+
[string[]]
36+
$Path
37+
)
38+
39+
begin
40+
{
41+
Write-PSFMessage -Level InternalComment -Message "Bound parameters: $($PSBoundParameters.Keys -join ", ")" -Tag 'debug', 'start', 'param'
42+
}
43+
process
44+
{
45+
foreach ($file in $Path)
46+
{
47+
Write-PSFMessage -Level Verbose -Message "Processing $file" -Target $file
48+
$item = Get-Item $file
49+
if ($item.PSIsContainer)
50+
{
51+
Write-PSFMessage -Level Verbose -Message "is folder, skipping $file" -Target $file
52+
continue
53+
}
54+
55+
$tokens = $null
56+
$errors = $null
57+
$ast = [System.Management.Automation.Language.Parser]::ParseFile($item.FullName, [ref]$tokens, [ref]$errors)
58+
[pscustomobject]@{
59+
PSTypeName = 'PSModuleDevelopment.Meta.ParseResult'
60+
Ast = $ast
61+
Tokens = $tokens
62+
Errors = $errors
63+
File = $item.FullName
64+
}
65+
}
66+
67+
if ($ScriptCode)
68+
{
69+
$tokens = $null
70+
$errors = $null
71+
$ast = [System.Management.Automation.Language.Parser]::ParseInput($ScriptCode, [ref]$tokens, [ref]$errors)
72+
[pscustomobject]@{
73+
PSTypeName = 'PSModuleDevelopment.Meta.ParseResult'
74+
Ast = $ast
75+
Tokens = $tokens
76+
Errors = $errors
77+
Source = $ScriptCode
78+
}
79+
}
80+
}
81+
}
82+
Set-Alias -Name parse -Value Read-PSMDScript
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
function Set-PSMDEncoding
2+
{
3+
<#
4+
.SYNOPSIS
5+
Sets the encoding for the input file.
6+
7+
.DESCRIPTION
8+
This command reads the input file using the default encoding interpreter.
9+
It then writes the contents as the specified enconded string back to itself.
10+
11+
There is no inherent encoding conversion enacted, so special characters may break.
12+
This is a tool designed to reformat code files, where special characters shouldn't be used anyway.
13+
14+
.PARAMETER Path
15+
Path to the files to be set.
16+
Silently ignores folders.
17+
18+
.PARAMETER Encoding
19+
The encoding to set to (Defaults to "UTF8 with BOM")
20+
21+
.PARAMETER EnableException
22+
Replaces user friendly yellow warnings with bloody red exceptions of doom!
23+
Use this if you want the function to throw terminating errors you want to catch.
24+
25+
.PARAMETER Confirm
26+
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.
27+
28+
.PARAMETER WhatIf
29+
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
30+
31+
.EXAMPLE
32+
PS C:\> Get-ChildItem -Recurse | Set-PSMDEncoding
33+
34+
Converts all files in the current folder and subfolders to UTF8
35+
#>
36+
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
37+
param (
38+
[Parameter(ValueFromPipeline = $true, Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
39+
[Alias('FullName')]
40+
[string[]]
41+
$Path,
42+
43+
[System.Text.Encoding]
44+
$Encoding = [System.Text.Encoding]::UTF8,
45+
46+
[switch]
47+
$EnableException
48+
)
49+
50+
begin
51+
{
52+
Write-PSFMessage -Level InternalComment -Message "Bound parameters: $($PSBoundParameters.Keys -join ", ")" -Tag 'debug', 'start', 'param'
53+
}
54+
process
55+
{
56+
foreach ($pathItem in $Path)
57+
{
58+
Write-PSFMessage -Level VeryVerbose -Message "Processing $pathItem" -Target $pathItem
59+
try { $pathResolved = Resolve-PSFPath -Path $pathItem -Provider FileSystem }
60+
catch { Stop-PSFFunction -Message " " -EnableException $EnableException -ErrorRecord $_ -Target $pathItem -Continue }
61+
62+
foreach ($resolvedPath in $pathResolved)
63+
{
64+
if ((Get-Item $resolvedPath).PSIsContainer) { continue }
65+
66+
Write-PSFMessage -Level Verbose -Message "Setting encoding for $resolvedPath" -Target $pathItem
67+
try
68+
{
69+
if (Test-PSFShouldProcess -PSCmdlet $PSCmdlet -Target $resolvedPath -Action "Set encoding to $($Encoding.EncodingName)")
70+
{
71+
$text = [System.IO.File]::ReadAllText($resolvedPath)
72+
[System.IO.File]::WriteAllText($resolvedPath, $text, $Encoding)
73+
}
74+
}
75+
catch
76+
{
77+
Stop-PSFFunction -Message "Failed to access file! $resolvedPath" -EnableException $EnableException -ErrorRecord $_ -Target $pathItem -Continue
78+
}
79+
}
80+
}
81+
}
82+
}

PSModuleDevelopment/functions/templating/Invoke-PSMDTemplate.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
7373
Creates a project based on the module template with the name "MyModule"
7474
#>
75+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSPossibleIncorrectUsageOfAssignmentOperator", "")]
7576
[CmdletBinding(SupportsShouldProcess = $true)]
7677
param (
7778
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Template')]

PSModuleDevelopment/functions/templating/New-PSMDTemplate.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@
324324
325325
Chained together in a logical or, in order to avoid combination issues.
326326
#>
327-
$pattern = "$($Identifier)([^{}!]+?)$($Identifier)|$($Identifier)!([^{}!]+?)!$($Identifier)|$($Identifier){(.+?)}$($Identifier)"
327+
$pattern = "$($Identifier)([^{}!]+?)$($Identifier)|$($Identifier)!([^{}!]+?)!$($Identifier)|(?ms)$($Identifier){(.+?)}$($Identifier)"
328328
#endregion Regex
329329

330330
$name = $Item.Name
Binary file not shown.

0 commit comments

Comments
 (0)