-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUCBuildModule.ps1
More file actions
55 lines (41 loc) · 2.35 KB
/
UCBuildModule.ps1
File metadata and controls
55 lines (41 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
param(
[version]$Version = "1.0.0"
)
#Getting module name from the current script path
$ModuleName = Split-Path $PSScriptRoot -Leaf
#Check if Output path exists, if so deletes previous files.
if (!(Test-Path -Path "$PSScriptRoot\Output\$ModuleName")) {
New-Item -Path "$PSScriptRoot\Output\$ModuleName" -ItemType Directory | Out-Null
}
else {
Remove-Item "$PSScriptRoot\Output\$ModuleName\*.*" -Recurse -Force
}
#Region Copy Readme and Format file if exists.
if (Test-Path -Path "$PSScriptRoot\README.md"){
Copy-Item -Path "$PSScriptRoot\README.md" -Destination "$PSScriptRoot\Output\$ModuleName\README.md"
}
if (Test-Path -Path "$PSScriptRoot\Source\$ModuleName.format.ps1xml"){
Copy-Item -Path "$PSScriptRoot\Source\$ModuleName.format.ps1xml" -Destination "$PSScriptRoot\Output\$ModuleName\$ModuleName.format.ps1xml"
}
#endregion
#Region Create Module
$outModuleContent = ""
$FunctionsToExport = "@("
Get-ChildItem -Path ("$PSScriptRoot\Source\Private") -Filter *.ps1 | ForEach-Object { $outModuleContent += [System.IO.File]::ReadAllText($_.FullName)+[Environment]::NewLine+[Environment]::NewLine}
Get-ChildItem -Path ("$PSScriptRoot\Source\Public") -Filter *.ps1 | ForEach-Object { $outModuleContent += [System.IO.File]::ReadAllText($_.FullName)+[Environment]::NewLine+[Environment]::NewLine; $FunctionsToExport+= "'" + $_.BaseName + "',"}
[System.IO.File]::WriteAllText("$PSScriptRoot\Output\$ModuleName\$ModuleName.psm1", $outModuleContent, [System.Text.Encoding]::UTF8)
$FunctionsToExport = $FunctionsToExport.Substring(0,$FunctionsToExport.Length-1) + ")"
#endregion
#Region Update and copy Module Manifest
if (Test-Path -Path "$PSScriptRoot\Source\$ModuleName.psd1"){
#Copy-Item -Path "$PSScriptRoot\Source\$ModuleName.psd1" -Destination "$PSScriptRoot\Output\$ModuleName\$ModuleName.psd1"
$ModuleManifest = [System.IO.File]::ReadAllText("$PSScriptRoot\Source\$ModuleName.psd1")
$ModuleManifest = $ModuleManifest -replace '#%ModuleVersion%', ("""$Version""")
$ModuleManifest = $ModuleManifest -replace '#%FunctionsToExport%', $FunctionsToExport
[System.IO.File]::WriteAllText("$PSScriptRoot\Output\$ModuleName\$ModuleName.psd1", $ModuleManifest, [System.Text.Encoding]::UTF8)
} else {
Write-Warning "Missing Manifest file: $ModuleName.psd1"
}
#endregion
"$PSScriptRoot\Output\$ModuleName"
Import-Module -Name ("$PSScriptRoot\Output\$ModuleName") -Force