Skip to content

Commit b93b85b

Browse files
Merge pull request #125 from PowershellFrameworkCollective/development
2.2.8.103
2 parents 5a469ad + 9987293 commit b93b85b

File tree

13 files changed

+605
-41
lines changed

13 files changed

+605
-41
lines changed

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 9 additions & 20 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.7.98'
7+
ModuleVersion = '2.2.8.103'
88

99
# ID used to uniquely identify this module
1010
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'
@@ -24,25 +24,10 @@
2424
# Minimum version of the Windows PowerShell engine required by this module
2525
PowerShellVersion = '3.0'
2626

27-
# Name of the Windows PowerShell host required by this module
28-
PowerShellHostName = ''
29-
30-
# Minimum version of the Windows PowerShell host required by this module
31-
PowerShellHostVersion = ''
32-
33-
# Minimum version of the .NET Framework required by this module
34-
DotNetFrameworkVersion = '2.0'
35-
36-
# Minimum version of the common language runtime (CLR) required by this module
37-
CLRVersion = '2.0.50727'
38-
39-
# Processor architecture (None, X86, Amd64, IA64) required by this module
40-
ProcessorArchitecture = 'None'
41-
4227
# Modules that must be imported into the global environment prior to importing
4328
# this module
4429
RequiredModules = @(
45-
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.0.35' }
30+
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.1.59' }
4631
)
4732

4833
# Assemblies that must be loaded prior to importing this module
@@ -72,6 +57,7 @@
7257
'Get-PSMDArgumentCompleter',
7358
'Get-PSMDAssembly',
7459
'Get-PSMDConstructor',
60+
'Get-PSMDFileCommand',
7561
'Get-PSMDHelp',
7662
'Get-PSMDMember',
7763
'Get-PSMDModuleDebug',
@@ -86,6 +72,8 @@
8672
'New-PSMDModuleNugetPackage',
8773
'New-PSMDTemplate',
8874
'New-PssModuleProject',
75+
'Publish-PSMDScriptFile',
76+
'Publish-PSMDStagedModule',
8977
'Read-PSMDScript',
9078
'Remove-PSMDModuleDebug',
9179
'Remove-PSMDTemplate',
@@ -97,15 +85,16 @@
9785
'Set-PSMDCmdletBinding',
9886
'Set-PSMDModulePath',
9987
'Set-PSMDParameterHelp',
88+
'Set-PSMDStagingRepository',
10089
'Show-PSMDSyntax',
10190
'Split-PSMDScriptFile'
10291
)
10392

10493
# Cmdlets to export from this module
105-
CmdletsToExport = ''
94+
# CmdletsToExport = ''
10695

10796
# Variables to export from this module
108-
VariablesToExport = ''
97+
# VariablesToExport = ''
10998

11099
# Aliases to export from this module
111100
AliasesToExport = @(
@@ -145,7 +134,7 @@
145134
# IconUri = ''
146135

147136
# ReleaseNotes of this module
148-
# ReleaseNotes = ''
137+
ReleaseNotes = 'https://github.com/PowershellFrameworkCollective/PSModuleDevelopment/blob/master/PSModuleDevelopment/changelog.md'
149138

150139
} # End of PSData hashtable
151140

PSModuleDevelopment/changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# Changelog
2+
3+
## 2.2.8.103 (July 24th, 2020)
4+
5+
- New: Publish-PSMDScriptFile - Packages a script with all dependencies and "publishes" it as a zip package.
6+
- New: Get-PSMDFileCommand - Parses a scriptfile and returns the contained/used commands.
7+
- New: Set-PSMDStagingRepository - Define the repository to use for deploying modules along with scripts.
8+
- New: Publish-PSMDStagedModule - Publish a module to your staging repository.
9+
- Fix: Export-PSMDString - Random failure to execute (thanks @AndiBellstedt !)
10+
211
## 2.2.7.98 (May 30th, 2020)
312

413
- Upd: Template PSFTest - Pester v5 compatibility
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
@{
2-
'MeasurePSMDLinesOfCode.Processing' = 'Processing Path: {0}'
3-
'Remove-PSMDTemplate.Removing.Template' = 'Removing template {0} (v{1}) from store {2}'
2+
'Get-PSMDFileCommand.SyntaxError' = 'Syntax error in file: {0}' # $pathItem
3+
4+
'MeasurePSMDLinesOfCode.Processing' = 'Processing Path: {0}' # $fileItem
5+
6+
'Publish-PSMDScriptFile.Module.Saving' = 'Saving module {0} from repository {1}' # $moduleName, (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Script.StagingRepository')
7+
'Publish-PSMDScriptFile.Script.Command' = 'Processing command {0} (used {1} times) from module {2}' # $command.Name, $command.Count, $command.Module
8+
'Publish-PSMDScriptFile.Script.Command.NotKnown' = 'The command {0} (used {1} times) cannot be resolved. Manually figure out where it came from if needed.' # $command.Name, $command.Count
9+
'Publish-PSMDScriptFile.Script.ParseError' = 'Syntax error in file: {0}' # $Path
10+
11+
'Publish-PSMDStagedModule.Module.AlreadyPublished' = 'The module {0} at version {1} has already been published to this repository' # $moduleToPublish.Name, $moduleToPublish.Version
12+
'Publish-PSMDStagedModule.Module.NotFound' = 'The module {0} could not be found' # $Name
13+
'Publish-PSMDStagedModule.Module.PublishError' = 'Error publishing {0} from {1}' # $Name, $folder.Name
14+
15+
'Remove-PSMDTemplate.Removing.Template' = 'Removing template {0} (v{1}) from store {2}' # $item.Name, $item.Version, $item.Store
16+
17+
'Validate.File' = 'Path does not exist or is not a file: {0}' # <user input>, <validation item>
18+
'Validate.Path' = 'Path does not exist: {0}' # <user input>, <validation item>
419
}

PSModuleDevelopment/functions/refactor/Export-PSMDString.ps1

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
<#
44
.SYNOPSIS
55
Parses a module that uses the PSFramework localization feature for strings and their value.
6-
6+
77
.DESCRIPTION
88
Parses a module that uses the PSFramework localization feature for strings and their value.
99
This command can be used to generate and update the language files used by the module.
1010
It is also used in automatic tests, ensuring no abandoned string has been left behind and no key is unused.
11-
11+
1212
.PARAMETER ModuleRoot
1313
The root of the module to process.
1414
Must be the root folder where the psd1 file is stored in.
15-
15+
1616
.EXAMPLE
1717
PS C:\> Export-PSMDString -ModuleRoot 'C:\Code\Github\MyModuleProject\MyModule'
18-
18+
1919
Generates the strings data for the MyModule module.
2020
#>
2121
[CmdletBinding()]
@@ -25,7 +25,7 @@
2525
[string]
2626
$ModuleRoot
2727
)
28-
28+
2929
process
3030
{
3131
#region Find Language Files : $languageFiles
@@ -40,7 +40,7 @@
4040
}
4141
}
4242
#endregion Find Language Files : $languageFiles
43-
43+
4444
#region Find Keys : $foundKeys
4545
$foundKeys = foreach ($file in (Get-ChildItem -Path $ModuleRoot -Recurse | Where-Object Extension -match '^\.ps1$|^\.psm1$'))
4646
{
@@ -51,12 +51,12 @@
5151
if (-not ($args[0].CommandElements.ParameterName -match '^String$|^ActionString$')) { return $false }
5252
$true
5353
}, $true)
54-
54+
5555
foreach ($commandAst in $commandAsts)
5656
{
5757
$stringParam = $commandAst.CommandElements | Where-Object ParameterName -match '^String$|^ActionString$'
5858
$stringParamValue = $commandAst.CommandElements[($commandAst.CommandElements.IndexOf($stringParam) + 1)].Value
59-
59+
6060
$stringValueParam = $commandAst.CommandElements | Where-Object ParameterName -match '^StringValues$|^ActionStringValues$'
6161
if ($stringValueParam)
6262
{
@@ -72,7 +72,7 @@
7272
StringValues = $stringValueParamValue
7373
}
7474
}
75-
75+
7676
# Additional checks for splatted commands
7777
# find all splatted commands
7878
$splattedVariables = $ast.FindAll( {
@@ -109,10 +109,13 @@
109109
{
110110
# find any String or ActionString
111111
$splatParam = $splatAssignmentAst.Right.Expression.KeyValuePairs | Where-Object Item1 -match '^String$|^ActionString$'
112-
# The kvp.item.extent.text returns nested quotes where as the commandast.extent.text doesn't so strip them off
113-
$splatParamValue = $splatParam.Item2.Extent.Text.Trim('"').Trim("'")
114-
# find any StringValue or ActionStringValue
115-
$splatValueParam = $splatAssignmentAst.Right.Expression.KeyValuePairs | Where-Object Item1 -match '^StringValues$|^ActionStringValues$'
112+
if ($splatParam)
113+
{
114+
# The kvp.item.extent.text returns nested quotes where as the commandast.extent.text doesn't so strip them off
115+
$splatParamValue = $splatParam.Item2.Extent.Text.Trim('"').Trim("'")
116+
# find any StringValue or ActionStringValue
117+
$splatValueParam = $splatAssignmentAst.Right.Expression.KeyValuePairs | Where-Object Item1 -match '^StringValues$|^ActionStringValues$'
118+
}
116119
if ($splatValueParam)
117120
{
118121
# The kvp.item.extent.text returns nested quotes whereas the commandast.extent.text doesn't so strip them off
@@ -139,7 +142,7 @@
139142
if (-not ($args[0].NamedArguments.ArgumentName -eq 'ErrorString')) { return $false }
140143
$true
141144
}, $true)
142-
145+
143146
foreach ($validateAst in $validateAsts)
144147
{
145148
[PSCustomObject]@{
@@ -153,7 +156,7 @@
153156
}
154157
}
155158
#endregion Find Keys : $foundKeys
156-
159+
157160
#region Report Findings
158161
$totalResults = foreach ($languageFile in $languageFiles.Keys)
159162
{
@@ -166,7 +169,7 @@
166169
$results[$foundKey.String].Entries += $foundKey
167170
continue
168171
}
169-
172+
170173
$results[$foundKey.String] = [PSCustomObject] @{
171174
PSTypeName = 'PSmoduleDevelopment.String.LanguageFinding'
172175
Language = $languageFile
@@ -180,7 +183,7 @@
180183
}
181184
$results.Values
182185
#endregion Phase 1: Matching parsed strings to language file
183-
186+
184187
#region Phase 2: Finding unneeded strings
185188
foreach ($key in $languageFiles[$languageFile].Keys)
186189
{
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
function Get-PSMDFileCommand
2+
{
3+
<#
4+
.SYNOPSIS
5+
Parses a scriptfile and returns the contained/used commands.
6+
7+
.DESCRIPTION
8+
Parses a scriptfile and returns the contained/used commands.
9+
Use this to determine, what command resources are being used.
10+
11+
.PARAMETER Path
12+
The path to the scriptfile to parse.
13+
14+
.PARAMETER EnableException
15+
Replaces user friendly yellow warnings with bloody red exceptions of doom!
16+
Use this if you want the function to throw terminating errors you want to catch.
17+
18+
.EXAMPLE
19+
PS C:\> Get-PSMDFileCommand -Path './task_usersync.ps1'
20+
21+
Parses the scriptfile task_usersync.ps1 for commands used.
22+
#>
23+
[CmdletBinding()]
24+
param (
25+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
26+
[PsfValidateScript('PSModuleDevelopment.Validate.Path', ErrorString = 'PSModuleDevelopment.Validate.Path')]
27+
[string[]]
28+
$Path,
29+
30+
[switch]
31+
$EnableException
32+
)
33+
34+
process
35+
{
36+
foreach ($pathItem in $Path)
37+
{
38+
# Skip Folders
39+
if (-not (Test-Path -Path $pathItem -PathType Leaf)) { continue }
40+
41+
$parsedCode = Read-PSMDScript -Path $pathItem
42+
if ($parsedCode.Errors)
43+
{
44+
Stop-PSFFunction -String 'Get-PSMDFileCommand.SyntaxError' -StringValues $pathItem -EnableException $EnableException -Continue
45+
}
46+
47+
$results = @{ }
48+
$commands = $parsedCode.Ast.FindAll({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $true)
49+
$internalCommands = $parsedCode.Ast.FindAll({ $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $true).Name
50+
51+
foreach ($command in $commands)
52+
{
53+
if (-not $results[$command.CommandElements[0].Value])
54+
{
55+
$commandInfo = Get-Command $command.CommandElements[0].Value -ErrorAction Ignore
56+
$module = $commandInfo.Module
57+
if (-not $module) { $module = $commandInfo.PSSnapin }
58+
$results[$command.CommandElements[0].Value] = [pscustomobject]@{
59+
PSTypeName = 'PSModuleDevelopment.File.Command'
60+
File = Get-Item $pathItem
61+
Name = $command.CommandElements[0].Value
62+
Parameters = @{ }
63+
Count = 0
64+
AstObjects = @()
65+
CommandInfo = $commandInfo
66+
Module = $module
67+
Internal = $command.CommandElements[0].Value -in $internalCommands
68+
Path = $pathItem
69+
}
70+
}
71+
$object = $results[$command.CommandElements[0].Value]
72+
$object.Count = $object.Count + 1
73+
$object.AstObjects += $command
74+
foreach ($parameter in $command.CommandElements.Where{ $_ -is [System.Management.Automation.Language.CommandParameterAst] })
75+
{
76+
if (-not $object.Parameters[$parameter.ParameterName]) { $object.Parameters[$parameter.ParameterName] = 1 }
77+
else { $object.Parameters[$parameter.ParameterName] = $object.Parameters[$parameter.ParameterName] + 1 }
78+
}
79+
}
80+
81+
$results.Values
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)