Skip to content

Commit 9987293

Browse files
Merge pull request #124 from PowershellFrameworkCollective/scripting
2.2.8.103
2 parents 2e38b35 + 6b4b194 commit 9987293

File tree

11 files changed

+582
-23
lines changed

11 files changed

+582
-23
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
}
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)