diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..3f54a1ce --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,97 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Build and Import Module", + "command": "pwsh", + "type": "shell", + "windows": { + "command": "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" + }, + "args": [ + "-command", + "Import-Module ${workspaceFolder}\\tools\\build.psm1;", + "Install-DevelopmentModule", + ], + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": false, + } + }, + { + "label": "Install Dependencies", + "command": "pwsh", + "windows": { + "command": "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" + }, + "args": [ + "-command", + "Import-Module ${workspaceFolder}\\tools\\build.psm1;", + "Install-Dependencies" + ], + "problemMatcher": [], + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": false, + } + }, + { + "label": "Remove Development Module", + "command": "pwsh", + "windows": { + "command": "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" + }, + "args": [ + "-command", + "Import-Module ${workspaceFolder}\\tools\\build.psm1;", + "Uninstall-DevelopmentModule" + ], + "problemMatcher": [], + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": false, + } + }, + { + "label": "Run Full Test Suite", + "command": "pwsh", + "windows": { + "command": "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe" + }, + "args": [ + "-command", + "Import-Module ${workspaceFolder}\\tools\\build.psm1;", + "Install-Dependencies;", + "Invoke-PowerShellGetTest" + ], + "problemMatcher": [], + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": false, + } + } + ] +} diff --git a/README.md b/README.md index 0f945216..72914752 100644 --- a/README.md +++ b/README.md @@ -106,29 +106,49 @@ Import-Module src/PowerShellGet ``` +Local Development +================= +### Visual Studio Code:- +1. Open VSCode choosing "Run as Administrator" +2. Select Terminal>Run Task>Install Dependencies +3. Select Terminal>Run Task>Build and Import Module + +for subsequent changes you can just run 'Build and Import Module' or press ctrl + shift + B + +### Standard PowerShell:- +1. Open an administrative PowerShell prompt +2. Run the following commands +```PowerShell +Import-Module "$ClonePath\tools\build.psm1" +Install-Dependencies +Install-DevelopmentModule +``` + +This will take the published module from ./dist and install it into the powershell module path under the current version of PowerShellGet apending 9999 to the version number. + +An explicit or implicit (such as when the test suite is invoked) import of the PowerShell get module will ensure the module version under development gets loaded. + +It is therefore easy to see with ```Get Module``` that the version under development is loaded, like this:- + +![alt text](./imgs/readme-getmodule-1.png "") + +To remove this module and revert to the production PowerShellGallery published version, simply remove the folder from the module path. (if running VSCode select Terminal>Run Task>Remove Development Module). + Running Tests ============= +### VSCode +You can run the test task Terminal>Run Task>Run Full Test Suite + +### Non VSCode + Pester-based PowerShellGet Tests are located in `/PowerShellGet/Tests` folder. Run following commands in PowerShell Console with Administrator privileges. ```powershell Import-Module "$ClonePath\tools\build.psm1" - Install-Dependencies - -# Option 1: Execute the following, replacing $ClonePath, when testing PowerShellGet module changes under $ClonePath. -# $env:PSModulePath = "$ClonePath\src;$env:PSModulePath" - -# Option 2: Execute the following commands to run tests with the merged PSModule.psm1 -<# -Update-ModuleManifestFunctions -Publish-ModuleArtifacts -Install-PublishedModule -#> - -# Run tests Invoke-PowerShellGetTest ``` diff --git a/imgs/readme-getmodule-1.png b/imgs/readme-getmodule-1.png new file mode 100644 index 00000000..bc2718b8 Binary files /dev/null and b/imgs/readme-getmodule-1.png differ diff --git a/tools/build.psm1 b/tools/build.psm1 index f9fdb897..19369c98 100644 --- a/tools/build.psm1 +++ b/tools/build.psm1 @@ -131,7 +131,7 @@ function Install-PackageManagement { $null = Microsoft.PowerShell.Management\New-Item -Path $OneGetModulePath -Force -ItemType Directory Microsoft.PowerShell.Management\Copy-Item -Path "$($OneGetWithVersion.FullName)\*" -Destination "$OneGetModulePath\" -Recurse -Force - Get-Module -ListAvailable -Name $OneGetModuleName | Microsoft.PowerShell.Core\Where-Object {$_.Version -eq $OneGetVersion} + Get-Module -ListAvailable -Name $OneGetModuleName | Microsoft.PowerShell.Core\Where-Object { $_.Version -eq $OneGetVersion } } finally { Remove-Item -Path $TempModulePath -Recurse -Force @@ -425,11 +425,25 @@ function Publish-ModuleArtifacts { } function Install-PublishedModule { # function to install the merged module artifact from /dist into the module path. + Param ( + [switch]$LocalDevInstall + ) + $moduleFolder = Join-Path -Path $ArtifactRoot -ChildPath 'PowerShellGet' - $PowerShellGetModuleInfo = Test-ModuleManifest "$moduleFolder\PowerShellGet.psd1" -ErrorAction Ignore + $manifestFullName = Join-Path -Path $moduleFolder -ChildPath "PowerShellGet.psd1" -ErrorAction Ignore + $PowerShellGetModuleInfo = Test-ModuleManifest $manifestFullName $ModuleVersion = "$($PowerShellGetModuleInfo.Version)" $InstallLocation = Join-Path -Path $AllUsersModulesPath -ChildPath 'PowerShellGet' + if ($LocalDevInstall) { + Write-Verbose -Message "Local dev installation specified." + $versionUnderDevelopment = "$ModuleVersion.9999" + $rawManifest = Get-Content -Path $manifestFullName -Raw + $newContent = $rawManifest -replace " ModuleVersion = '$ModuleVersion'", " ModuleVersion = '$versionUnderDevelopment'" + Set-Content -Path $manifestFullName -Value $newContent + $ModuleVersion = $versionUnderDevelopment + } + if (($script:PowerShellEdition -eq 'Core') -or ($PSVersionTable.PSVersion -ge '5.0.0')) { $InstallLocation = Join-Path -Path $InstallLocation -ChildPath $ModuleVersion } @@ -439,6 +453,26 @@ function Install-PublishedModule { Write-Verbose -Message "Copied module artifacts from $moduleFolder merged module artifact to`n$InstallLocation" } +function Install-DevelopmentModule { + Update-ModuleManifestFunctions + Publish-ModuleArtifacts + Install-PublishedModule -LocalDevInstall +} + +function Uninstall-DevelopmentModule { + $manifestFullName = Join-Path -Path $ModuleRoot -ChildPath "PowerShellGet.psd1" -ErrorAction Ignore + $PowerShellGetModuleInfo = Test-ModuleManifest $manifestFullName + $ModuleVersion = "$($PowerShellGetModuleInfo.Version)" + $InstallLocation = Join-Path -Path $AllUsersModulesPath -ChildPath 'PowerShellGet' + $versionUnderDevelopment = "$ModuleVersion.9999" + + if (($script:PowerShellEdition -eq 'Core') -or ($PSVersionTable.PSVersion -ge '5.0.0')) { + $InstallLocation = Join-Path -Path $InstallLocation -ChildPath $versionUnderDevelopment + Remove-Item $InstallLocation -Recurse -Force + } + +} + <# .SYNOPSIS This function changes the folder location in the current session to