Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

WIP: localdev publishing #462

Merged
merged 2 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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,
}
}
]
}
46 changes: 33 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>B</kbd>

### 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 `<branch>/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
```

Expand Down
Binary file added imgs/readme-getmodule-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 36 additions & 2 deletions tools/build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down