Skip to content

Commit 5a2b55b

Browse files
author
FriedrichWeinmann
committed
generic updates
1 parent 985bc61 commit 5a2b55b

5 files changed

Lines changed: 112 additions & 15 deletions

File tree

‎PSModuleDevelopment/PSModuleDevelopment.psd1‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
Description = 'A module designed to speed up the development of PowerShell modules'
2323

2424
# Minimum version of the Windows PowerShell engine required by this module
25-
PowerShellVersion = '2.0'
25+
PowerShellVersion = '3.0'
2626

2727
# Name of the Windows PowerShell host required by this module
2828
PowerShellHostName = ''
@@ -41,7 +41,7 @@
4141

4242
# Modules that must be imported into the global environment prior to importing
4343
# this module
44-
RequiredModules = @()
44+
RequiredModules = @("PSFramework")
4545

4646
# Assemblies that must be loaded prior to importing this module
4747
RequiredAssemblies = @()
Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,48 @@
1-
# Perform Actions before loading the rest of the content
2-
. "$PSScriptRoot\scripts\preload.ps1"
1+
$script:PSModuleDevelopmentModuleRoot = $PSScriptRoot
32

4-
#region Load module content
3+
$script:doDotSource = $false
4+
if (Get-PSFConfigValue -Name PSModuleDevelopment.Import.DoDotSource) { $script:doDotSource = $true }
55

6-
. "$PSScriptRoot\functions\Get-HelpEx.ps1"
7-
. "$PSScriptRoot\functions\Get-ModuleDebug.ps1"
8-
. "$PSScriptRoot\functions\Import-ModuleDebug.ps1"
9-
. "$PSScriptRoot\functions\Measure-CommandEx.ps1"
10-
. "$PSScriptRoot\functions\New-PssModuleProject.ps1"
11-
. "$PSScriptRoot\functions\Remove-ModuleDebug.ps1"
12-
. "$PSScriptRoot\functions\Restart-Shell.ps1"
13-
. "$PSScriptRoot\functions\Set-ModuleDebug.ps1"
6+
#region Helper function
7+
function Import-PSMDFile
8+
{
9+
<#
10+
.SYNOPSIS
11+
Loads files into the module on module import.
12+
13+
.DESCRIPTION
14+
This helper function is used during module initialization.
15+
It should always be dotsourced itself, in order to proper function.
16+
17+
.PARAMETER Path
18+
The path to the file to load
19+
20+
.EXAMPLE
21+
PS C:\> . Import-PSMDFile -File $function.FullName
22+
23+
Imports the file stored in $function according to import policy
24+
#>
25+
[CmdletBinding()]
26+
Param (
27+
[string]
28+
$Path
29+
)
30+
31+
if ($script:doDotSource) { . $Path }
32+
else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($Path))), $null, $null) }
33+
}
34+
#endregion Helper function
1435

15-
#endregion Load module content
36+
37+
# Perform Actions before loading the rest of the content
38+
. Import-PSMDFile -Path "$PSModuleDevelopmentModuleRoot\scripts\preload.ps1"
39+
40+
#region Load functions
41+
foreach ($function in (Get-ChildItem "$PSModuleDevelopmentModuleRoot\functions" -Recurse -File -Filter "*.ps1"))
42+
{
43+
. Import-PSMDFile -Path $function.FullName
44+
}
45+
#endregion Load functions
1646

1747
# Perform Actions after loading the module contents
18-
. "$PSScriptRoot\scripts\postload.ps1"
48+
. Import-PSMDFile -Path "$PSModuleDevelopmentModuleRoot\scripts\postload.ps1"

‎PSModuleDevelopment/PSModuleDevelopment.psproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<File Build="2" Shared="True" ReferenceFunction="Invoke-Measure-CommandEx_ps1">functions\performance\Measure-CommandEx.ps1</File>
2727
<File Build="2" Shared="False" ReferenceFunction="Invoke-New-PssModuleProject_ps1">functions\utility\New-PssModuleProject.ps1</File>
2828
<File Build="2">en-us\about_psmoduledevelopment.help.txt</File>
29+
<File Build="2" Shared="False" ReferenceFunction="Invoke-Set-PSMDModulePath_ps1">functions\utility\Set-PSMDModulePath.ps1</File>
2930
</Files>
3031
<StartupScript>F:\Synchronized Data\Scripte\Powershell Studio\Projects\PSModuleDevelopment\Test-Module.ps1</StartupScript>
3132
</Project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function Set-PSMDModulePath
2+
{
3+
<#
4+
.SYNOPSIS
5+
Sets the path of the module currently being developed.
6+
7+
.DESCRIPTION
8+
Sets the path of the module currently being developed.
9+
This is used by several utility commands in order to not require any path input.
10+
11+
This is a wrapper around the psframework configuration system, the same action can be taken by running this command:
12+
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $Path
13+
14+
.PARAMETER Path
15+
The path to set as currently developed module.
16+
17+
.PARAMETER EnableException
18+
Replaces user friendly yellow warnings with bloody red exceptions of doom!
19+
Use this if you want the function to throw terminating errors you want to catch.
20+
21+
.EXAMPLE
22+
PS C:\> Set-PSMDModulePath -Path
23+
#>
24+
[CmdletBinding()]
25+
Param (
26+
[Parameter(Mandatory = $true)]
27+
[string]
28+
$Path,
29+
30+
[switch]
31+
$EnableException
32+
)
33+
34+
$resolvedPath = Resolve-Path -Path $Path
35+
if (Test-Path -Path $resolvedPath)
36+
{
37+
if ((Get-Item $resolvedPath).PSIsContainer)
38+
{
39+
Set-PSFConfig -Module PSModuleDevelopment -Name "Module.Path" -Value $resolvedPath
40+
return
41+
}
42+
}
43+
44+
Stop-PSFFunction -Target $Path -Message "Could not validate/resolve path: $Path" -EnableException $EnableException -Category InvalidArgument
45+
return
46+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
2+
<CodeSnippet Format="1.0.0">
3+
<Header>
4+
<Title>_help_EnableException</Title>
5+
<Shortcut></Shortcut>
6+
<Description>Default documentation on Enable Exception parameter</Description>
7+
<Author>Infernal Associates ltd.</Author>
8+
<SnippetTypes>
9+
<SnippetType>Expansion</SnippetType>
10+
</SnippetTypes>
11+
</Header>
12+
<Snippet>
13+
<Code Language="PowerShell">
14+
<![CDATA[.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+
</Code>
18+
</Snippet>
19+
</CodeSnippet>
20+
</CodeSnippets>

0 commit comments

Comments
 (0)