Skip to content

Commit aca15d2

Browse files
Add Install-PSModule function to facilitate module installation
1 parent 31c6a55 commit aca15d2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

scripts/Helpers/Helpers.psm1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,35 @@ function Show-FileContent {
282282
$lineNumber++
283283
}
284284
}
285+
286+
function Install-PSModule {
287+
<#
288+
.SYNOPSIS
289+
Installs a build PS module.
290+
291+
.DESCRIPTION
292+
Installs a build PS module.
293+
294+
.EXAMPLE
295+
Install-PSModule -SourceFolderPath $ModuleFolderPath -ModuleName $moduleName
296+
297+
Installs a module located at $ModuleFolderPath with the name $moduleName.
298+
#>
299+
[CmdletBinding()]
300+
param(
301+
# Path to the folder where the module source code is located.
302+
[Parameter(Mandatory)]
303+
[string] $ModulePath
304+
)
305+
306+
$moduleName = Split-Path -Path $ModulePath -Leaf
307+
$manifestFilePath = Join-Path -Path $ModulePath "$moduleName.psd1"
308+
Write-Verbose " - Manifest file path: [$manifestFilePath]" -Verbose
309+
Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath
310+
$PSModulePath = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Select-Object -First 1
311+
$codePath = New-Item -Path "$PSModulePath/$moduleName/999.0.0" -ItemType Directory -Force | Select-Object -ExpandProperty FullName
312+
Copy-Item -Path "$ModulePath/*" -Destination $codePath -Recurse -Force
313+
LogGroup 'Importing module' {
314+
Import-Module -Name $moduleName -Verbose
315+
}
316+
}

0 commit comments

Comments
 (0)