mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-15 02:35:46 +00:00
Add Invoke-PSScriptAnalyzer call to remove whitespace from files
This commit is contained in:
parent
e2a5157790
commit
5d6fb23e91
1 changed files with 35 additions and 20 deletions
39
deploy.ps1
39
deploy.ps1
|
|
@ -52,11 +52,12 @@ param
|
||||||
[switch]$ResetCurrentEnvironment
|
[switch]$ResetCurrentEnvironment
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
Write-Host "Beginning deployment" -ForegroundColor Green
|
Write-Host "Beginning deployment" -ForegroundColor Green
|
||||||
|
|
||||||
Write-Host "Importing required modules" -ForegroundColor Green
|
Write-Host "Importing required modules" -ForegroundColor Green
|
||||||
Import-Module "Microsoft.PowerShell.Utility" -ErrorAction Stop
|
|
||||||
|
Import-Module "PSScriptAnalyzer", "Microsoft.PowerShell.Utility" -ErrorAction Stop
|
||||||
|
|
||||||
|
|
||||||
$ModuleName = 'NetboxPS'
|
$ModuleName = 'NetboxPS'
|
||||||
$ConcatenatedFilePath = "$PSScriptRoot\concatenated.ps1"
|
$ConcatenatedFilePath = "$PSScriptRoot\concatenated.ps1"
|
||||||
$FunctionPath = "$PSScriptRoot\Functions"
|
$FunctionPath = "$PSScriptRoot\Functions"
|
||||||
|
|
@ -64,12 +65,17 @@ $OutputDirectory = "$PSScriptRoot\$ModuleName"
|
||||||
$PSD1OutputPath = "$OutputDirectory\$ModuleName.psd1"
|
$PSD1OutputPath = "$OutputDirectory\$ModuleName.psd1"
|
||||||
$PSM1OutputPath = "$OutputDirectory\$ModuleName.psm1"
|
$PSM1OutputPath = "$OutputDirectory\$ModuleName.psm1"
|
||||||
|
|
||||||
|
|
||||||
|
Write-Host "Removing whitespace from files" -ForegroundColor Green
|
||||||
|
Invoke-ScriptAnalyzer -Path $FunctionPath -IncludeRule 'PSAvoidTrailingWhitespace' -Recurse -Fix
|
||||||
|
|
||||||
|
|
||||||
|
Write-Host "Concatenating [$($PS1FunctionFiles.Count)] PS1 files from $FunctionPath"
|
||||||
$PS1FunctionFiles = Get-ChildItem $FunctionPath -Filter "*.ps1" -Recurse | Sort-Object Name
|
$PS1FunctionFiles = Get-ChildItem $FunctionPath -Filter "*.ps1" -Recurse | Sort-Object Name
|
||||||
|
|
||||||
"" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8
|
"" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8
|
||||||
|
|
||||||
$Counter = 0
|
$Counter = 0
|
||||||
Write-Host "Concatenating [$($PS1FunctionFiles.Count)] PS1 files from $FunctionPath"
|
|
||||||
foreach ($File in $PS1FunctionFiles) {
|
foreach ($File in $PS1FunctionFiles) {
|
||||||
$Counter++
|
$Counter++
|
||||||
|
|
||||||
|
|
@ -89,17 +95,11 @@ foreach ($File in $PS1FunctionFiles) {
|
||||||
|
|
||||||
"" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append
|
"" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append
|
||||||
|
|
||||||
if (-not (Test-Path $OutputDirectory)) {
|
|
||||||
try {
|
|
||||||
Write-Warning "Creating path [$OutputDirectory]"
|
|
||||||
$null = New-Item -Path $OutputDirectory -ItemType Directory -Force
|
|
||||||
} catch {
|
|
||||||
throw "Failed to create output directory [$OutputDirectory]: $($_.Exception.Message)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Write-Host " Adding psm1"
|
Write-Host " Adding psm1"
|
||||||
Get-Content "$PSScriptRoot\$ModuleName.psm1" | Out-File -FilePath $ConcatenatedFilePath -Encoding UTF8 -Append
|
Get-Content "$PSScriptRoot\$ModuleName.psm1" | Out-File -FilePath $ConcatenatedFilePath -Encoding UTF8 -Append
|
||||||
|
|
||||||
|
|
||||||
$PSDManifest = Import-PowerShellDataFile -Path "$PSScriptRoot\$ModuleName.psd1"
|
$PSDManifest = Import-PowerShellDataFile -Path "$PSScriptRoot\$ModuleName.psd1"
|
||||||
# Get the version from the PSD1
|
# Get the version from the PSD1
|
||||||
[version]$CurrentVersion = $PSDManifest.ModuleVersion
|
[version]$CurrentVersion = $PSDManifest.ModuleVersion
|
||||||
|
|
@ -115,6 +115,8 @@ if ($Environment -ilike 'dev*') {
|
||||||
} else {
|
} else {
|
||||||
$UpdateModuleManifestSplat['FunctionsToExport'] = ($PS1FunctionFiles.BaseName | Where-Object { $_ -like '*-*' })
|
$UpdateModuleManifestSplat['FunctionsToExport'] = ($PS1FunctionFiles.BaseName | Where-Object { $_ -like '*-*' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Write-Host "Comparing versions"
|
Write-Host "Comparing versions"
|
||||||
switch ($PSCmdlet.ParameterSetName) {
|
switch ($PSCmdlet.ParameterSetName) {
|
||||||
"SkipVersion" {
|
"SkipVersion" {
|
||||||
|
|
@ -146,15 +148,28 @@ switch ($PSCmdlet.ParameterSetName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Write-Host "Updating Module Manifest"
|
Write-Host "Updating Module Manifest"
|
||||||
Update-ModuleManifest @UpdateModuleManifestSplat
|
Update-ModuleManifest @UpdateModuleManifestSplat
|
||||||
|
|
||||||
|
if (-not (Test-Path $OutputDirectory)) {
|
||||||
|
try {
|
||||||
|
Write-Warning "Creating output directory [$OutputDirectory]"
|
||||||
|
$null = New-Item -Path $OutputDirectory -ItemType Directory -Force
|
||||||
|
} catch {
|
||||||
|
throw "Failed to create output directory [$OutputDirectory]: $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Write-Host " Copying psd1"
|
Write-Host " Copying psd1"
|
||||||
Copy-Item -Path "$PSScriptRoot\$ModuleName.psd1" -Destination $PSD1OutputPath -Force
|
Copy-Item -Path "$PSScriptRoot\$ModuleName.psd1" -Destination $PSD1OutputPath -Force
|
||||||
|
|
||||||
|
|
||||||
Write-Host " Copying psm1"
|
Write-Host " Copying psm1"
|
||||||
Copy-Item -Path $ConcatenatedFilePath -Destination $PSM1OutputPath -Force
|
Copy-Item -Path $ConcatenatedFilePath -Destination $PSM1OutputPath -Force
|
||||||
|
|
||||||
|
|
||||||
Write-Host "Deployment complete" -ForegroundColor Green
|
Write-Host "Deployment complete" -ForegroundColor Green
|
||||||
if ($ResetCurrentEnvironment) {
|
if ($ResetCurrentEnvironment) {
|
||||||
Write-Warning "Running commands to reset current environment"
|
Write-Warning "Running commands to reset current environment"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue