-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildModule.ps1
More file actions
155 lines (121 loc) · 4.95 KB
/
Copy pathBuildModule.ps1
File metadata and controls
155 lines (121 loc) · 4.95 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
[CmdletBinding()]
Param (
[Parameter(Mandatory=$False)]
[string]$ReleaseNotes,
[Parameter(Mandatory=$False)]
[switch]$IncrementVersion,
[Parameter(Mandatory=$False)]
[switch]$PublishToPsGallery
)
###############################################################################
# Create Manifest
# PsGallery requires: module name, version, description, and author
$ProjectRoot = Split-Path -parent $MyInvocation.MyCommand.Definition
$ModuleName = Get-Location | Split-Path -Leaf
# Outputs
$OutputDirectory = $ProjectRoot + '/' + $ModuleName
$ManifestFile = $OutputDirectory + '/' + $ModuleName + '.psd1'
$ModuleFile = $OutputDirectory + '/' + $ModuleName + '.psm1'
$ClassDirectory = $OutputDirectory + '/Classes'
###############################################################################
# Run PSSA
$ExcludedRules = @()
$ExcludedRules += 'PSAvoidGlobalVars'
# Load Classes into memory
# PowerShell Core and/or the MacOS File System Drive don't order these in alpha
# order. Loading them first keeps PSSA from throwing dependency errors.
$ClassFiles = Get-ChildItem -Path $ClassDirectory -Recurse -File | Sort-Object
foreach ($class in $ClassFiles) {
. $class.FullName
}
# Run PSSA
Invoke-ScriptAnalyzer -Path $OutputDirectory -Recurse -Settings PSGallery -ExcludeRule $ExcludedRules
$Description = "@
SqlTools provides cmdlets to interact with Sql Databases from Powershell. It allows for Transactions and Sanitizing input with Parameterized queries.
https://github.com/LockstepGroup/SqlTools
@"
if (Test-Path $ManifestFile) {
$UpdateParams = @{}
$UpdateParams.Path = $ManifestFile
$UpdateParams.FunctionsToExport = '*'
if ($ReleaseNotes) {
$UpdateParams.ReleaseNotes = $ReleaseNotes
}
if ($IncrementVersion) {
$CurrentVersion = (Test-ModuleManifest $ManifestFile).Version
$NewVersion = "{0}.{1}.{2}" -f $CurrentVersion.Major, $CurrentVersion.Minor, ($CurrentVersion.Build + 1)
$UpdateParams.ModuleVersion = $NewVersion
}
if ($ReleaseNotes -or $IncrementVersion) {
Update-ModuleManifest @UpdateParams
}
} else {
$ManifestParams = @{ Path = $ManifestFile
ModuleVersion = '1.0.0'
Author = 'Brian Addicks'
RootModule = "$ModuleName`.psm1"
CompanyName = 'Lockstep Technology Group'
Description = $Description
LicenseUri = 'https://raw.githubusercontent.com/LockstepGroup/SqlTools/master/LICENSE'
ProjectUri = 'https://github.com/LockstepGroup/SqlTools'
CmdletsToExport = '*'
FunctionsToExport = '*'
PowerShellVersion = '5.0' }
New-ModuleManifest @ManifestParams
}
# Create Documentation
# Add new docs to mkdocs file, didn't have much luck with any of the powershell yaml modules out there, so here's the cheap way to do it.
$MkdocsTheme = "readthedocs"
$MkdocsSiteName = "$ModuleName Docs"
$Pages = @{}
$Pages.Home = 'index.md'
$Pages.Cmdlets = @{}
# Import Our Module
$Remove = Remove-Module $ModuleName
$Import = Import-Module $ManifestFile
$Cmdlets = Get-Command -Module $ModuleName
foreach ($Cmdlet in $Cmdlets) {
$CmdletName = $Cmdlet.Name
./CreateHelpFile.ps1 -Cmdlet $CmdletName -Destination "./docs/cmdlets/$CmdletName.md"
$Pages.Cmdlets.$CmdletName = "cmdlets/$CmdletName.md"
}
# Output
$MkdocsOutput = @()
$MkdocsOutput += "site_name: " + $MkdocsSiteName
$MkdocsOutput += "theme: " + $MkdocsTheme
$MkdocsOutput += "pages:"
function ConvertHashToYaml ($Value,$Indent = 1) {
[CmdletBinding()]
$ReturnObject = @()
# Get Indententation
$TabSpace = ""
for ($i = 0;$i -lt $Indent;$i++) {
$TabSpace += " "
}
switch ($Value.GetType().Name) {
'hashtable' {
foreach ($entry in $Value.GetEnumerator()) {
$NewLine = $TabSpace + "- " + $entry.Key + ":"
if ($entry.Value.GetType().Name -eq "string") {
Write-Verbose "string"
$ReturnObject += $TabSpace + "- " + $entry.Key + ": " + $entry.Value
} else {
$ReturnObject += $TabSpace + "- " + $entry.Key + ":"
$ReturnObject += ConvertHashToYaml $entry.Value -Indent ($Indent + 1)
}
}
}
'string' {
return $Value
}
}
return $ReturnObject
}
$MkdocsOutput += ConvertHashToYaml $Pages
$MkdocsOutput | Out-File ./mkdocs.yml
##############################################################################
# PublishToPsGallery
#if ($PublishToPsGallery -and ($PSVersionTable.PSEdition -ne "Core")) {
if ($PublishToPsGallery) {
Publish-Module -Path (Resolve-Path "./$ModuleName/") -NuGetApiKey $global:nugetapikey
}