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

Commit 459695a

Browse files
Benny1007edyoung
authored andcommitted
WIP: localdev publishing (#462)
* facilitate easier local development * update readme file
1 parent 483dada commit 459695a

File tree

4 files changed

+166
-15
lines changed

4 files changed

+166
-15
lines changed

.vscode/tasks.json

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "Build and Import Module",
8+
"command": "pwsh",
9+
"type": "shell",
10+
"windows": {
11+
"command": "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
12+
},
13+
"args": [
14+
"-command",
15+
"Import-Module ${workspaceFolder}\\tools\\build.psm1;",
16+
"Install-DevelopmentModule",
17+
],
18+
"problemMatcher": [],
19+
"group": {
20+
"kind": "build",
21+
"isDefault": true
22+
},
23+
"presentation": {
24+
"echo": true,
25+
"reveal": "always",
26+
"focus": true,
27+
"panel": "shared",
28+
"showReuseMessage": true,
29+
"clear": false,
30+
}
31+
},
32+
{
33+
"label": "Install Dependencies",
34+
"command": "pwsh",
35+
"windows": {
36+
"command": "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
37+
},
38+
"args": [
39+
"-command",
40+
"Import-Module ${workspaceFolder}\\tools\\build.psm1;",
41+
"Install-Dependencies"
42+
],
43+
"problemMatcher": [],
44+
"presentation": {
45+
"echo": true,
46+
"reveal": "always",
47+
"focus": true,
48+
"panel": "shared",
49+
"showReuseMessage": true,
50+
"clear": false,
51+
}
52+
},
53+
{
54+
"label": "Remove Development Module",
55+
"command": "pwsh",
56+
"windows": {
57+
"command": "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
58+
},
59+
"args": [
60+
"-command",
61+
"Import-Module ${workspaceFolder}\\tools\\build.psm1;",
62+
"Uninstall-DevelopmentModule"
63+
],
64+
"problemMatcher": [],
65+
"presentation": {
66+
"echo": true,
67+
"reveal": "always",
68+
"focus": true,
69+
"panel": "shared",
70+
"showReuseMessage": true,
71+
"clear": false,
72+
}
73+
},
74+
{
75+
"label": "Run Full Test Suite",
76+
"command": "pwsh",
77+
"windows": {
78+
"command": "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
79+
},
80+
"args": [
81+
"-command",
82+
"Import-Module ${workspaceFolder}\\tools\\build.psm1;",
83+
"Install-Dependencies;",
84+
"Invoke-PowerShellGetTest"
85+
],
86+
"problemMatcher": [],
87+
"presentation": {
88+
"echo": true,
89+
"reveal": "always",
90+
"focus": true,
91+
"panel": "shared",
92+
"showReuseMessage": true,
93+
"clear": false,
94+
}
95+
}
96+
]
97+
}

README.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,29 +106,49 @@ Import-Module src/PowerShellGet
106106
```
107107

108108

109+
Local Development
110+
=================
111+
### Visual Studio Code:-
112+
1. Open VSCode choosing "Run as Administrator"
113+
2. Select Terminal>Run Task>Install Dependencies
114+
3. Select Terminal>Run Task>Build and Import Module
115+
116+
for subsequent changes you can just run 'Build and Import Module' or press <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>B</kbd>
117+
118+
### Standard PowerShell:-
119+
1. Open an administrative PowerShell prompt
120+
2. Run the following commands
121+
```PowerShell
122+
Import-Module "$ClonePath\tools\build.psm1"
123+
Install-Dependencies
124+
Install-DevelopmentModule
125+
```
126+
127+
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.
128+
129+
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.
130+
131+
It is therefore easy to see with ```Get Module``` that the version under development is loaded, like this:-
132+
133+
![alt text](./imgs/readme-getmodule-1.png "")
134+
135+
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).
136+
109137
Running Tests
110138
=============
111139

140+
### VSCode
141+
You can run the test task Terminal>Run Task>Run Full Test Suite
142+
143+
### Non VSCode
144+
112145
Pester-based PowerShellGet Tests are located in `<branch>/PowerShellGet/Tests` folder.
113146

114147
Run following commands in PowerShell Console with Administrator privileges.
115148

116149
```powershell
117150
Import-Module "$ClonePath\tools\build.psm1"
118-
119151
Install-Dependencies
120-
121-
# Option 1: Execute the following, replacing $ClonePath, when testing PowerShellGet module changes under $ClonePath.
122-
# $env:PSModulePath = "$ClonePath\src;$env:PSModulePath"
123-
124-
# Option 2: Execute the following commands to run tests with the merged PSModule.psm1
125-
<#
126-
Update-ModuleManifestFunctions
127-
Publish-ModuleArtifacts
128-
Install-PublishedModule
129-
#>
130-
131-
# Run tests
132152
Invoke-PowerShellGetTest
133153
```
134154

imgs/readme-getmodule-1.png

42 KB
Loading

tools/build.psm1

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function Install-PackageManagement {
131131

132132
$null = Microsoft.PowerShell.Management\New-Item -Path $OneGetModulePath -Force -ItemType Directory
133133
Microsoft.PowerShell.Management\Copy-Item -Path "$($OneGetWithVersion.FullName)\*" -Destination "$OneGetModulePath\" -Recurse -Force
134-
Get-Module -ListAvailable -Name $OneGetModuleName | Microsoft.PowerShell.Core\Where-Object {$_.Version -eq $OneGetVersion}
134+
Get-Module -ListAvailable -Name $OneGetModuleName | Microsoft.PowerShell.Core\Where-Object { $_.Version -eq $OneGetVersion }
135135
}
136136
finally {
137137
Remove-Item -Path $TempModulePath -Recurse -Force
@@ -425,11 +425,25 @@ function Publish-ModuleArtifacts {
425425
}
426426
function Install-PublishedModule {
427427
# function to install the merged module artifact from /dist into the module path.
428+
Param (
429+
[switch]$LocalDevInstall
430+
)
431+
428432
$moduleFolder = Join-Path -Path $ArtifactRoot -ChildPath 'PowerShellGet'
429-
$PowerShellGetModuleInfo = Test-ModuleManifest "$moduleFolder\PowerShellGet.psd1" -ErrorAction Ignore
433+
$manifestFullName = Join-Path -Path $moduleFolder -ChildPath "PowerShellGet.psd1" -ErrorAction Ignore
434+
$PowerShellGetModuleInfo = Test-ModuleManifest $manifestFullName
430435
$ModuleVersion = "$($PowerShellGetModuleInfo.Version)"
431436
$InstallLocation = Join-Path -Path $AllUsersModulesPath -ChildPath 'PowerShellGet'
432437

438+
if ($LocalDevInstall) {
439+
Write-Verbose -Message "Local dev installation specified."
440+
$versionUnderDevelopment = "$ModuleVersion.9999"
441+
$rawManifest = Get-Content -Path $manifestFullName -Raw
442+
$newContent = $rawManifest -replace " ModuleVersion = '$ModuleVersion'", " ModuleVersion = '$versionUnderDevelopment'"
443+
Set-Content -Path $manifestFullName -Value $newContent
444+
$ModuleVersion = $versionUnderDevelopment
445+
}
446+
433447
if (($script:PowerShellEdition -eq 'Core') -or ($PSVersionTable.PSVersion -ge '5.0.0')) {
434448
$InstallLocation = Join-Path -Path $InstallLocation -ChildPath $ModuleVersion
435449
}
@@ -439,6 +453,26 @@ function Install-PublishedModule {
439453
Write-Verbose -Message "Copied module artifacts from $moduleFolder merged module artifact to`n$InstallLocation"
440454
}
441455

456+
function Install-DevelopmentModule {
457+
Update-ModuleManifestFunctions
458+
Publish-ModuleArtifacts
459+
Install-PublishedModule -LocalDevInstall
460+
}
461+
462+
function Uninstall-DevelopmentModule {
463+
$manifestFullName = Join-Path -Path $ModuleRoot -ChildPath "PowerShellGet.psd1" -ErrorAction Ignore
464+
$PowerShellGetModuleInfo = Test-ModuleManifest $manifestFullName
465+
$ModuleVersion = "$($PowerShellGetModuleInfo.Version)"
466+
$InstallLocation = Join-Path -Path $AllUsersModulesPath -ChildPath 'PowerShellGet'
467+
$versionUnderDevelopment = "$ModuleVersion.9999"
468+
469+
if (($script:PowerShellEdition -eq 'Core') -or ($PSVersionTable.PSVersion -ge '5.0.0')) {
470+
$InstallLocation = Join-Path -Path $InstallLocation -ChildPath $versionUnderDevelopment
471+
Remove-Item $InstallLocation -Recurse -Force
472+
}
473+
474+
}
475+
442476
<#
443477
.SYNOPSIS
444478
This function changes the folder location in the current session to

0 commit comments

Comments
 (0)