-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinvoke-modulebuild.ps1
134 lines (99 loc) · 3.91 KB
/
invoke-modulebuild.ps1
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<#PSScriptInfo
.VERSION 1.0.0.0
.GUID 5568f4d3-8d91-4e84-ab28-1c82dc444a61
.AUTHOR JJ Fullmer
.COMPANYNAME Arrowhead Dental Lab
.COPYRIGHT 2024
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
1.0.0.0
Initial version
.PRIVATEDATA
#>
<#
.DESCRIPTION
builds just the module into a single psm1
#>
[CmdletBinding()]
Param()
Import-Module .\BuildHelpers.psm1
$moduleName = 'FogApi'
$modulePath = "$PSScriptRoot\$moduleName";
mkdir $modulePath -EA 0;
# mkdir "$modulePath\tools" -EA 0;
# mkdir "$modulePath\docs" -EA 0;
mkdir "$modulePath\lib" -EA 0;
mkdir "$modulePath\bin" -EA 0;
mkdir "$modulePath\Public" -EA 0;
mkdir "$modulePath\Private" -EA 0;
mkdir "$modulePath\Classes" -EA 0;
$PublicFunctions = Get-ChildItem "$modulePath\Public" -Recurse -Filter '*.ps1' -EA 0;
$Classes = Get-ChildItem "$modulePath\Classes" -Recurse -Filter '*.ps1' -EA 0;
$PrivateFunctions = Get-ChildItem "$modulePath\Private" -Recurse -Filter '*.ps1' -EA 0;
# mkdir "$PSSCriptRoot\ModuleBuild" -EA 0;
$buildPth = ".\_module_build\$moduleName";
$moduleFile = "$buildPth\$moduleName.psm1";
# Create the build output folder
if (Test-Path $buildPth) {
Remove-Item $buildPth -force -recurse;
}
mkdir $buildPth | Out-Null;
New-Item $moduleFile -Force | Out-Null;
Copy-Item "$docsPth\en-us" "$buildPth\en-us" -Recurse -Exclude '*.md';
Add-Content -Path $moduleFile -Value "`$PSModuleRoot = `$PSScriptRoot";
if ((Get-ChildItem "$modulePath\lib").count -gt 0) {
Copy-Item "$modulePath\lib" "$buildPth\lib" -Recurse;
Add-Content -Path $moduleFile -Value "`$script:lib = `"`$PSModuleRoot\lib`"";
}
if ((Get-ChildItem "$modulePath\bin").count -gt 0) {
Copy-Item "$modulePath\bin" "$buildPth\bin" -Recurse;
Add-Content -Path $moduleFile -Value "`$script:bin = `"`$PSModuleRoot\bin`"";
}
# Copy-Item "$modulePath\tools" "$buildPth\tools" -Recurse;
Add-Content -Path $moduleFile -Value "`$script:tools = `"`$PSModuleRoot\tools`"";
#Build the psm1 file
#Add Classes
if ($null -ne $Classes) {
$Classes | ForEach-Object {
Add-Content -Path $moduleFile -Value (Get-Content $_.FullName);
}
}
# Add-PublicFunctions
Add-Content -Path $moduleFile -Value $heading
# $PublicFunctions;
$PublicFunctions | ForEach-Object { # Replace the comment block with external help link
$rawContent = (Get-Content $_.FullName -Raw);
$commentStartIdx = $rawContent.indexOf('<#');
if ($commentStartIdx -ge 0) {
$commentEndIdx = $rawContent.IndexOf('#>');
$commentLength = $commentEndIdx - ($commentStartIdx-2); #-2 to adjust for the # in front of > and the index starting at 0
$comment = $rawContent.Substring($commentStartIdx,$commentLength);
$newComment = "# .ExternalHelp $moduleName-help.xml"
$Function = $rawContent.Replace($comment,$newComment);
} else {
$Function = $rawContent;
}
Add-Content -Path $moduleFile -Value $Function
}
#Add Private Functions
if ($null -ne $PrivateFunctions) {
$PrivateFunctions | ForEach-Object {
Add-Content -Path $moduleFile -Value (Get-Content $_.FullName);
}
}
$manifest = "$PSScriptRoot\$moduleName\$moduleName.psd1"
Copy-Item $manifest "$buildPth\$moduleName.psd1";
if (Get-Command Update-PSModuleManifest) {
Update-PSModuleManifest -Path "$buildPth\$moduleName.psd1" -RootModule "$moduleName.psm1" -FunctionsToExport $PublicFunctions.BaseName
} else {
"PSResourceGet version of update manifest not found, reverting to psget version, may cause issues with choco nuspec" | out-host;
Update-ModuleManifest -Path "$buildPth\$moduleName.psd1" -RootModule "$moduleName.psm1" -FunctionsToExport $PublicFunctions.BaseName
}
Set-EmptyExportArray -psd1Path "$buildPth\$moduleName.psd1" -ExportType Cmdlets;
Set-EmptyExportArray -psd1Path "$buildPth\$moduleName.psd1" -ExportType Variables;