From d0090e9cedd4ae892e9762f3a3a7279d10061dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 22 Jan 2026 14:36:26 +0100 Subject: [PATCH 1/7] refactor(module): recurse sync --- .gitignore | 2 - .vscode/settings.json | 9 ++ Test/helper/module.helper.ps1 | 119 ++++++++++++--------- Test/public/addIncludeToWorkspace.test.ps1 | 2 +- Test/public/listIncludes.test.ps1 | 59 +++++++--- Test/public/module.helper.test.ps1 | 16 +-- helper/module.helper.ps1 | 119 ++++++++++++--------- public/addIncludeToWorkspace.ps1 | 70 +++++++++--- public/listIncludes.ps1 | 52 ++++----- public/listSystemFiles.ps1 | 108 +++++++++++++++---- public/syncIncludeWithModule.ps1 | 10 +- 11 files changed, 371 insertions(+), 195 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 26da4ac..acc8348 100755 --- a/.gitignore +++ b/.gitignore @@ -322,5 +322,3 @@ ASALocalRun/ # MSBuild Binary and Structured Log *.binlog -# exclude vscode settings folder -.vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1d9904e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "terminal.integrated.profiles.osx": { + "pwsh": { + "path": "pwsh", + "icon": "terminal-powershell", + "args": ["-NoExit", "-Command", "if (Test-Path './tools/Test_Helper') { Import-Module './tools/Test_Helper' -Force }"] + } + } +} diff --git a/Test/helper/module.helper.ps1 b/Test/helper/module.helper.ps1 index f9c68cd..7ac11cd 100644 --- a/Test/helper/module.helper.ps1 +++ b/Test/helper/module.helper.ps1 @@ -36,8 +36,45 @@ $MODULE_NAME = (Get-ChildItem -Path $MODULE_ROOT_PATH -Filter *.psd1 | Select-Ob # Helper for module variables - -$VALID_FOLDER_NAMES = @('Include', 'Private', 'Public', 'Root', 'TestInclude', 'TestPrivate', 'TestPublic', 'TestRoot', 'Tools', 'DevContainer', 'WorkFlows', 'GitHub', 'Helper', 'Config', 'TestHelper', 'TestConfig') +# Folders names that IncludeHelper may add content to +$VALID_INCLUDE_FOLDER_NAMES = @( + 'Root', + 'Include', + 'DevContainer', + 'WorkFlows', + 'GitHub', + # 'Config', + 'Helper', + # 'Private', + # 'Public', + 'Tools', + + 'TestRoot', + # 'TestConfig' + 'TestInclude', + 'TestHelper', + # 'TestPrivate', + # 'TestPublic', + + "TestHelperRoot", + "TestHelperPrivate", + "TestHelperPublic" + + "VsCode" +) + +# Folders names that IncludeHelper should not add content to. +# In this folders is the module code itself +$VALID_MODULE_FOLDER_NAMES = @( + 'Config', + 'Private', + 'Public', + 'TestConfig' + 'TestPrivate', + 'TestPublic' +) + +$VALID_FOLDER_NAMES = $VALID_INCLUDE_FOLDER_NAMES + $VALID_MODULE_FOLDER_NAMES class ValidFolderNames : System.Management.Automation.IValidateSetValuesGenerator { [String[]] GetValidValues() { @@ -113,56 +150,38 @@ function Get-ModuleFolder{ # TestRootPath $testRootPath = $ModuleRootPath | Join-Path -ChildPath "Test" + $testHelperRootPath = $ModuleRootPath | Join-Path -ChildPath "tools/Test_Helper" switch ($FolderName){ - 'Public'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "public" - } - 'Private'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "private" - } - 'Include'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "include" - } - 'TestInclude'{ - $moduleFolder = $testRootPath | Join-Path -ChildPath "include" - } - 'TestPrivate'{ - $moduleFolder = $testRootPath | Join-Path -ChildPath "private" - } - 'TestPublic'{ - $moduleFolder = $testRootPath | Join-Path -ChildPath "public" - } - 'Root'{ - $moduleFolder = $ModuleRootPath - } - 'TestRoot'{ - $moduleFolder = $testRootPath - } - 'Tools'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "tools" - } - 'DevContainer'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".devcontainer" - } - 'WorkFlows'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github/workflows" - } - 'GitHub'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github" - } - 'Helper'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "helper" - } - 'Config'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "config" - } - 'TestHelper'{ - $moduleFolder = $testRootPath | Join-Path -ChildPath "helper" - } - 'TestConfig'{ - $moduleFolder = $testRootPath | Join-Path -ChildPath "config" - } + + # VALID_INCLUDE_FOLDER_NAMES + 'Root' { $moduleFolder = $ModuleRootPath } + 'Include' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "include" } + 'DevContainer'{ $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".devcontainer" } + 'WorkFlows' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github/workflows" } + 'GitHub' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github" } + 'Helper' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "helper" } + 'Tools' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "tools" } + + 'TestRoot' { $moduleFolder = $testRootPath } + 'TestInclude' { $moduleFolder = $testRootPath | Join-Path -ChildPath "include" } + 'TestHelper' { $moduleFolder = $testRootPath | Join-Path -ChildPath "helper" } + + 'TestHelperRoot' { $moduleFolder = $testHelperRootPath } + 'TestHelperPrivate' { $moduleFolder = $testHelperRootPath | Join-Path -ChildPath "private" } + 'TestHelperPublic' { $moduleFolder = $testHelperRootPath | Join-Path -ChildPath "public" } + + "VsCode" { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".vscode" } + + # VALID_MODULE_FOLDER_NAMES + 'Config' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "config" } + 'Private' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "private" } + 'Public' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "public" } + 'TestConfig' { $moduleFolder = $testRootPath | Join-Path -ChildPath "config" } + 'TestPrivate' { $moduleFolder = $testRootPath | Join-Path -ChildPath "private" } + 'TestPublic' { $moduleFolder = $testRootPath | Join-Path -ChildPath "public" } + + default{ throw "Folder [$FolderName] is unknown" } diff --git a/Test/public/addIncludeToWorkspace.test.ps1 b/Test/public/addIncludeToWorkspace.test.ps1 index f9b226e..5810813 100644 --- a/Test/public/addIncludeToWorkspace.test.ps1 +++ b/Test/public/addIncludeToWorkspace.test.ps1 @@ -84,7 +84,7 @@ function Test_AddIncludeToWorkspace_IfExists{ # Test for Include $includefiles = Get-IncludeFile - $include1 = $includefiles | Where-Object { $_.FolderName -eq "github" } | Select-Object -First 1 + $include1 = $includefiles | Where-Object { $_.FolderName -eq "Helper" } | Select-Object -First 1 $include2 = $includefiles | Where-Object { $_.FolderName -eq "Include" } | Select-Object -First 1 New-ModuleV3 -Name $moduleName diff --git a/Test/public/listIncludes.test.ps1 b/Test/public/listIncludes.test.ps1 index eeeea4d..87dc16c 100644 --- a/Test/public/listIncludes.test.ps1 +++ b/Test/public/listIncludes.test.ps1 @@ -5,7 +5,7 @@ function Test_GetIncludeFile{ $includelist =@() - @("github","Include","TestInclude","Helper","TestHelper") | ForEach-Object{ + @("Include","TestInclude","Helper","TestHelper") | ForEach-Object{ $includelist += Get-ModuleFolder -FolderName $_ | Get-ChildItem -File } @@ -32,23 +32,56 @@ function Test_GetIncludeFile{ function Test_GetIncludeSystemFiles { # Test for IncludeSystemFiles - $name = "deploy.ps1" - $folderName = "Root" + + $expectedList = @( + @{ FolderName = "Root" ; Name = "{modulename}.psm1" } + @{ FolderName = "Root" ; Name = "deploy.ps1" } + @{ FolderName = "Root" ; Name = "LICENSE" } + @{ FolderName = "Root" ; Name = "release.ps1" } + @{ FolderName = "Root" ; Name = "sync.ps1" } + @{ FolderName = "Root" ; Name = "test.ps1" } + @{ FolderName = "DevContainer" ; Name = "devcontainer.json" } + @{ FolderName = "GitHub" ; Name = "copilot-commit-message-instructions.md" } + @{ FolderName = "GitHub" ; Name = "copilot-instructions.md" } + @{ FolderName = "GitHub" ; Name = "copilot-pull-request-description-instructions.md" } + @{ FolderName = "TestHelperRoot" ; Name = "Test_Helper.psd1" } + @{ FolderName = "TestHelperRoot" ; Name = "Test_Helper.psm1" } + @{ FolderName = "TestHelperPublic" ; Name = "Get-RequiredModule.ps1" } + @{ FolderName = "TestHelperPublic" ; Name = "Import-RequiredModule.ps1" } + @{ FolderName = "TestHelperPublic" ; Name = "testname.ps1" } + @{ FolderName = "TestHelperPublic" ; Name = "testResults.ps1" } + @{ FolderName = "Tools" ; Name = "deploy.Helper.ps1" } + @{ FolderName = "Tools" ; Name = "sync.Helper.ps1" } + @{ FolderName = "TestRoot" ; Name = "Test.psm1" } + @{ FolderName = "WorkFlows" ; Name = "deploy_module_on_release.yml" } + @{ FolderName = "WorkFlows" ; Name = "powershell.yml" } + @{ FolderName = "WorkFlows" ; Name = "test_with_TestingHelper.yml" } + @{ FolderName = "VsCode" ; Name = "settings.json" } + @{ FolderName = "VsCode" ; Name = "launch.json" } + + ) # Act $result = Get-IncludeSystemFiles + + # Assert + Assert-Count -Expected $expectedList.Count -Presented $result - Assert-Count -Expected 15 -Presented $result + foreach($Item in $expectedList){ + Assert-IncludeFile -Name $Item.Name -FolderName $Item.FolderName -IncludesList $result + } - # Assert - $item = $result | Where-Object {$_.Name -eq $name} - Assert-Count -Expected 1 -Presented $Item - Assert-AreEqual -Expected $folderName -Presented $item.FolderName +} - # Filtered - $result = Get-IncludeSystemFiles -Filter "testing" - Assert-Count -Expected 1 -Presented $result - $item = $result | Where-Object {$_.Name -eq "test_with_TestingHelper.yml"} - Assert-AreEqual -Expected "WorkFlows" -Presented $item.FolderName +function Assert-IncludeFile{ + param( + [Parameter(Mandatory)][string]$Name, + [Parameter(Mandatory)][string]$FolderName, + [Parameter(Mandatory)][array]$IncludesList + ) + + $item = $IncludesList | Where-Object {$_.Name -eq $Name} + Assert-Count -Expected 1 -Presented $item + Assert-AreEqual -Expected $FolderName -Presented $item.FolderName -Comment "Include File $Name should be in folder $FolderName" } diff --git a/Test/public/module.helper.test.ps1 b/Test/public/module.helper.test.ps1 index 20c97be..24fd690 100644 --- a/Test/public/module.helper.test.ps1 +++ b/Test/public/module.helper.test.ps1 @@ -27,13 +27,13 @@ function Test_GetModuleFolder{ # Load include file to test . $(Get-Ps1FullPath -Name "module.helper.ps1" -FolderName "Helper" -ModuleRootPath $MODULE_ROOT_PATH) - $result = Get-ModuleFolder -FolderName "Public" + # $result = Get-ModuleFolder -FolderName "Public" - Assert-AreEqual -Expected ($moduleRootPath | Join-Path -ChildPath "public") -Presented $result + # Assert-AreEqual -Expected ($moduleRootPath | Join-Path -ChildPath "public") -Presented $result - $result = Get-ModuleFolder -FolderName "Private" + # $result = Get-ModuleFolder -FolderName "Private" - Assert-AreEqual -Expected ($moduleRootPath | Join-Path -ChildPath "private") -Presented $result + # Assert-AreEqual -Expected ($moduleRootPath | Join-Path -ChildPath "private") -Presented $result $result = Get-ModuleFolder -FolderName "Include" @@ -43,13 +43,13 @@ function Test_GetModuleFolder{ Assert-AreEqual -Expected ($moduleRootPath | Join-Path -ChildPath "Test\include") -Presented $result - $result = Get-ModuleFolder -FolderName "TestPrivate" + # $result = Get-ModuleFolder -FolderName "TestPrivate" - Assert-AreEqual -Expected ($moduleRootPath | Join-Path -ChildPath "Test\private") -Presented $result + # Assert-AreEqual -Expected ($moduleRootPath | Join-Path -ChildPath "Test\private") -Presented $result - $result = Get-ModuleFolder -FolderName "TestPublic" + # $result = Get-ModuleFolder -FolderName "TestPublic" - Assert-AreEqual -Expected ($moduleRootPath | Join-Path -ChildPath "Test\public") -Presented $result + # Assert-AreEqual -Expected ($moduleRootPath | Join-Path -ChildPath "Test\public") -Presented $result $result = Get-ModuleFolder -FolderName "Root" diff --git a/helper/module.helper.ps1 b/helper/module.helper.ps1 index f9c68cd..7ac11cd 100644 --- a/helper/module.helper.ps1 +++ b/helper/module.helper.ps1 @@ -36,8 +36,45 @@ $MODULE_NAME = (Get-ChildItem -Path $MODULE_ROOT_PATH -Filter *.psd1 | Select-Ob # Helper for module variables - -$VALID_FOLDER_NAMES = @('Include', 'Private', 'Public', 'Root', 'TestInclude', 'TestPrivate', 'TestPublic', 'TestRoot', 'Tools', 'DevContainer', 'WorkFlows', 'GitHub', 'Helper', 'Config', 'TestHelper', 'TestConfig') +# Folders names that IncludeHelper may add content to +$VALID_INCLUDE_FOLDER_NAMES = @( + 'Root', + 'Include', + 'DevContainer', + 'WorkFlows', + 'GitHub', + # 'Config', + 'Helper', + # 'Private', + # 'Public', + 'Tools', + + 'TestRoot', + # 'TestConfig' + 'TestInclude', + 'TestHelper', + # 'TestPrivate', + # 'TestPublic', + + "TestHelperRoot", + "TestHelperPrivate", + "TestHelperPublic" + + "VsCode" +) + +# Folders names that IncludeHelper should not add content to. +# In this folders is the module code itself +$VALID_MODULE_FOLDER_NAMES = @( + 'Config', + 'Private', + 'Public', + 'TestConfig' + 'TestPrivate', + 'TestPublic' +) + +$VALID_FOLDER_NAMES = $VALID_INCLUDE_FOLDER_NAMES + $VALID_MODULE_FOLDER_NAMES class ValidFolderNames : System.Management.Automation.IValidateSetValuesGenerator { [String[]] GetValidValues() { @@ -113,56 +150,38 @@ function Get-ModuleFolder{ # TestRootPath $testRootPath = $ModuleRootPath | Join-Path -ChildPath "Test" + $testHelperRootPath = $ModuleRootPath | Join-Path -ChildPath "tools/Test_Helper" switch ($FolderName){ - 'Public'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "public" - } - 'Private'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "private" - } - 'Include'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "include" - } - 'TestInclude'{ - $moduleFolder = $testRootPath | Join-Path -ChildPath "include" - } - 'TestPrivate'{ - $moduleFolder = $testRootPath | Join-Path -ChildPath "private" - } - 'TestPublic'{ - $moduleFolder = $testRootPath | Join-Path -ChildPath "public" - } - 'Root'{ - $moduleFolder = $ModuleRootPath - } - 'TestRoot'{ - $moduleFolder = $testRootPath - } - 'Tools'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "tools" - } - 'DevContainer'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".devcontainer" - } - 'WorkFlows'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github/workflows" - } - 'GitHub'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github" - } - 'Helper'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "helper" - } - 'Config'{ - $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "config" - } - 'TestHelper'{ - $moduleFolder = $testRootPath | Join-Path -ChildPath "helper" - } - 'TestConfig'{ - $moduleFolder = $testRootPath | Join-Path -ChildPath "config" - } + + # VALID_INCLUDE_FOLDER_NAMES + 'Root' { $moduleFolder = $ModuleRootPath } + 'Include' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "include" } + 'DevContainer'{ $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".devcontainer" } + 'WorkFlows' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github/workflows" } + 'GitHub' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github" } + 'Helper' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "helper" } + 'Tools' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "tools" } + + 'TestRoot' { $moduleFolder = $testRootPath } + 'TestInclude' { $moduleFolder = $testRootPath | Join-Path -ChildPath "include" } + 'TestHelper' { $moduleFolder = $testRootPath | Join-Path -ChildPath "helper" } + + 'TestHelperRoot' { $moduleFolder = $testHelperRootPath } + 'TestHelperPrivate' { $moduleFolder = $testHelperRootPath | Join-Path -ChildPath "private" } + 'TestHelperPublic' { $moduleFolder = $testHelperRootPath | Join-Path -ChildPath "public" } + + "VsCode" { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".vscode" } + + # VALID_MODULE_FOLDER_NAMES + 'Config' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "config" } + 'Private' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "private" } + 'Public' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "public" } + 'TestConfig' { $moduleFolder = $testRootPath | Join-Path -ChildPath "config" } + 'TestPrivate' { $moduleFolder = $testRootPath | Join-Path -ChildPath "private" } + 'TestPublic' { $moduleFolder = $testRootPath | Join-Path -ChildPath "public" } + + default{ throw "Folder [$FolderName] is unknown" } diff --git a/public/addIncludeToWorkspace.ps1 b/public/addIncludeToWorkspace.ps1 index 953c4d3..2f53782 100644 --- a/public/addIncludeToWorkspace.ps1 +++ b/public/addIncludeToWorkspace.ps1 @@ -40,20 +40,27 @@ function Add-IncludeToWorkspace { [Parameter()][switch]$Force ) - process{ + begin{ + + #">> Add-IncludeToWorkspace" | Write-MyDebug $SourceModulePath = $SourceLocal ? "." : $SourceModulePath $DestinationModulePath = $DestinationIncludeHelper ? (Get-ModuleFolder -FolderName 'Root') : $DestinationModulePath - # Resolve source and destination module paths $SourceModulePath, $DestinationModulePath = Resolve-SourceDestinationPath -SourceModulePath $SourceModulePath -DestinationModulePath $DestinationModulePath + #"SourceModulePath : $SourceModulePath" | Write-MyDebug + #"DestinationModulePath: $DestinationModulePath" | Write-MyDebug + } + + process{ + # File paths # If source empty defaults to IncludeHelper $sourcePath = Get-ModuleFolder -FolderName $FolderName -ModuleRootPath $sourceModulePath - "Source folder is $sourcePath" | Write-Verbose + ## "Source folder is $sourcePath" | Write-MyDebug $destinationpath = Get-ModuleFolder -FolderName $FolderName -ModuleRootPath $DestinationModulePath - "Destination folder is $destinationpath" | Write-Verbose + ## "Destination folder is $destinationpath" | Write-MyDebug # Expand file name trasnformation # Replace name {variables} with their value based on destination module @@ -62,22 +69,22 @@ function Add-IncludeToWorkspace { # File Full paths $sourceFile = $sourcePath | Join-Path -ChildPath $souceName - "Source file is $sourceFile" | Write-Verbose + ## "Source file is $sourceFile" | Write-MyDebug $destinationFile = $destinationpath | Join-Path -ChildPath $destinationName - "Destination file is $destinationFile" | Write-Verbose + ## "Destination file is $destinationFile" | Write-MyDebug # Check for $IfExist switch if ($IfExists) { # Only copy if destination file exists # This is an upgrade functionality if (-Not (Test-Path $destinationFile)) { - Write-Verbose "File $destinationFile does not exist and -IfExists was specified. Skipping." + #Write-MyDebug "SKIP : File does not exist and -IfExists was specified. Skipping $destinationFile" return - } else { - Write-Verbose "File $destinationFile exists and -IfExists was specified. Proceeding with copy." } } + #Write-MyDebug "COPY : $destinationFile" + # Expand filecontent Transformations $content = Expand-FileContentTransformation -SourceFileName $sourceFile -SourceModulePath $SourceModulePath -DestinationModulePath $DestinationModulePath @@ -92,6 +99,7 @@ function Add-IncludeToWorkspace { # create destination folder if it does not exist if(-Not (Test-Path $destinationpath)){ + #"Create folder $destinationpath" | Write-MyDebug $null = New-Item -Path $destinationpath -ItemType Directory -Force } @@ -102,11 +110,15 @@ function Add-IncludeToWorkspace { if ($PSCmdlet.ShouldProcess("$sourceFile", "copy to $destinationFile")) { # Copy-Item -Path $sourceFile -Destination $destinationFile -Force - Write-Output $destinationFile Set-Content -Path $destinationFile -Value $content -Force + Write-Output $destinationFile } } + end{ + #"<< Add-IncludeToWorkspace" | Write-MyDebug + } + } Export-ModuleMember -Function Add-IncludeToWorkspace function Resolve-SourceDestinationPath{ @@ -160,6 +172,24 @@ function Expand-FileNameTransformation{ } } +function Compress-FileNameTransformation{ + [CmdletBinding()] + param( + [Parameter(Mandatory,ValueFromPipeline,Position=0)][string]$FileName, + [Parameter(Mandatory,ValueFromPipeline,Position=1)][string]$SourceModulePath + ) + + begin{ + $moduleName = Get-ModuleNameFromPath -Path $SourceModulePath + } + process{ + #ModuleName transformation + $ret = $FileName -replace $moduleName, '{modulename}' + + return $ret + } +} + function Expand-FileContentTransformation{ [CmdletBinding()] param( @@ -170,8 +200,6 @@ function Expand-FileContentTransformation{ begin{ $moduleName = Get-ModuleNameFromPath -Path $DestinationModulePath - $sourceGuid = Get-ModuleGuidFromPath -Path $SourceModulePath - $destinationGuid = Get-ModuleGuidFromPath -Path $DestinationModulePath } process{ $content = Get-Content -Path $SourceFileName -Raw @@ -183,6 +211,24 @@ function Expand-FileContentTransformation{ } } +function Compress-FileNameTransformation{ + [CmdletBinding()] + param( + [Parameter(Mandatory,ValueFromPipeline,Position=0)][string]$FileName, + [Parameter(Mandatory,ValueFromPipeline,Position=1)][string]$SourceModulePath + ) + + begin{ + $moduleName = Get-ModuleNameFromPath -Path $SourceModulePath + } + process{ + #ModuleName transformation + $ret = $FileName -replace $moduleName, '{modulename}' + + return $ret + } +} + function Update-IncludeFileToIncludeHelper{ [CmdletBinding(SupportsShouldProcess)] param ( diff --git a/public/listIncludes.ps1 b/public/listIncludes.ps1 index fee9110..69d04bc 100644 --- a/public/listIncludes.ps1 +++ b/public/listIncludes.ps1 @@ -35,6 +35,7 @@ function Get-IncludeFile{ param( #add filter pattern [Parameter( Position = 0 )] [string]$Filter = '*', + [Parameter()][string[]]$Folders, [Parameter()][switch]$Local, [Parameter()][string]$ModuleRootPath ) @@ -44,22 +45,33 @@ function Get-IncludeFile{ # If Local use '.' # If not Localuse includeHelper module if([string]::IsNullOrWhiteSpace($ModuleRootPath)){ - $moduleRootPath = $Local ? "." : " " + $moduleRootPath = $Local ? "." : $(Get-ModuleRootPath) } + $moduleName = Get-ModuleNameFromPath -Path $ModuleRootPath + $ret =@() - @("github","Include","TestInclude","Helper","TestHelper") | ForEach-Object { + # If folder not specified search on default include folders + $fileFolders = $Folders ?? @("Include","Helper","TestInclude","TestHelper") + + # Validate that all folder names are valid + $invalidFolders = $folders | Where-Object { $_ -notin $VALID_FOLDER_NAMES } + if ($invalidFolders.Count -gt 0) { + Write-MyError "Invalid folder names: $($invalidFolders -join ', '). Valid names are: $($VALID_FOLDER_NAMES -join ', ')" + return + } + + $fileFolders| ForEach-Object { $FolderName = $_ $path = Get-ModuleFolder -FolderName $FolderName -ModuleRootPath $ModuleRootPath - $moduleName = $ModuleRootPath | Split-Path -Leaf - $items = Get-ChildItem -Path $path -Filter "*$Filter*" -File -ErrorAction SilentlyContinue | ForEach-Object { + [PSCustomObject]@{ - Name = $_.Name + Name = Compress-FileNameTransformation -FileName $_.Name -SourceModulePath $ModuleRootPath FolderName = $FolderName ModuleName = $moduleName Path = $_.FullName @@ -72,32 +84,6 @@ function Get-IncludeFile{ return $ret - # $include = Get-ModuleFolder -FolderName 'Include' -ModuleRootPath $ModuleRootPath - # $includeTest = Get-ModuleFolder -FolderName 'TestInclude' -ModuleRootPath $ModuleRootPath - - # $includeItems = Get-ChildItem -Path $include -Filter "*$Filter*" -ErrorAction SilentlyContinue | ForEach-Object { - # [PSCustomObject]@{ - # Name = $_.Name - # FolderName = 'Include' - # Path = $_.FullName - # } - # } - # if ($includeItems.Count -ne 0) { - # $ret += $includeItems - # } - - # $includeTestItems = Get-ChildItem -Path $includeTest -Filter "*$Filter*" -ErrorAction SilentlyContinue | ForEach-Object { - # [PSCustomObject]@{ - # Name = $_.Name - # FolderName = 'TestInclude' - # Path = $_.FullName - # } - # } - # if ($includeTestItems.Count -ne 0) { - # $ret += $includeTestItems - # } - - # return $ret } Export-ModuleMember -Function Get-IncludeFile <# @@ -117,9 +103,7 @@ function Open-IncludeFile{ [CmdletBinding()] param ( [Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0)][string]$Name, - [Parameter(Mandatory,ValueFromPipelineByPropertyName, Position = 1)] - # [ValidateSet('Include', 'Private', 'Public', 'Root', 'TestInclude', 'TestPrivate', 'TestPublic', 'TestRoot', 'Tools', 'DevContainer', 'WorkFlows', 'GitHub', 'Helper', 'Config', 'TestHelper', 'TestConfig')] - [string]$FolderName + [Parameter(Mandatory,ValueFromPipelineByPropertyName, Position = 1)][string]$FolderName ) process{ diff --git a/public/listSystemFiles.ps1 b/public/listSystemFiles.ps1 index 56474f0..5d20dd8 100644 --- a/public/listSystemFiles.ps1 +++ b/public/listSystemFiles.ps1 @@ -2,40 +2,95 @@ function Get-IncludeSystemFiles{ [CmdletBinding()] param( #add filter pattern - [Parameter(Mandatory = $false, Position = 0)] [string]$Filter = '*' + [Parameter(Mandatory = $false, Position = 0)] [string]$Filter = '*', + [Parameter()][switch]$Local ) - $includeItems =@() + $systemFolders = @( + # 'Root', + # 'Include', + 'DevContainer', + # 'WorkFlows', + 'GitHub', + # 'Config', + # 'Helper', + # 'Private', + # 'Public', + # 'Tools', + + # 'TestRoot', + # 'TestConfig' + # 'TestInclude', + # 'TestHelper', + # 'TestPrivate', + # 'TestPublic', + + "TestHelperRoot", + "TestHelperPrivate", + "TestHelperPublic", + + "VsCode" + + ) + + $includeItems = @() + # Get the files from folders that do not know the number of files in them + $includeItems += Get-IncludeFile -Folders $systemFolders -Local:$Local + # Root - $includeItems += [PSCustomObject]@{ FolderName = 'Root' ; Name = 'deploy.ps1' } - $includeItems += [PSCustomObject]@{ FolderName = 'Root' ; Name = 'LICENSE' } - # $includeItems += [PSCustomObject]@{ FolderName = 'Root' ; Name = '{modulename}.psd1' } - $includeItems += [PSCustomObject]@{ FolderName = 'Root' ; Name = '{modulename}.psm1' } - $includeItems += [PSCustomObject]@{ FolderName = 'Root' ; Name = 'release.ps1' } - $includeItems += [PSCustomObject]@{ FolderName = 'Root' ; Name = 'sync.ps1' } - $includeItems += [PSCustomObject]@{ FolderName = 'Root' ; Name = 'test.ps1' } + $includeItems += Get-IncludeFile -Local:$Local -Folders "Root" -Filter 'deploy.ps1' + $includeItems += Get-IncludeFile -Local:$Local -Folders "Root" -Filter 'LICENSE' + $includeItems += Get-IncludeFile -Local:$Local -Folders "Root" -Filter 'release.ps1' + $includeItems += Get-IncludeFile -Local:$Local -Folders "Root" -Filter 'sync.ps1' + $includeItems += Get-IncludeFile -Local:$Local -Folders "Root" -Filter 'test.ps1' # Tools - $includeItems += [PSCustomObject]@{ FolderName = 'Tools' ; Name = 'deploy.Helper.ps1' } - $includeItems += [PSCustomObject]@{ FolderName = 'Tools' ; Name = 'sync.Helper.ps1' } + $includeItems += Get-IncludeFile -Local:$Local -Folders "Tools" -Filter 'deploy.Helper.ps1' + $includeItems += Get-IncludeFile -Local:$Local -Folders "Tools" -Filter 'sync.Helper.ps1' + + #TestRoot + # $includeItems += Get-IncludeFile -Local:$Local -Folders "TestRoot" -Filter 'Test.psd1' + $includeItems += Get-IncludeFile -Local:$Local -Folders "TestRoot" -Filter 'Test.psm1' + + #WorkFlows + $includeItems += Get-IncludeFile -Local:$Local -Folders "WorkFlows" -Filter 'deploy_module_on_release.yml' + $includeItems += Get-IncludeFile -Local:$Local -Folders "WorkFlows" -Filter 'powershell.yml' + $includeItems += Get-IncludeFile -Local:$Local -Folders "WorkFlows" -Filter 'test_with_TestingHelper.yml' + + # Root + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'Root') ; Name = 'deploy.ps1' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'Root') ; Name = 'LICENSE' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'Root') ; Name = '{modulename}.psd1' } + $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'Root') ; Name = '{modulename}.psm1' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'Root') ; Name = 'release.ps1' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'Root') ; Name = 'sync.ps1' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'Root') ; Name = 'test.ps1' } + + # # Tools + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'Tools') ; Name = 'deploy.Helper.ps1' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'Tools') ; Name = 'sync.Helper.ps1' } # TestRoot - # $includeItems += [PSCustomObject]@{ FolderName = 'TestRoot' ; Name = 'Test.psd1' } - $includeItems += [PSCustomObject]@{ FolderName = 'TestRoot' ; Name = 'Test.psm1' } + # #$includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'TestRoot') ; Name = 'Test.psd1' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'TestRoot') ; Name = 'Test.psm1' } - # DevContainer - $includeItems += [PSCustomObject]@{ FolderName = 'DevContainer' ; Name = 'devcontainer.json' } + # # TestHelperRoot + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'TestHelperRoot') ; Name = 'Test_Helper.psd1' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'TestHelperRoot') ; Name = 'Test_Helper.psm1' } - # WorkFlows - $includeItems += [PSCustomObject]@{ FolderName = 'WorkFlows' ; Name = 'deploy_module_on_release.yml' } - $includeItems += [PSCustomObject]@{ FolderName = 'WorkFlows' ; Name = 'powershell.yml' } - $includeItems += [PSCustomObject]@{ FolderName = 'WorkFlows' ; Name = 'test_with_TestingHelper.yml' } + # # DevContainer + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'DevContainer') ; Name = 'devcontainer.json' } - # GitHub - $includeItems += [PSCustomObject]@{ FolderName = 'GitHub' ; Name = 'copilot-commit-message-instructions.md' } - $includeItems += [PSCustomObject]@{ FolderName = 'GitHub' ; Name = 'copilot-instructions.md' } + # # WorkFlows + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'WorkFlows') ; Name = 'deploy_module_on_release.yml' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'WorkFlows') ; Name = 'powershell.yml' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'WorkFlows') ; Name = 'test_with_TestingHelper.yml' } + + # # GitHub + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'GitHub') ; Name = 'copilot-commit-message-instructions.md' } + # $includeItems += [PSCustomObject]@{ FolderName = $(Get-Folder 'GitHub') ; Name = 'copilot-instructions.md' } # Filter items if($Filter -ne '*'){ @@ -45,3 +100,12 @@ function Get-IncludeSystemFiles{ return $includeItems } Export-ModuleMember -Function Get-IncludeSystemFiles + +function Get-Folder{ + [CmdletBinding()] + param( + [Parameter(Mandatory,Position = 0)][ValidateSet([ValidFolderNames])][string]$FolderName + ) + + return $FolderName +} \ No newline at end of file diff --git a/public/syncIncludeWithModule.ps1 b/public/syncIncludeWithModule.ps1 index fbe3d0c..bce3e58 100644 --- a/public/syncIncludeWithModule.ps1 +++ b/public/syncIncludeWithModule.ps1 @@ -1,11 +1,15 @@ function Sync-IncludeWithModule{ [CmdletBinding()] param( - [Parameter()][string]$DestinationModulePath + [Parameter()][string]$DestinationModulePath, + [Parameter()][switch]$DestinationIncludeHelper, + [Parameter()][switch]$SourceLocal ) - Get-IncludeFile | Add-IncludeToWorkspace -IfExists -DestinationModulePath $DestinationModulePath + $local = $SourceLocal.IsPresent - Get-IncludeSystemFiles | Add-IncludeToWorkspace -IfExists -DestinationModulePath $DestinationModulePath + Get-IncludeFile -Local:$local | Add-IncludeToWorkspace -IfExists -DestinationModulePath $DestinationModulePath -SourceLocal:$SourceLocal -DestinationIncludeHelper:$DestinationIncludeHelper + + Get-IncludeSystemFiles -Local:$local | Add-IncludeToWorkspace -IfExists -DestinationModulePath $DestinationModulePath -SourceLocal:$SourceLocal -DestinationIncludeHelper:$DestinationIncludeHelper } Export-ModuleMember -Function Sync-IncludeWithModule \ No newline at end of file From 4c842c6fc7a22de56f130ca221f8986f07840a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 22 Jan 2026 15:13:22 +0100 Subject: [PATCH 2/7] feat(tools): add script to remove trailing whitespace from PowerShell files --- tools/remove-trailing-whitespace.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tools/remove-trailing-whitespace.ps1 diff --git a/tools/remove-trailing-whitespace.ps1 b/tools/remove-trailing-whitespace.ps1 new file mode 100644 index 0000000..83dbd85 --- /dev/null +++ b/tools/remove-trailing-whitespace.ps1 @@ -0,0 +1,25 @@ +# Script to remove trailing whitespace from PowerShell files +# This addresses the PSAvoidTrailingWhitespace rule in PSScriptAnalyzer + +Write-Host "Removing trailing whitespace from files..." -ForegroundColor Green + +# Get all PowerShell files recursively +$files = Get-ChildItem -Path . -Include *.ps1, *.psm1, *.psd1 -Recurse + +$count = 0 + +foreach ($file in $files) { + $content = Get-Content -Path $file.FullName -Raw + + # Replace trailing whitespace with nothing + $newContent = $content -replace '[ \t]+\r?\n', "`n" + + # Check if content changed + if ($newContent -ne $content) { + Set-Content -Path $file.FullName -Value $newContent -NoNewline + $count++ + Write-Host "Fixed: $($file.FullName)" + } +} + +Write-Host "Done! Fixed trailing whitespace in $count files." -ForegroundColor Green From 7a47304f281c7e2c03cc411e6653ee8e26b5538c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 22 Jan 2026 15:16:51 +0100 Subject: [PATCH 3/7] style: remove tailing whitespaces from all files --- Test/helper/module.helper.ps1 | 2 +- Test/include/callPrivateContext.ps1 | 4 +-- Test/include/config.mock.ps1 | 6 ++-- Test/include/database.mock.ps1 | 2 +- Test/include/parameter.test.helper.ps1 | 2 +- Test/include/run_BeforeAfter.ps1 | 2 +- Test/include/transcriptHelp.ps1 | 4 +-- Test/public/MyWrite.test.ps1 | 2 +- Test/public/SampleFunctionTests.ps1 | 10 +++--- Test/public/addIncludeToWorkspace.test.ps1 | 36 +++++++++++----------- Test/public/callAPI.test.ps1 | 8 ++--- Test/public/datehelper.test.ps1 | 4 +-- Test/public/dependencies.test.ps1 | 22 ++++++------- Test/public/featureflag.test.ps1 | 4 +-- Test/public/invokeCommand.mock.test.ps1 | 14 ++++----- Test/public/listIncludes.test.ps1 | 2 +- Test/public/module.helper.test.ps1 | 12 ++++---- deploy.ps1 | 8 ++--- helper/module.helper.ps1 | 2 +- include/MyWrite.ps1 | 4 +-- include/callAPI.ps1 | 26 ++++++++-------- include/config.ps1 | 2 +- include/databaseV2.ps1 | 16 +++++----- include/datehelper.ps1 | 16 +++++----- include/dependencies.ps1 | 18 +++++------ include/featureflag.ps1 | 4 +-- include/getHashCode.ps1 | 2 +- private/samplePrivateFunction.ps1 | 2 +- public/addIncludeToWorkspace.ps1 | 14 ++++----- public/copyIncludeToWorkspace.ps1 | 12 ++++---- public/listIncludes.ps1 | 8 ++--- public/listSystemFiles.ps1 | 2 +- public/selectByFolder.ps1 | 2 +- release.ps1 | 8 ++--- sync.ps1 | 2 +- test.ps1 | 2 +- tools/deploy.Helper.ps1 | 18 +++++------ tools/sync.Helper.ps1 | 2 +- 38 files changed, 153 insertions(+), 153 deletions(-) diff --git a/Test/helper/module.helper.ps1 b/Test/helper/module.helper.ps1 index 7ac11cd..670d090 100644 --- a/Test/helper/module.helper.ps1 +++ b/Test/helper/module.helper.ps1 @@ -19,7 +19,7 @@ function Find-ModuleRootPath{ $path = $path | Split-Path -Parent continue } - + # foudn module return $path } diff --git a/Test/include/callPrivateContext.ps1 b/Test/include/callPrivateContext.ps1 index 9b9a1e8..a7e7f83 100644 --- a/Test/include/callPrivateContext.ps1 +++ b/Test/include/callPrivateContext.ps1 @@ -21,12 +21,12 @@ function Invoke-PrivateContext { if ([string]::IsNullOrEmpty($ModulePath)) { $modulePath = $MODULE_PATH | Split-Path -Parent } - + $module = Import-Module -Name $modulePath -PassThru if ($null -eq $module) { throw "Failed to import the main module." } - & $module $ScriptBlock + & $module $ScriptBlock } Export-ModuleMember -Function Invoke-PrivateContext diff --git a/Test/include/config.mock.ps1 b/Test/include/config.mock.ps1 index 5f5abc6..9a50f77 100644 --- a/Test/include/config.mock.ps1 +++ b/Test/include/config.mock.ps1 @@ -1,5 +1,5 @@ -# CONFIG MOCK +# CONFIG MOCK # # This file is used to mock the config path and the config file # for the tests. It creates a mock config path and a mock config file @@ -38,8 +38,8 @@ function Mock_Config{ if([string]::IsNullOrWhiteSpace($ModuleName)){ $moduleName = $MODULE_NAME - } - + } + $invokefunction = $CONFIG_INVOKE_GET_ROOT_PATH_CMD -replace "{modulename}", $moduleName # Mock invoke call diff --git a/Test/include/database.mock.ps1 b/Test/include/database.mock.ps1 index 3932a9f..bdd8838 100644 --- a/Test/include/database.mock.ps1 +++ b/Test/include/database.mock.ps1 @@ -1,4 +1,4 @@ -# DATABASE MOCK +# DATABASE MOCK # # This file is used to mock the database path and the database file # for the tests. It creates a mock database path and a mock database file diff --git a/Test/include/parameter.test.helper.ps1 b/Test/include/parameter.test.helper.ps1 index 4837c40..45dde5a 100644 --- a/Test/include/parameter.test.helper.ps1 +++ b/Test/include/parameter.test.helper.ps1 @@ -27,7 +27,7 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Scope='function')] $WarningParameters = @{ - WarningAction = 'SilentlyContinue' + WarningAction = 'SilentlyContinue' WarningVariable = 'warningVar' } diff --git a/Test/include/run_BeforeAfter.ps1 b/Test/include/run_BeforeAfter.ps1 index 0807113..15439ee 100644 --- a/Test/include/run_BeforeAfter.ps1 +++ b/Test/include/run_BeforeAfter.ps1 @@ -1,5 +1,5 @@ # Run Before and After any test -# +# # Supported by TestingHelper 4.1.0 we can specify code that will run : # - Before each test # - After each test diff --git a/Test/include/transcriptHelp.ps1 b/Test/include/transcriptHelp.ps1 index 4d36a40..892d25e 100644 --- a/Test/include/transcriptHelp.ps1 +++ b/Test/include/transcriptHelp.ps1 @@ -17,7 +17,7 @@ function Start-MyTranscript { } function Stop-MyTranscript { - + $null = Stop-Transcript $transcriptContent = Get-Content -Path $TEST_TRANSCRIPT_FILE @@ -41,6 +41,6 @@ function Export-MyTranscript { $lastLine = $i[2] - 1 $retlist = $transcriptContent[$firstLine..$lastLine] - + return $retlist } diff --git a/Test/public/MyWrite.test.ps1 b/Test/public/MyWrite.test.ps1 index 5794b18..0f8f2c0 100644 --- a/Test/public/MyWrite.test.ps1 +++ b/Test/public/MyWrite.test.ps1 @@ -5,7 +5,7 @@ function Test_WriteMyHost_Singleline { Invoke-PrivateContext { Write-MyHost -Message "This is a test transcript." } - + $result = Stop-MyTranscript Assert-AreEqual -Expected "This is a test transcript." -Presented $result diff --git a/Test/public/SampleFunctionTests.ps1 b/Test/public/SampleFunctionTests.ps1 index 34b30f2..720d192 100644 --- a/Test/public/SampleFunctionTests.ps1 +++ b/Test/public/SampleFunctionTests.ps1 @@ -1,13 +1,13 @@ $TESTED_MODULE_PATH = $PSScriptRoot | split-path -Parent | split-path -Parent -function Test_GetPublicString{ +function Test_GetPublicString{ $sampleString = "this is a sample string" - + $result = Get-PublicString -Param1 $sampleString Assert-AreEqual -Expected ("Public string [{0}]" -f $samplestring) -presented $result -Comment "Sample test failed" - + } function Test_GetPrivateString { @@ -16,12 +16,12 @@ function Test_GetPrivateString { $testedModule = Import-Module -Name $testedModulePath -Force -PassThru $sampleString = "this is a sample string" - + $result = & $testedModule { $sampleString = "this is a sample string" Get-PrivateString -Param1 $sampleString } Assert-AreEqual -Expected ("Private string [{0}]" -f $samplestring) -presented $result -Comment "Sample test failed" - + } diff --git a/Test/public/addIncludeToWorkspace.test.ps1 b/Test/public/addIncludeToWorkspace.test.ps1 index 5810813..5d21023 100644 --- a/Test/public/addIncludeToWorkspace.test.ps1 +++ b/Test/public/addIncludeToWorkspace.test.ps1 @@ -61,7 +61,7 @@ function Test_AddIncludeToWorkspace_Force{ } function Test_AddIncludeToWorkspace_WithFileTransformation{ - + Import-Module -Name TestingHelper New-ModuleV3 -Name TestModule @@ -112,13 +112,13 @@ function Test_AddIncludeToWorkspace_IfExists{ } function Test_AddIncludeToWorkspace_PipeParameters{ - + Import-Module -Name TestingHelper New-ModuleV3 -Name TestModule - + # Test for Include $destinationModulePath = "TestModule" - + $includesToAdd = @( [PSCustomObject]@{ Name = "config.ps1"; FolderName = "Include" }, [PSCustomObject]@{ Name = "config.mock.ps1"; FolderName = "TestInclude" } @@ -138,7 +138,7 @@ function Test_AddIncludeToWorkspace_PipeParameters{ } function Test_AddIncludeToWorkspace_WithoutSource_WithoutDestination{ - + Reset-InvokeCommandMock Import-Module -Name TestingHelper @@ -150,10 +150,10 @@ function Test_AddIncludeToWorkspace_WithoutSource_WithoutDestination{ $destinationFilePath = $destinationPath | Join-Path -ChildPath $destinationName Remove-Item -Path $destinationFilePath -ErrorAction SilentlyContinue - + # Act Assert-itemNotExist -path $destinationFilePath - + Set-Location -Path ./TestModule $fileInfo | Add-IncludeToWorkspace Set-Location -Path ../ @@ -189,7 +189,7 @@ function Test_AddIncludeToWorkspace_FromSourceToDestination{ # Act $includes = Get-IncludeFile -ModuleRootPath $SourceModuleName $includes | Add-IncludeToWorkspace -SourceModulePath $SourceModuleName -DestinationModulePath $TargetModuleName - + # Assert Assert-ItemExist -Path "$TInclude\MyInclude1.ps1" Assert-ItemExist -Path "$TInclude\MyInclude2.ps1" @@ -197,14 +197,14 @@ function Test_AddIncludeToWorkspace_FromSourceToDestination{ # With soruce not destination function Test_AddIncludeToWorkspace_FromSourceToDestination_WithoutDestination{ - + Reset-InvokeCommandMock $FileName1 = "MyInclude1.ps1" $FileName2 = "MyInclude2.ps1" $DestinationModuleName = "DestinationModule" - $SourceModuleName = "SourceModule" + $SourceModuleName = "SourceModule" $DestinationModulePath = New-ModuleV3 -Name $DestinationModuleName $SourceModulePath = New-ModuleV3 -Name $SourceModuleName @@ -221,7 +221,7 @@ function Test_AddIncludeToWorkspace_FromSourceToDestination_WithoutDestination{ $includes = Get-IncludeFile -ModuleRootPath $SourceModulePath Assert-Count -Expected 2 -Presented $includes $includes | Add-IncludeToWorkspace -SourceModulePath $SourceModulePath - + # Assert Assert-ItemExist -Path "$TInclude\MyInclude1.ps1" Assert-ItemExist -Path "$TInclude\MyInclude2.ps1" @@ -238,34 +238,34 @@ function Test_ResolveSourceDestinationPath{ $DestinationModuleName = "TargetModule" $SourceModuleName = "SourceModule" $LocalModuleName = "LocalModule" - + # Includehelper root folder $local = $PSScriptRoot $IncludeHelperModulePath = $local | Split-Path -Parent | Split-Path -Parent - + # TEsting modules New-ModuleV3 -Name $DestinationModuleName ; $DestinationModulePath = $DestinationModuleName | Convert-Path New-ModuleV3 -Name $SourceModuleName ; $SourceModulePath = $SourceModuleName | Convert-Path New-ModuleV3 -Name $LocalModuleName ; $LocalModulePath = $LocalModuleName | Convert-Path - + # Set location to test module $LocalModuleName | Set-Location - + # Act Null / Null - Soruce:Include to Destination:local $resultsource,$resultdestination = Resolve-SourceDestinationPath Assert-AreEqualPath -Presented $resultsource -Expected $IncludeHelperModulePath Assert-AreEqualPath -Presented $resultdestination -Expected $LocalModulePath - + # Act Source / Null - Source: Path to Destination: local $resultsource,$resultdestination = Resolve-SourceDestinationPath -SourceModulePath $SourceModulePath Assert-AreEqualPath -Presented $resultsource -Expected $SourceModulePath Assert-AreEqualPath -Presented $resultdestination -Expected $LocalModulePath - + # Act Null / Destination sourceI:Include to Destination: Path $resultsource,$resultdestination = Resolve-SourceDestinationPath -DestinationModulePath $DestinationModulePath Assert-AreEqualPath -Presented $resultsource -Expected $IncludeHelperModulePath Assert-AreEqualPath -Presented $resultdestination -Expected $DestinationModulePath - + # Act Sorce / Destination - Source: Path to Destination: Path $resultsource,$resultdestination = Resolve-SourceDestinationPath -SourceModulePath $SourceModulePath -DestinationModulePath $DestinationModulePath Assert-AreEqualPath -Presented $resultsource -Expected $SourceModulePath diff --git a/Test/public/callAPI.test.ps1 b/Test/public/callAPI.test.ps1 index fae7ac3..64912fe 100644 --- a/Test/public/callAPI.test.ps1 +++ b/Test/public/callAPI.test.ps1 @@ -5,7 +5,7 @@ function Test_CallAPI_RESTAPI_Withpagination_1{ Enable-InvokeCommandAliasModule # Act - $result = Invoke-RestAPI -Api "/orgs/octodemo/credential-authorizations" + $result = Invoke-RestAPI -Api "/orgs/octodemo/credential-authorizations" Assert-Count -Expected 31 -Presented $result @@ -31,7 +31,7 @@ function Test_CallAPI_RESTAPI_Withpagination_2{ } function Test_Call_API_GraphQL{ - + Assert-SkipTest "This test is not implemented" Reset-InvokeCommandMock @@ -44,14 +44,14 @@ function Test_Call_API_GraphQL{ '@ $variables = @{login = "octodemo"} - $result = Invoke-GraphQL -Query $query -variables $variables + $result = Invoke-GraphQL -Query $query -variables $variables Assert-AreEqual -Presented $result.data.organization.id -Expected "MDEyOk9yZ2FuaXphdGlvbjM4OTQwODk3" } function Test_Call_API_GraphQL_outfile{ - + Assert-SkipTest "This test is not implemented" Reset-InvokeCommandMock diff --git a/Test/public/datehelper.test.ps1 b/Test/public/datehelper.test.ps1 index 1709bb8..da5a704 100644 --- a/Test/public/datehelper.test.ps1 +++ b/Test/public/datehelper.test.ps1 @@ -64,7 +64,7 @@ function Test_GetDaysBetweenDates_DefaultStartDate { $futureDate = (Get-Date).AddDays(10) | Get-Date -Format 'yyyy-MM-dd' $result = Get-DaysBetweenDates -EndDate $futureDate - + # Result should be approximately 10 days (allowing for same-day test execution) Assert-AreEqual -Expected 10 -Presented $result } @@ -181,7 +181,7 @@ function Test_ConvertToEpochTime_BeforeEpoch { $dateTime = [datetime]::UnixEpoch.AddDays(-1) $result = ConvertTo-EpochTime -DateTime $dateTime - + # Assert Assert-AreEqual -Expected -86400 -Presented $result diff --git a/Test/public/dependencies.test.ps1 b/Test/public/dependencies.test.ps1 index d580f51..245c207 100644 --- a/Test/public/dependencies.test.ps1 +++ b/Test/public/dependencies.test.ps1 @@ -11,7 +11,7 @@ function Test_ImportDepepency_Already_loaded{ # Mock Import-Module Mock_ImportModule -Name $name -Folder $modulesFolder - + #Act Enable-IncludeHelperVerbose Start-MyTranscript @@ -21,7 +21,7 @@ function Test_ImportDepepency_Already_loaded{ #Assert verbose message Assert-AreEqual -Expected $name -Presented $result.Name - Assert-Contains -Presented $tt -Expected "Module [$Name] imported from own module" + Assert-Contains -Presented $tt -Expected "Module [$Name] imported from own module" } function Test_ImportDepepency_SideBySide{ @@ -186,7 +186,7 @@ function Mock_GetModule_Null{ param( [Parameter(Mandatory,Position=0)][string]$Name ) - + MockCallToNull -Command "Get-Module -Name $name" } @@ -197,11 +197,11 @@ function Mock_GetModuleListAvailable{ [Parameter(Mandatory,Position=0)][string]$Name, [Parameter(Mandatory,Position=1)][string]$Folder ) - + $path = "$Folder/$Name" $path = Convert-Path -Path $path $expression = "New-Object -TypeName PSCustomObject -Property @{ Name = '$name'; Path = '$path' }" - + MockCallExpression -Command "Get-Module -Name $name -ListAvailable" -Expression $expression } @@ -210,8 +210,8 @@ function Mock_GetModuleListAvailable_Null{ param( [Parameter(Mandatory,Position=0)][string]$Name ) - - MockCallToNull -Command "Get-Module -Name $name -ListAvailable" + + MockCallToNull -Command "Get-Module -Name $name -ListAvailable" } @@ -241,7 +241,7 @@ function Mock_ImportModule{ $command = $command -replace "{path}", $path MockCallExpression -Command $command -Expression $expression - + } function Convert-MyPath{ @@ -273,9 +273,9 @@ function Mock_GetMyModuleRootPath{ ) # Mock GetMyModuleRootPath on SideBySide - # Check that happens before ImportFromModuleManager + # Check that happens before ImportFromModuleManager # that we are testing here - $modulePath = "$Folder/$Name" + $modulePath = "$Folder/$Name" New-ModuleV3 -Name $Name -Path $folder $path = Convert-Path -Path $modulePath MockCallToString -Command 'GetMyModuleRootPath' -OutString "$path" @@ -304,7 +304,7 @@ function Mock_CloneRepo{ [Parameter(Mandatory,Position=1)][string]$Name, [Parameter(Mandatory,Position=2)][string]$Folder ) - + $url = "https://github.com/$owner/$Name" $path = "$Folder/$Name" $path = Convert-MyPath -Path $path diff --git a/Test/public/featureflag.test.ps1 b/Test/public/featureflag.test.ps1 index 12cd516..528b604 100644 --- a/Test/public/featureflag.test.ps1 +++ b/Test/public/featureflag.test.ps1 @@ -20,7 +20,7 @@ function Test_FeatureFlag_Success{ # Set flag adds $true to the config.FeatureFlags $config = Get-Content $configFilePath| ConvertFrom-Json -AsHashtable Assert-IsTrue -Condition $config.FeatureFlags.$ffName - + Clear-FeatureFlag $ffName $result = tff $ffName Assert-IsFalse -Condition $result @@ -46,7 +46,7 @@ function Test_RegisteredFeatureFlags_Success{ Get-IncludeFile config.ps1 | Add-IncludeToWorkspace -DestinationModulePath $fullpath Get-IncludeFile featureflag.ps1 | Add-IncludeToWorkspace -DestinationModulePath $fullpath Get-IncludeFile module.helper.ps1 | Add-IncludeToWorkspace -DestinationModulePath $fullpath - + # Add a fake Registered featureflags configuration $reg = @{ deprecated = @( diff --git a/Test/public/invokeCommand.mock.test.ps1 b/Test/public/invokeCommand.mock.test.ps1 index 22458a2..48abf06 100644 --- a/Test/public/invokeCommand.mock.test.ps1 +++ b/Test/public/invokeCommand.mock.test.ps1 @@ -89,31 +89,31 @@ function Test_MockCallExpression{ function Test_TraceInvokeCOmmandAlias{ - + $fileName = "traceInvoke.log" Assert-ItemNotExist -Path $fileName - - # Set flag + + # Set flag touch $fileName $fileNamePath = $fileName | Resolve-Path $env:TraceInvokeMockFilePath = $fileNamePath Assert-ItemExist -Path $fileNamePath - + # Act record invoke alias Set-InvokeCommandMock -alias "fakeAlias1" -Command 'echo "hello from fakeAlias1"' Set-InvokeCommandMock -alias "fakeAlias2" -Command 'echo "hello from fakeAlias2"' - + # Assert the two new alias are recorded $content = Get-Content $fileNamePath Assert-Count -Expected 2 -Presented $content Assert-Contains -Presented $content -Expected 'fakeAlias1' Assert-Contains -Presented $content -Expected 'fakeAlias2' - + # Assert no duplicate alias are recorded Set-InvokeCommandMock -alias "fakeAlias1" -Command 'echo "hello from fakeAlias1"' $content = Get-Content $fileNamePath Assert-Count -Expected 2 -Presented $content - + # Assert new alias are recorded Set-InvokeCommandMock -alias "fakeAlias3" -Command 'echo "hello from fakeAlias1"' $content = Get-Content $fileNamePath diff --git a/Test/public/listIncludes.test.ps1 b/Test/public/listIncludes.test.ps1 index 87dc16c..56cafe9 100644 --- a/Test/public/listIncludes.test.ps1 +++ b/Test/public/listIncludes.test.ps1 @@ -63,7 +63,7 @@ function Test_GetIncludeSystemFiles { # Act $result = Get-IncludeSystemFiles - + # Assert Assert-Count -Expected $expectedList.Count -Presented $result diff --git a/Test/public/module.helper.test.ps1 b/Test/public/module.helper.test.ps1 index 24fd690..330d3c6 100644 --- a/Test/public/module.helper.test.ps1 +++ b/Test/public/module.helper.test.ps1 @@ -1,11 +1,11 @@ function Test_ModuleHelper_AreEqual_InModule_And_TestModule{ - - # to avoid confusion we need to ensure that this helper has the same + + # to avoid confusion we need to ensure that this helper has the same # code in both module and test modules $name = "module.helper.ps1" - + $files = get-includefile -Filter $name $filePath = @{} @@ -76,8 +76,8 @@ function Test_FindModuleRootPath{ $moduleName = "TestModule" New-ModuleV3 -Name $moduleName -AddTesting - New-TestingFolder -Path "$moduleName/include/kk1/kk2" - New-TestingFolder -Path "$moduleName/Test/include/kk1/kk2" + New-TestingFolder -Path "$moduleName/include/kk1/kk2" + New-TestingFolder -Path "$moduleName/Test/include/kk1/kk2" New-testingFolder -Path "kk1/kk2/kk3" $moduleRootPath = $moduleName | Convert-Path @@ -93,7 +93,7 @@ function Test_FindModuleRootPath{ Assert-AreEqual -Expected $moduleRootPath -Presented $result } - @( + @( ".", "kk1", "kk1/kk2", diff --git a/deploy.ps1 b/deploy.ps1 index bf66cfb..c78abaf 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -19,7 +19,7 @@ .EXAMPLE $env:$NUGETAPIKEY = '****' - .\deploy.ps1 -VersionTag v10.0.01-alpha + .\deploy.ps1 -VersionTag v10.0.01-alpha .EXAMPLE .\deploy.ps1 -VersionTag v10.0.01-alpha -NuGetApiKey $NUGETAPIKEY -DependencyInjection $SCRIPTBLOCK_FOR_TESTING @@ -45,12 +45,12 @@ $MODULE_NAME = $MODULE_PATH | Split-Path -LeafBase $MODULE_PSD1 = Join-Path -Path $MODULE_PATH -ChildPath "$MODULE_NAME.psd1" $MODULE_TOOLS = Join-Path -Path $MODULE_PATH -ChildPath "tools" -# Load helper +# Load helper # We dot souce the ps1 to allow all code to be in the same scope as the script # Easier to inject for testing with DependecyInjection parameter . ($MODULE_TOOLS | Join-Path -ChildPath "deploy.Helper.ps1") -if ($DependencyInjection) { - . $DependencyInjection +if ($DependencyInjection) { + . $DependencyInjection } # Process Tag diff --git a/helper/module.helper.ps1 b/helper/module.helper.ps1 index 7ac11cd..670d090 100644 --- a/helper/module.helper.ps1 +++ b/helper/module.helper.ps1 @@ -19,7 +19,7 @@ function Find-ModuleRootPath{ $path = $path | Split-Path -Parent continue } - + # foudn module return $path } diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index 43173fc..7c4e8bd 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -195,11 +195,11 @@ function Get-ObjetString { if ($null -eq $Object) { return "null" } - + if ($Object -is [string]) { return $Object } - + return $Object | ConvertTo-Json -Depth 10 -ErrorAction SilentlyContinue } } diff --git a/include/callAPI.ps1 b/include/callAPI.ps1 index f7475a3..8e96b37 100644 --- a/include/callAPI.ps1 +++ b/include/callAPI.ps1 @@ -20,27 +20,27 @@ function Invoke-GraphQL { try { $apiUri = "https://api.$ApiHost/graphql" - + # Define the headers for the request $headers = @{ "Authorization" = "Bearer $token" "Content-Type" = "application/json" "GraphQL-Features" = $GRAPHQL_FEATURES } - + # Define the body for the request $body = @{ query = $Query variables = $Variables } | ConvertTo-Json -Depth 100 - + # Trace request "[[QUERY]]" | writedebug $Query | writedebug - + "[[VARIABLES]]" | writedebug $Variables | ConvertTo-Json -Depth 100 | writedebug - + # Send the request $start = Get-Date ">>> Invoke-RestMethod - $apiUri" | writedebug @@ -48,15 +48,15 @@ function Invoke-GraphQL { { $response = Invoke-RestMethod -Uri $apiUri -Method Post -Body $body -Headers $headers } else { $response = Invoke-RestMethod -Uri $apiUri -Method Post -Body $body -Headers $headers -OutFile $OutFile } "<<< Invoke-RestMethod - $apiUri [ $(((Get-Date) - $start).TotalSeconds) seconds]" | writedebug - + # Trace response "[[RESPONSE]]" | writedebug $response | ConvertTo-Json -Depth 100 | writedebug - + if($response.errors){ throw "GraphQL query return errors - Error: $($response.errors.message)" } - + return $response } catch { @@ -82,21 +82,21 @@ function Invoke-RestAPI { try { $apiHost = "api.$ApiHost" - + # Define the headers for the request $headers = @{ "Authorization" = "Bearer $token" "Content-Type" = "application/json" } - + $uriBuilder = New-Object System.UriBuilder $uriBuilder.Scheme = "https" $uriBuilder.Host = $apiHost $uriBuilder.Path = $api $uriBuilder.Query = "?per_page=$PageSize" - + $url = $uriBuilder.Uri.AbsoluteUri - + # Send the request $start = Get-Date ">>> Invoke-RestMethod - $url" | writedebug @@ -125,7 +125,7 @@ function Invoke-RestAPI { } "<<< Invoke-RestMethod - $url [ $(((Get-Date) - $start).TotalSeconds) seconds]" | writedebug - + # Trace response "[[RESPONSE]]" | writedebug $response | ConvertTo-Json -Depth 100 | writedebug diff --git a/include/config.ps1 b/include/config.ps1 index 1e2b2d5..cc3207e 100644 --- a/include/config.ps1 +++ b/include/config.ps1 @@ -101,7 +101,7 @@ function Save-Configuration { return $false } finally{ - Remove-Variable -Scope Script -Name "config-$Key" -ErrorAction SilentlyContinue + Remove-Variable -Scope Script -Name "config-$Key" -ErrorAction SilentlyContinue } return $true diff --git a/include/databaseV2.ps1 b/include/databaseV2.ps1 index 3fb68f2..1141f95 100644 --- a/include/databaseV2.ps1 +++ b/include/databaseV2.ps1 @@ -20,15 +20,15 @@ $DB_INVOKE_GET_ROOT_PATH_ALIAS = "$($MODULE_NAME)GetDbRootPath" $function = "Invoke-$($MODULE_NAME)GetDbRootPath" if(-not (Test-Path -Path function:$function)){ - + # PUBLIC FUNCTION function Invoke-MyModuleGetDbRootPath{ [CmdletBinding()] param() - + $databaseRoot = GetDatabaseRootPath return $databaseRoot - + } Rename-Item -path Function:Invoke-MyModuleGetDbRootPath -NewName $function Export-ModuleMember -Function $function @@ -41,15 +41,15 @@ if(-not (Test-Path -Path function:$function)){ function Reset-MyModuleDatabaseStore{ [CmdletBinding()] param() - + $databaseRoot = Invoke-MyCommand -Command $DB_INVOKE_GET_ROOT_PATH_ALIAS - + Remove-Item -Path $databaseRoot -Recurse -Force -ErrorAction SilentlyContinue - + New-Item -Path $databaseRoot -ItemType Directory - + } - + Rename-Item -path Function:Reset-MyModuleDatabaseStore -NewName $function Export-ModuleMember -Function $function } diff --git a/include/datehelper.ps1 b/include/datehelper.ps1 index 9e826bd..97f5cd2 100644 --- a/include/datehelper.ps1 +++ b/include/datehelper.ps1 @@ -25,9 +25,9 @@ function Get-DaysBetweenDates { $start = [DateTime]::ParseExact($StartDate, 'yyyy-MM-dd', $null) $end = [DateTime]::ParseExact($EndDate, 'yyyy-MM-dd', $null) - + $timeSpan = $end - $start - + return [Math]::Abs($timeSpan.Days) } @@ -35,11 +35,11 @@ function Get-EpochTime { [CmdletBinding()] [OutputType([long])] param() - + $epoch = [datetime]::UnixEpoch $now = Invoke-MyCommand -Command GetUtcNow $timeSpan = $now - $epoch - + return [long]$timeSpan.TotalSeconds } @@ -50,10 +50,10 @@ function ConvertFrom-EpochTime { [Parameter(Mandatory, Position = 0)] [long]$EpochTime ) - + $epoch = [datetime]::UnixEpoch $dateTime = $epoch.AddSeconds($EpochTime) - + return $dateTime } @@ -64,9 +64,9 @@ function ConvertTo-EpochTime { [Parameter(Mandatory, Position = 0)] [datetime]$DateTime ) - + $epoch = [datetime]::UnixEpoch $timeSpan = $DateTime.ToUniversalTime() - $epoch - + return [long]$timeSpan.TotalSeconds } diff --git a/include/dependencies.ps1 b/include/dependencies.ps1 index 2c1538f..7bc66d5 100644 --- a/include/dependencies.ps1 +++ b/include/dependencies.ps1 @@ -30,19 +30,19 @@ Set-MyInvokeCommandAlias -Alias "ImportModule" -Command 'Import-Module # function Invoke-MyModuleRootPath{ # [CmdletBinding()] # param() - + # # We will asume that this include file will be on a public,private or include folder. # $root = $PSScriptRoot | split-path -Parent - + # # confirm that in root folder we have a psd1 file # $psd1 = Get-ChildItem -Path $root -Filter *.psd1 -Recurse -ErrorAction SilentlyContinue - + # if(-Not $psd1){ # throw "Wrong root folder. Not PSD1 file found in [$root]. Modify Invoke-GetMyModuleRootPath to adjust location" -# } - +# } + # return $root -# } +# } # Copy-Item -path Function:Invoke-MyModuleRootPath -Destination Function:"Invoke-$($MODULE_NAME)RootPath" # Export-ModuleMember -Function "Invoke-$($MODULE_NAME)RootPath" @@ -124,7 +124,7 @@ function Import-Dependency{ $url = "https://github.com/rulasg/$name" $testUrl = Invoke-MyCommand -Command 'TestGitHubRepo' -Parameters @{ url = $url } -ErrorAction SilentlyContinue - + if ($testUrl -eq $true) { # Clone side by side this module $local = Invoke-MyCommand -Command 'GetMyModuleRootPath' @@ -153,7 +153,7 @@ function Import-Dependency{ "Failed to reload module [$Name] from GitHub repository" | Write-Verbose return $null } - } + } else # Url not found { "Module [$Name] not found in GitHub repository" | Write-Verbose @@ -174,7 +174,7 @@ function Import-MyModule{ # $result = Get-Module -Name $module.Name $result = Invoke-MyCommand -Command 'GetModule' -Parameters @{ name = $module.Name } - + return $result } diff --git a/include/featureflag.ps1 b/include/featureflag.ps1 index 677a491..aaed2a5 100644 --- a/include/featureflag.ps1 +++ b/include/featureflag.ps1 @@ -2,7 +2,7 @@ # # Feature Flags management module # -# This module will allow set Feature Flags to the module to quicker release +# This module will allow set Feature Flags to the module to quicker release # features with less risk # # Include design description @@ -120,7 +120,7 @@ function Get-ModuleNameRegisteredFeatureFlags{ return } - $Json = Get-Content $ffPath + $Json = Get-Content $ffPath $ff = $Json | ConvertFrom-Json diff --git a/include/getHashCode.ps1 b/include/getHashCode.ps1 index 830a869..2d6b285 100644 --- a/include/getHashCode.ps1 +++ b/include/getHashCode.ps1 @@ -19,7 +19,7 @@ function Get-HashCode { $bytes = [System.Text.Encoding]::UTF8.GetBytes($InputString) $hashBytes = $md5.ComputeHash($bytes) $hashString = [BitConverter]::ToString($hashBytes) -replace '-', '' - + return $hashString } diff --git a/private/samplePrivateFunction.ps1 b/private/samplePrivateFunction.ps1 index f929475..83580a5 100644 --- a/private/samplePrivateFunction.ps1 +++ b/private/samplePrivateFunction.ps1 @@ -5,4 +5,4 @@ function Get-PrivateString { ) return ("Private string [{0}]" -f $param1) -} +} diff --git a/public/addIncludeToWorkspace.ps1 b/public/addIncludeToWorkspace.ps1 index 2f53782..a3cefa1 100644 --- a/public/addIncludeToWorkspace.ps1 +++ b/public/addIncludeToWorkspace.ps1 @@ -3,7 +3,7 @@ Adds an include folder to the workspace. .DESCRIPTION -The Add-IncludeToWorkspace function adds a specified include folder to the workspace. +The Add-IncludeToWorkspace function adds a specified include folder to the workspace. It supports ShouldProcess for safety and allows specifying the destination module path. .PARAMETER Name @@ -87,7 +87,7 @@ function Add-IncludeToWorkspace { # Expand filecontent Transformations $content = Expand-FileContentTransformation -SourceFileName $sourceFile -SourceModulePath $SourceModulePath -DestinationModulePath $DestinationModulePath - + #Skip destination module check if Force is set if(-Not $Force){ # Check if there is a .psd1 file in the DestinationModulePath @@ -96,18 +96,18 @@ function Add-IncludeToWorkspace { throw "Destination Path $DestinationModulePath does not seem to be a PowershellMddule." } } - + # create destination folder if it does not exist if(-Not (Test-Path $destinationpath)){ #"Create folder $destinationpath" | Write-MyDebug $null = New-Item -Path $destinationpath -ItemType Directory -Force } - + # Check if source file exists if(-Not (Test-Path $sourceFile)){ throw "File $sourceFile not found" } - + if ($PSCmdlet.ShouldProcess("$sourceFile", "copy to $destinationFile")) { # Copy-Item -Path $sourceFile -Destination $destinationFile -Force Set-Content -Path $destinationFile -Value $content -Force @@ -128,7 +128,7 @@ function Resolve-SourceDestinationPath{ [Parameter(Position=1)][string]$DestinationModulePath ) # This function copies include files from one module to another - # We have two wellknown modules: + # We have two wellknown modules: # 1. Local Running module: this is the module where this function is running # 2. Local Path model : the module present where the location is set. aka '.' # We have two parameters: @@ -146,7 +146,7 @@ function Resolve-SourceDestinationPath{ if([string]::IsNullOrWhiteSpace($DestinationModulePath)){ $DestinationModulePath = Get-ModuleFolder -FolderName 'Root' -ModuleRootPath '.' } - + $SourceModulePath = Convert-Path -Path $SourceModulePath $DestinationModulePath = Convert-Path -Path $DestinationModulePath diff --git a/public/copyIncludeToWorkspace.ps1 b/public/copyIncludeToWorkspace.ps1 index d15dddb..bee0860 100644 --- a/public/copyIncludeToWorkspace.ps1 +++ b/public/copyIncludeToWorkspace.ps1 @@ -6,7 +6,7 @@ function Copy-IncludeToWorkSpace{ [Parameter(Mandatory,ValueFromPipelineByPropertyName,Position=0)][string]$Name, [Parameter()][string]$DestinationModulePath = "." ) - + process{ $includeRoot = Get-ModuleFolder -FolderName 'Root' @@ -15,28 +15,28 @@ function Copy-IncludeToWorkSpace{ "Source folder is $sourceIncludeModuleFolder" | Write-Verbose $destinationpath = $DestinationModulePath | Join-Path -ChildPath $FolderPath "Destination folder is $destinationpath" | Write-Verbose - + $sourceFile = $sourceIncludeModuleFolder | Join-Path -ChildPath $Name "Source file is $sourceFile" | Write-Verbose $destinationFile = $destinationpath | Join-Path -ChildPath $Name "Destination file is $destinationFile" | Write-Verbose - + # Check if there is a .psd1 file in the DestinationModulePath $psd1File = Get-ChildItem -Path $DestinationModulePath -Filter *.psd1 -ErrorAction SilentlyContinue if (-Not $psd1File) { throw "Destination Path $DestinationModulePath does not seem to be a PowershellMddule." } - + # create destination folder if it does not exist if(-Not (Test-Path $destinationpath)){ $null = New-Item -Path $destinationpath -ItemType Directory -Force } - + # Check if source file exists if(-Not (Test-Path $sourceFile)){ throw "File $sourceFile not found" } - + if ($PSCmdlet.ShouldProcess("$sourceFile", "copy to $destinationFile")) { Copy-Item -Path $sourceFile -Destination $destinationFile -Force } diff --git a/public/listIncludes.ps1 b/public/listIncludes.ps1 index 69d04bc..d60ab72 100644 --- a/public/listIncludes.ps1 +++ b/public/listIncludes.ps1 @@ -42,7 +42,7 @@ function Get-IncludeFile{ #checkif $moduleRootPath is null, whitespace or empty # If value keep value. - # If Local use '.' + # If Local use '.' # If not Localuse includeHelper module if([string]::IsNullOrWhiteSpace($ModuleRootPath)){ $moduleRootPath = $Local ? "." : $(Get-ModuleRootPath) @@ -109,14 +109,14 @@ function Open-IncludeFile{ process{ $sourceIncludeModuleFolder = Get-ModuleFolder -FolderName $FolderName - + $sourceFile = $sourceIncludeModuleFolder | Join-Path -ChildPath $Name - + # Check if source file exists if(-Not (Test-Path $sourceFile)){ throw "File $sourceFile not found" } - + # Open the file using the default application based on the OS if ($IsWindows) { Start-Process $sourceFile diff --git a/public/listSystemFiles.ps1 b/public/listSystemFiles.ps1 index 5d20dd8..2404016 100644 --- a/public/listSystemFiles.ps1 +++ b/public/listSystemFiles.ps1 @@ -35,7 +35,7 @@ function Get-IncludeSystemFiles{ ) $includeItems = @() - + # Get the files from folders that do not know the number of files in them $includeItems += Get-IncludeFile -Folders $systemFolders -Local:$Local diff --git a/public/selectByFolder.ps1 b/public/selectByFolder.ps1 index 5d45f1d..3248094 100644 --- a/public/selectByFolder.ps1 +++ b/public/selectByFolder.ps1 @@ -9,7 +9,7 @@ filter Select-IncludeFileByFolder { [string] $FolderName ) - + # Check if the object has a FolderName property and if it matches the specified value if ($InputObject.FolderName -Like "$FolderName") { $InputObject diff --git a/release.ps1 b/release.ps1 index a97de5f..c014c56 100644 --- a/release.ps1 +++ b/release.ps1 @@ -6,7 +6,7 @@ Create a tag on the repo and a release to that tag on GitHub remote repo. This script works very well with GitHub Actions workflow that run on release creation. - Check the following workflow as an example: + Check the following workflow as an example: https://raw.githubusercontent.com/rulasg/DemoPsModule/main/.github/workflows/deploy_module_on_release.yml @@ -32,8 +32,8 @@ .EXAMPLE .\release.ps1 -VersionTag v10.0.01-alpha -CreateTag -Force - Create tag and create release without confirmation. - + Create tag and create release without confirmation. + .LINK https://raw.githubusercontent.com/rulasg/DemoPsModule/main/release.ps1 #> @@ -61,7 +61,7 @@ if ($CreateTag) { if ($PSCmdlet.ShouldProcess($VersionTag, "gh release create")) { if ($NotPreRelease) { - gh release create $VersionTag --generate-notes --verify-tag --title "Release $VersionTag" + gh release create $VersionTag --generate-notes --verify-tag --title "Release $VersionTag" } else { gh release create $VersionTag --generate-notes --verify-tag --title "Release $VersionTag (PreRelease)" --prerelease diff --git a/sync.ps1 b/sync.ps1 index 09f7fd3..ca51c06 100644 --- a/sync.ps1 +++ b/sync.ps1 @@ -4,7 +4,7 @@ .DESCRIPTION Synchronizes with TestingHelper templates to the local repo. - TestingHelper uses templates to create a new module. + TestingHelper uses templates to create a new module. This script will update the local module with the latest templates. .LINK https://raw.githubusercontent.com/rulasg/TestingHelper/main/sync.ps1 diff --git a/test.ps1 b/test.ps1 index 5695fb2..b1d497a 100644 --- a/test.ps1 +++ b/test.ps1 @@ -72,7 +72,7 @@ function Import-RequiredModule{ ) process{ - # Powershell module manifest does not allow versions with prerelease tags on them. + # Powershell module manifest does not allow versions with prerelease tags on them. # Powershell modle manifest does not allow to add a arbitrary field to specify prerelease versions. # Valid value (ModuleName, ModuleVersion, RequiredVersion, GUID) # There is no way to specify a prerelease required module. diff --git a/tools/deploy.Helper.ps1 b/tools/deploy.Helper.ps1 index 16eeea5..d4e1543 100644 --- a/tools/deploy.Helper.ps1 +++ b/tools/deploy.Helper.ps1 @@ -54,11 +54,11 @@ function Invoke-DeployModuleToPSGallery{ if ($Force -and -not $Confirm){ $ConfirmPreference = 'None' } - + # Deploy the module with ShouldProcess (-whatif, -confirm) if ($PSCmdlet.ShouldProcess($psdPath, "Invoke-DeployModule")) { "Deploying {0} {1} {2} to PSGallery ..." -f $($psd1.RootModule), $($psd1.ModuleVersion), $($psd1.PrivateData.pSData.Prerelease) | Write-Information - # During testing we should use -WhatIf paarmetre when calling for deploy. + # During testing we should use -WhatIf paarmetre when calling for deploy. # Just reach this point when testing call failure Invoke-DeployModule -Name $psdPath -NuGetApiKey $NuGetApiKey -Force:$ForceDeploy } @@ -79,8 +79,8 @@ function Update-DeployModuleManifest { # if ($PSCmdlet.ShouldProcess($parameters.Path, "Update-ModuleManifest with ModuleVersion:{0} Prerelease:{1}" -f $parameters.ModuleVersion, $parameters.Prerelease)) { if ($PSCmdlet.ShouldProcess($parameters.Path, "Update-ModuleManifest with $versionTag")) { "Updating module manifest with version tag [$VersionTag] ..." | Write-Information - Update-ModuleManifest @parameters - + Update-ModuleManifest @parameters + } else { Write-Warning -Message "Update-ModuleManifest skipped. Any PSD1 deploy will not have the proper version." } @@ -92,7 +92,7 @@ function Update-DeployModuleManifest { Write-Error -Message "Failed to update module manifest with version tag [$VersionTag]" exit 1 } -} +} function script:Invoke-DeployModule { [CmdletBinding()] @@ -117,7 +117,7 @@ function script:Invoke-DeployModule { Write-Error -Message "Failed to deploy module [$Name] to PSGallery" exit 1 } -} +} function Get-DeployModuleVersion { [CmdletBinding()] @@ -125,7 +125,7 @@ function Get-DeployModuleVersion { [Parameter(Mandatory=$true)][string]$VersionTag ) - $version = $VersionTag.split('-')[0] + $version = $VersionTag.split('-')[0] #remove all leters from $version $version = $version -replace '[a-zA-Z_]' $version @@ -138,8 +138,8 @@ function Get-DeployModulePreRelease { ) $preRelease = $VersionTag.split('-')[1] - # to clear the preRelease by Update-ModuleManifest - # preRelease must be a string with a space. + # to clear the preRelease by Update-ModuleManifest + # preRelease must be a string with a space. # $null or [string]::Empty leaves the value that has. $preRelease = $preRelease ?? " " $preRelease diff --git a/tools/sync.Helper.ps1 b/tools/sync.Helper.ps1 index d7ea2e1..deb1b6c 100644 --- a/tools/sync.Helper.ps1 +++ b/tools/sync.Helper.ps1 @@ -4,7 +4,7 @@ .DESCRIPTION Helper functions Synchronize TestingHelper templates to the local repo. - TestingHelper uses templates to create a new module. + TestingHelper uses templates to create a new module. This script will update the local module with the latest templates. .LINK https://raw.githubusercontent.com/rulasg/DemoPsModule/main/sync.ps1 From c5ce53d698b8a7b85b4e3115fccdd99ebed7586c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 22 Jan 2026 16:15:02 +0100 Subject: [PATCH 4/7] refactor(tools): enhance script to remove trailing whitespace and empty lines --- tools/remove-trailing-whitespace.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/remove-trailing-whitespace.ps1 b/tools/remove-trailing-whitespace.ps1 index 83dbd85..b4ee8ec 100644 --- a/tools/remove-trailing-whitespace.ps1 +++ b/tools/remove-trailing-whitespace.ps1 @@ -1,7 +1,7 @@ # Script to remove trailing whitespace from PowerShell files # This addresses the PSAvoidTrailingWhitespace rule in PSScriptAnalyzer -Write-Host "Removing trailing whitespace from files..." -ForegroundColor Green +Write-Host "Removing trailing whitespace and trailing empty lines from files..." -ForegroundColor Green # Get all PowerShell files recursively $files = Get-ChildItem -Path . -Include *.ps1, *.psm1, *.psd1 -Recurse @@ -11,9 +11,12 @@ $count = 0 foreach ($file in $files) { $content = Get-Content -Path $file.FullName -Raw - # Replace trailing whitespace with nothing + # Replace trailing whitespace on each line $newContent = $content -replace '[ \t]+\r?\n', "`n" + # Remove trailing empty lines at the end of the file + $newContent = $newContent -replace '(\r?\n)+$', "`n" + # Check if content changed if ($newContent -ne $content) { Set-Content -Path $file.FullName -Value $newContent -NoNewline @@ -22,4 +25,4 @@ foreach ($file in $files) { } } -Write-Host "Done! Fixed trailing whitespace in $count files." -ForegroundColor Green +Write-Host "Done! Fixed trailing whitespace and empty lines in $count files." -ForegroundColor Green From 610e7a6f32ff0fd3672f6c11092a9e29e0cecc03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 22 Jan 2026 16:15:33 +0100 Subject: [PATCH 5/7] style: remove trailing whitespace from multiple files --- IncludeHelper.psd1 | 1 - Test/Test.psd1 | 1 - Test/include/invokeCommand.mock.ps1 | 4 ---- Test/public/config.test.ps1 | 1 - Test/public/listIncludes.test.ps1 | 1 - helper/invokeCommand.helper.ps1 | 1 - include/MyWrite.ps1 | 4 ---- include/callAPI.ps1 | 2 -- include/databaseV2.ps1 | 2 -- tools/deploy.Helper.ps1 | 1 - 10 files changed, 18 deletions(-) diff --git a/IncludeHelper.psd1 b/IncludeHelper.psd1 index 044e68d..bae85da 100644 --- a/IncludeHelper.psd1 +++ b/IncludeHelper.psd1 @@ -129,4 +129,3 @@ PrivateData = @{ # DefaultCommandPrefix = '' } - diff --git a/Test/Test.psd1 b/Test/Test.psd1 index 3f4a44e..0470479 100644 --- a/Test/Test.psd1 +++ b/Test/Test.psd1 @@ -129,4 +129,3 @@ PrivateData = @{ # DefaultCommandPrefix = '' } - diff --git a/Test/include/invokeCommand.mock.ps1 b/Test/include/invokeCommand.mock.ps1 index 0889788..e10e6ca 100644 --- a/Test/include/invokeCommand.mock.ps1 +++ b/Test/include/invokeCommand.mock.ps1 @@ -282,7 +282,3 @@ function Assert-MockFileNotfound{ throw "File not found or wrong case name. Expected[ $filename ] - Found[$( $file.name )]" } } - - - - diff --git a/Test/public/config.test.ps1 b/Test/public/config.test.ps1 index ea7aa42..e36999f 100644 --- a/Test/public/config.test.ps1 +++ b/Test/public/config.test.ps1 @@ -21,4 +21,3 @@ function Test_ConfigInclude{ Assert-AreEqual -Expected $value -Presented $result.TestKey } - diff --git a/Test/public/listIncludes.test.ps1 b/Test/public/listIncludes.test.ps1 index 56cafe9..d5378e4 100644 --- a/Test/public/listIncludes.test.ps1 +++ b/Test/public/listIncludes.test.ps1 @@ -84,4 +84,3 @@ function Assert-IncludeFile{ Assert-Count -Expected 1 -Presented $item Assert-AreEqual -Expected $FolderName -Presented $item.FolderName -Comment "Include File $Name should be in folder $FolderName" } - diff --git a/helper/invokeCommand.helper.ps1 b/helper/invokeCommand.helper.ps1 index e71eb58..5a08f46 100644 --- a/helper/invokeCommand.helper.ps1 +++ b/helper/invokeCommand.helper.ps1 @@ -47,4 +47,3 @@ function Reset-MyInvokeCommandAlias{ # Reset all aliases for this module on each refresh Reset-MyInvokeCommandAlias - diff --git a/include/MyWrite.ps1 b/include/MyWrite.ps1 index 7c4e8bd..7e8ffbb 100644 --- a/include/MyWrite.ps1 +++ b/include/MyWrite.ps1 @@ -203,7 +203,3 @@ function Get-ObjetString { return $Object | ConvertTo-Json -Depth 10 -ErrorAction SilentlyContinue } } - - - - diff --git a/include/callAPI.ps1 b/include/callAPI.ps1 index 8e96b37..f99c1e7 100644 --- a/include/callAPI.ps1 +++ b/include/callAPI.ps1 @@ -232,5 +232,3 @@ function writedebug{ Write-MyDebug $Message -Section "api" } } - - diff --git a/include/databaseV2.ps1 b/include/databaseV2.ps1 index 1141f95..c6a34b1 100644 --- a/include/databaseV2.ps1 +++ b/include/databaseV2.ps1 @@ -169,5 +169,3 @@ function Test-DatabaseKey{ return $true } - - diff --git a/tools/deploy.Helper.ps1 b/tools/deploy.Helper.ps1 index d4e1543..3b27ab3 100644 --- a/tools/deploy.Helper.ps1 +++ b/tools/deploy.Helper.ps1 @@ -144,4 +144,3 @@ function Get-DeployModulePreRelease { $preRelease = $preRelease ?? " " $preRelease } - From db4fc3b3f0c780ef824791b22c2c26b785e986ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 22 Jan 2026 20:34:58 +0100 Subject: [PATCH 6/7] style: remove trailing whitespace from multiple scripts --- .../public/Remove-TailSpacesAndLines.test.ps1 | 165 ++++++++++++++++++ tools/Test_Helper/Test_Helper.psd1 | 131 ++++++++++++++ tools/Test_Helper/Test_Helper.psm1 | 26 +++ .../public/Remove-TailSpacesAndLines.ps1 | 52 ++++++ tools/remove-trailing-whitespace.ps1 | 28 --- 5 files changed, 374 insertions(+), 28 deletions(-) create mode 100644 Test/public/tools/Test_Helper/public/Remove-TailSpacesAndLines.test.ps1 create mode 100644 tools/Test_Helper/Test_Helper.psd1 create mode 100644 tools/Test_Helper/Test_Helper.psm1 create mode 100644 tools/Test_Helper/public/Remove-TailSpacesAndLines.ps1 delete mode 100644 tools/remove-trailing-whitespace.ps1 diff --git a/Test/public/tools/Test_Helper/public/Remove-TailSpacesAndLines.test.ps1 b/Test/public/tools/Test_Helper/public/Remove-TailSpacesAndLines.test.ps1 new file mode 100644 index 0000000..d42f283 --- /dev/null +++ b/Test/public/tools/Test_Helper/public/Remove-TailSpacesAndLines.test.ps1 @@ -0,0 +1,165 @@ +function Test_RemoveTrailingWhitespace { + + Import-Test_Helper + + $Expected = @" + + Line with spaces + + Line with tabs + +Line with no trailing spaces +"@ + + $content = @" + + Line with spaces + + Line with tabs + +Line with no trailing spaces + + + +"@ + + $presentedFile = New-TestingFile -Content $content -PassThru + $expectedFile = New-TestingFile -Content $Expected -PassThru + + # Act + $result = Remove-TailSpacesAndLines -Path $presentedFile.FullName + + # Assert + Assert-AreEqualPath $presentedFile.FullName $result + + Assert-AreEqualFiles $expectedFile.FullName $result + +} + +function Test_RemoveTrailingWhitespace_Manyfiles { + + Import-Test_Helper + + + $contentDirty = " + Line with spaces + Line with tabs + + +" + $contentClean = " + Line with spaces + + Line with tabs +" + New-TestingFile -Content $contentDirty -Name dirty1.txt + New-TestingFile -Content $contentDirty -Name dirty2.txt + New-TestingFile -Content $contentDirty -Name dirty3.txt + New-TestingFile -Content $contentClean -Name clean1.txt + New-TestingFile -Content $contentClean -Name clean2.txt + + # Act + $files = Get-ChildItem + $result = $files | Remove-TailSpacesAndLines + + # Assert + Assert-Count -Expected 3 -Presented $result + +} + +function Test_RemoveTrailingWhitespace_NoPath { + + Import-Test_Helper + + + $contentDirty = " + Line with spaces + Line with tabs + + +" + $contentClean = " + Line with spaces + + Line with tabs +" + New-TestingFile -Content $contentDirty -Name dirty1.txt + New-TestingFile -Content $contentDirty -Name dirty2.txt + New-TestingFile -Content $contentDirty -Name dirty3.txt + New-TestingFile -Content $contentDirty -Name dirty4.txt -Path kk1 + New-TestingFile -Content $contentClean -Name clean1.txt + New-TestingFile -Content $contentClean -Name clean2.txt + New-TestingFile -Content $contentClean -Name clean3.txt -Path kk2 + + # Act + $result = Remove-TailSpacesAndLines + + # Assert + Assert-Count -Expected 3 -Presented $result + +} + +function Test_RemoveTrailingWhitespace_NoPath_Recursive { + + Import-Test_Helper + + + $contentDirty = " + Line with spaces + Line with tabs + + +" + $contentClean = " + Line with spaces + + Line with tabs +" + New-TestingFile -Content $contentDirty -Name dirty1.txt -Path kk1 + New-TestingFile -Content $contentDirty -Name dirty2.txt + New-TestingFile -Content $contentDirty -Name dirty3.txt -Path kk2/subkk + New-TestingFile -Content $contentClean -Name clean1.txt + New-TestingFile -Content $contentClean -Name clean2.txt + + # Act + $result = Remove-TailSpacesAndLines -Recurse + + # Assert + Assert-Count -Expected 3 -Presented $result + +} + +function Import-Test_Helper{ + + $modulepath = Get-ModuleRootPath + $testhelpermodulepath = $modulepath | Join-Path -ChildPath "tools" -AdditionalChildPath "Test_Helper" + Import-Module $testhelpermodulepath -Force +} + +function Assert-AreEqualFiles { + param ( + [Parameter(Mandatory, Position = 0)][string] $Expected, + [Parameter(Mandatory, Position = 1)][string] $Presented + ) + + process { + $content1 = Get-Content -Path $Expected + $content2 = Get-Content -Path $Presented + + + if($content1.Count -ne $content2.Count) { + Write-Error "Files have different number of lines" + return $false + } + + foreach($i in 0..($content1.Count - 1)) { + if($content1[$i] -ne $content2[$i]) { + Write-Error "Files differ at line $($i + 1)" + return $false + } + } + + return $true + + } +} diff --git a/tools/Test_Helper/Test_Helper.psd1 b/tools/Test_Helper/Test_Helper.psd1 new file mode 100644 index 0000000..76dad7f --- /dev/null +++ b/tools/Test_Helper/Test_Helper.psd1 @@ -0,0 +1,131 @@ +# +# Module manifest for module 'Test_Helper' +# +# Generated by: rulasg +# +# Generated on: 20/1/2026 +# + +@{ + +# Script module or binary module file associated with this manifest. +RootModule = 'Test_Helper.psm1' + +# Version number of this module. +ModuleVersion = '0.0.1' + +# Supported PSEditions +# CompatiblePSEditions = @() + +# ID used to uniquely identify this module +GUID = '0be904b3-72c4-4e02-882a-153fa558e074' + +# Author of this module +Author = 'rulasg' + +# Company or vendor of this module +CompanyName = 'Unknown' + +# Copyright statement for this module +Copyright = '(c) rulasg. All rights reserved.' + +# Description of the functionality provided by this module +# Description = '' + +# Minimum version of the PowerShell engine required by this module +# PowerShellVersion = '' + +# Name of the PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# ClrVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +# RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = '*' + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = '*' + +# Variables to export from this module +VariablesToExport = '*' + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = '*' + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + # Prerelease string of this module + Prerelease = 'dev' + + # Flag to indicate whether the module requires explicit user acceptance for install/update/save + # RequireLicenseAcceptance = $false + + # External dependent modules of this module + # ExternalModuleDependencies = @() + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +} diff --git a/tools/Test_Helper/Test_Helper.psm1 b/tools/Test_Helper/Test_Helper.psm1 new file mode 100644 index 0000000..2a22cac --- /dev/null +++ b/tools/Test_Helper/Test_Helper.psm1 @@ -0,0 +1,26 @@ +Write-Information -Message ("Loading {0} ..." -f ($PSCommandPath | Split-Path -LeafBase)) -InformationAction continue + +#Module path is where resides the RootModule file. This file. :) +$MODULE_PATH = $PSScriptRoot + +#Get public and private function definition files. +$Public = @( Get-ChildItem -Path $MODULE_PATH\public\*.ps1 -ErrorAction SilentlyContinue ) +$Private = @( Get-ChildItem -Path $MODULE_PATH\private\*.ps1 -ErrorAction SilentlyContinue ) + +#Dot source the files +Foreach($import in @($Public + $Private)) +{ + Try + { + . $import.fullname + } + Catch + { + Write-Error -Message "Failed to import function $($import.fullname): $_" + } +} + +# Here I might... +# Read in or create an initial config file and variable +# Export Public functions ($Public.BaseName) for WIP modules +# Set variables visible to the module and its functions only diff --git a/tools/Test_Helper/public/Remove-TailSpacesAndLines.ps1 b/tools/Test_Helper/public/Remove-TailSpacesAndLines.ps1 new file mode 100644 index 0000000..880382e --- /dev/null +++ b/tools/Test_Helper/public/Remove-TailSpacesAndLines.ps1 @@ -0,0 +1,52 @@ +function Remove-TailSpacesAndLines { + param ( + [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] + [string[]] $Path = '.', + [Parameter()][switch] $Recurse + ) + + process { + + $files = Get-ChildItem -Path $Path -File -force -Recurse:$Recurse -Include *.ps1, *.psm1, *.psd1, *.json, *.yml, *.yaml, *.md, *.txt, *.xml + + # Remove .git content (exact .git folder only, not .github) + $files = $files | Where-Object { $_.FullName -notmatch '(^|[\\/])\.git[\\/]' } + + foreach ($file in $files) { + + Write-Verbose "Processing file: $($file.FullName)" + + $dirty = $false + + $content = Get-Content -Path $file.FullName + $newContent = @() + + # Trim each line + foreach ($line in $content) { + + if([string]::IsNullOrWhiteSpace($line)) { + $newLine = "" + } else { + $newLine = $line.TrimEnd() + } + + $newContent += $newLine + + if($newLine -ne $line) { + $dirty = $true + } + } + + # Remove trailing empty lines + while (($newContent.count -ne 0) -and ([string]::IsNullOrWhiteSpace($newContent[-1]))) { + $newContent = $newContent[0..($newContent.Count - 2)] + $dirty = $true + } + + if($dirty) { + Set-Content -Path $file.FullName -Value $newContent + Write-Output $file.FullName + } + } + } +} diff --git a/tools/remove-trailing-whitespace.ps1 b/tools/remove-trailing-whitespace.ps1 deleted file mode 100644 index b4ee8ec..0000000 --- a/tools/remove-trailing-whitespace.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -# Script to remove trailing whitespace from PowerShell files -# This addresses the PSAvoidTrailingWhitespace rule in PSScriptAnalyzer - -Write-Host "Removing trailing whitespace and trailing empty lines from files..." -ForegroundColor Green - -# Get all PowerShell files recursively -$files = Get-ChildItem -Path . -Include *.ps1, *.psm1, *.psd1 -Recurse - -$count = 0 - -foreach ($file in $files) { - $content = Get-Content -Path $file.FullName -Raw - - # Replace trailing whitespace on each line - $newContent = $content -replace '[ \t]+\r?\n', "`n" - - # Remove trailing empty lines at the end of the file - $newContent = $newContent -replace '(\r?\n)+$', "`n" - - # Check if content changed - if ($newContent -ne $content) { - Set-Content -Path $file.FullName -Value $newContent -NoNewline - $count++ - Write-Host "Fixed: $($file.FullName)" - } -} - -Write-Host "Done! Fixed trailing whitespace and empty lines in $count files." -ForegroundColor Green From 5c00b89938389a07851d48b856786b1ac9ffe605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Thu, 22 Jan 2026 20:35:22 +0100 Subject: [PATCH 7/7] style: remove trailing whitespace and empty lines in multiple files --- .devcontainer/devcontainer.json | 6 +++--- .github/copilot-instructions.md | 6 +++--- .../copilot-pull-request-description-instructions.md | 4 +--- .github/workflows/deploy_module_on_release.yml | 2 +- .github/workflows/powershell.yml | 10 +++++----- .github/workflows/test_with_TestingHelper.yml | 6 +++--- .vscode/launch.json | 2 +- 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2d0e0e5..db52110 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ "name": "PowerShell", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile "image": "mcr.microsoft.com/powershell:lts-ubuntu-22.04", - + "features": { "ghcr.io/devcontainers/features/common-utils:2": {}, "ghcr.io/devcontainers/features/sshd:1": {}, @@ -20,10 +20,10 @@ // Configure properties specific to VS Code. "vscode": { // Set *default* container specific settings.json values on container create. - "settings": { + "settings": { "terminal.integrated.defaultProfile.linux": "pwsh" }, - + // Add the IDs of extensions you want installed when the container is created. "extensions": [ "ms-vscode.powershell", diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 2e0c7b4..b679dd4 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -53,10 +53,10 @@ function Test_AddIncludeToWorkspace { # Arrange - Setup test data and mocks Import-Module -Name TestingHelper New-ModuleV3 -Name TestModule - + # Act - Execute the function being tested Add-IncludeToWorkspace -Name "getHashCode.ps1" -FolderName "Include" -DestinationModulePath "TestModule" - + # Assert - Verify results Assert-ItemExist -path (Join-Path $folderPath "getHashCode.ps1") } @@ -81,4 +81,4 @@ function Test_AddIncludeToWorkspace { - `./test.ps1` - Run all unit tests - `./sync.ps1` - Sync includes to workspace/module - `./deploy.ps1` - Deploy module -- `./release.ps1` - Release module version \ No newline at end of file +- `./release.ps1` - Release module version diff --git a/.github/copilot-pull-request-description-instructions.md b/.github/copilot-pull-request-description-instructions.md index 78661ee..b871512 100644 --- a/.github/copilot-pull-request-description-instructions.md +++ b/.github/copilot-pull-request-description-instructions.md @@ -1,6 +1,6 @@ # Pull Request Code Instructions -## PR TITLE +## PR TITLE Follow this guidelines to construct the title of your pull request. @@ -39,5 +39,3 @@ References: - Add a summery of the intention of the PR. Use the title and the messages of the commits to create a summary. - Add a list with all the commit messages in the PR. - - diff --git a/.github/workflows/deploy_module_on_release.yml b/.github/workflows/deploy_module_on_release.yml index e73346b..70da980 100644 --- a/.github/workflows/deploy_module_on_release.yml +++ b/.github/workflows/deploy_module_on_release.yml @@ -26,7 +26,7 @@ jobs: EVENT_REF: ${{ github.event.ref }} RELEASE_TAG: ${{ github.event.release.tag_name }} RELEASE_NAME: ${{ github.event.release.name }} - run: | + run: | $env:EVENT_REF = $env:REF If ([string]::IsNullOrEmpty($env:EVENT_REF)) { diff --git a/.github/workflows/powershell.yml b/.github/workflows/powershell.yml index 419192b..bae227e 100644 --- a/.github/workflows/powershell.yml +++ b/.github/workflows/powershell.yml @@ -12,7 +12,7 @@ name: PSScriptAnalyzer on: workflow_dispatch: pull_request: - + permissions: contents: read @@ -21,7 +21,7 @@ jobs: permissions: contents: read # for actions/checkout to fetch code security-events: write # for github/codeql-action/upload-sarif to upload SARIF results - actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status name: PSScriptAnalyzer runs-on: ubuntu-latest steps: @@ -33,12 +33,12 @@ jobs: # Check https://github.com/microsoft/action-psscriptanalyzer for more info about the options. # The below set up runs PSScriptAnalyzer to your entire repository and runs some basic security rules. path: .\ - recurse: true + recurse: true severity: 'Error' - # Include your own basic security rules. Removing this option will run all the rules + # Include your own basic security rules. Removing this option will run all the rules # includeRule: '"PSAvoidGlobalAliases", "PSAvoidUsingConvertToSecureStringWithPlainText"' output: results.sarif - + # Upload the SARIF file generated in the previous step - name: Upload SARIF results file uses: github/codeql-action/upload-sarif@v3 diff --git a/.github/workflows/test_with_TestingHelper.yml b/.github/workflows/test_with_TestingHelper.yml index d08b89d..8039700 100644 --- a/.github/workflows/test_with_TestingHelper.yml +++ b/.github/workflows/test_with_TestingHelper.yml @@ -31,7 +31,7 @@ jobs: # Runs a single command using the runners shell - name: Run test.ps1 shell: pwsh - run: | + run: | $result = ./test.ps1 -ShowTestErrors $result @@ -40,6 +40,6 @@ jobs: # $passed = $result.Tests -eq $result.Pass if($passed) - { "All test passed" | Write-Verbose -verbose ; exit 0 } - else + { "All test passed" | Write-Verbose -verbose ; exit 0 } + else { "Not all tests passed" | Write-Verbose -verbose ; exit 1 } diff --git a/.vscode/launch.json b/.vscode/launch.json index 668bddc..8f78fe0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,7 +4,7 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // // Module V2 - https://raw.githubusercontent.com/rulasg/DemoPsModule/main/.vscode/launch.json - + "version": "0.2.0", "configurations": [ {