Skip to content

Commit 223dd34

Browse files
committed
Merge pull request #58 from cbadke/Chocolatey
Chocolatey Packaging
2 parents 931defe + a9f0e0a commit 223dd34

File tree

8 files changed

+194
-0
lines changed

8 files changed

+194
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@ Generated_Code #added for RIA/Silverlight projects
107107
_UpgradeReport_Files/
108108
Backup*/
109109
UpgradeLog*.XML
110+
111+
#Chocolatey Build Output
112+
ChocolateyPackage/PSReadLine/
113+
*.nupkg

ChocolateyPackage/PSReadline.nuspec

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<package>
3+
<metadata>
4+
<id>PSReadline</id>
5+
<version></version>
6+
<authors>Jason Shirk</authors>
7+
<owners>Jason Shirk</owners>
8+
<projectUrl>https://github.com/lzybkr/PSReadLine</projectUrl>
9+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
10+
<licenseUrl>https://raw.github.com/lzybkr/PSReadLine/master/License.txt</licenseUrl>
11+
<summary>A bash inspired readline implementation for PowerShell</summary>
12+
<description>Once installed you will likely want to change your profile.ps1 to automatically load the PSReadLine module. Please refer to the project website for instructions. Note that to upgrade or uninstall you will likely need to close all instances of PowerShell and uninstall from cmd.exe. This package installs as a global module accessible by all users.</description>
13+
<releaseNotes>https://raw.github.com/lzybkr/PSReadLine/master/Changes.txt</releaseNotes>
14+
<copyright></copyright>
15+
<tags>Powershell PS Script</tags>
16+
<dependencies>
17+
</dependencies>
18+
</metadata>
19+
<files>
20+
<file src="tools\**" target="tools" />
21+
<file src="PSReadline\**" target="PSReadline" />
22+
</files>
23+
</package>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
param(
2+
[Parameter(Mandatory=$TRUE)]
3+
[String] $PathToModuleFiles,
4+
[Parameter(Mandatory=$TRUE)]
5+
[String] $ModuleName
6+
)
7+
8+
$ErrorActionPreference = "Stop"
9+
10+
if (!(Test-Path -PathType Container $PathToModuleFiles)) {
11+
Write-Error "$PathToModuleFiles not found or is not a directory. Nothing to install."
12+
exit
13+
}
14+
15+
$moduleRoot = "$($env:CommonProgramW6432)\Modules\"
16+
$dest = "$moduleRoot\$ModuleName\"
17+
18+
if (!(Test-Path $moduleRoot)) {
19+
New-Item -ItemType directory $moduleRoot | out-null
20+
}
21+
22+
Write-Host -NoNewLine "Copying $ModuleName module to $moduleRoot... "
23+
24+
Copy-Item -Force -Recurse $PathToModuleFiles $dest
25+
26+
Write-Host -ForegroundColor Green "done"
27+
28+
#Update PSModulePath if it needs it
29+
$path = [Environment]::GetEnvironmentVariable("PSModulePath")
30+
31+
$pathContainsRoot = 0 -ne ($path.Split(';') | ? { Test-Path $_ } | ? { (Resolve-Path $_).Path -eq (Resolve-Path $moduleRoot).Path}).count
32+
33+
if(-Not $pathContainsRoot) {
34+
35+
Write-Host -NoNewLine "Adding $moduleRoot to `$env:PSModulePath... "
36+
37+
$path += ";$moduleRoot"
38+
[Environment]::SetEnvironmentVariable("PSModulePath", $path, "Machine")
39+
40+
Write-Host -ForegroundColor Green "done"
41+
}
42+
43+
Write-Host "Installation complete."
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
param(
2+
[Parameter(Mandatory=$TRUE)]
3+
[String] $ModuleName
4+
)
5+
6+
$ErrorActionPreference = "Stop"
7+
8+
9+
$moduleRoot = "$($env:CommonProgramW6432)\Modules\"
10+
$dir = "$moduleRoot\$ModuleName\"
11+
12+
if (Test-Path $dir) {
13+
Write-Host -NoNewLine "Removing $ModuleName module from $moduleRoot... "
14+
15+
Remove-Item -Recurse -Force $dir
16+
17+
Write-Host -ForegroundColor Green "done"
18+
}
19+
20+
if (Test-Path $moduleRoot) {
21+
if (!(Get-ChildItem -Recurse -Force $moduleRoot)) {
22+
Write-Host "Module directory empty."
23+
24+
Write-Host -NoNewLine "Removing module directory from `$env:PSModulePath... "
25+
26+
$path = [Environment]::GetEnvironmentVariable("PSModulePath")
27+
28+
#Remove match paths but be careful about handling paths that don't
29+
#exist. We don't want to accidentally remove a path that we didn't
30+
#add.
31+
$cleanedPath = $path.Split(';') |
32+
Where-Object {
33+
(-Not (Test-Path $_ )) -or
34+
((Resolve-Path $_).Path -ne (Resolve-Path $moduleRoot).Path) } |
35+
Select-Object -Unique
36+
$cleanedPath = $cleanedPath -Join ';'
37+
38+
[Environment]::SetEnvironmentVariable("PSModulePath", $cleanedPath, "Machine")
39+
40+
Write-Host -ForegroundColor Green "done"
41+
42+
43+
Write-Host -NoNewLine "Removing empty module directory... "
44+
Remove-Item $moduleRoot
45+
Write-Host -ForegroundColor Green "done"
46+
47+
}
48+
49+
Write-Host "Removal complete."
50+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$packageName = "PSReadLine"
2+
3+
try {
4+
$source = Resolve-Path ($PSScriptRoot + "\..\$packageName\")
5+
6+
Start-ChocolateyProcessAsAdmin "$PSScriptRoot\Install-Module.ps1 '$source' '$packageName'"
7+
8+
9+
Write-ChocolateySuccess $packageName
10+
} catch {
11+
Write-ChocolateyFailure $packageName $($_.Exception.Message)
12+
throw
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
$packageName = "PSReadLine"
2+
3+
try {
4+
5+
Start-ChocolateyProcessAsAdmin "$PSScriptRoot\Remove-Module.ps1 '$packageName'"
6+
7+
Write-ChocolateySuccess $packageName
8+
} catch {
9+
$message = @"
10+
Uhoh. Looks like $packageName doesn't want to uninstall! But don't worry there is probably a good explanation.
11+
12+
It is highly likely that you have an instance of PowerShell running with $packageName loaded.
13+
14+
You should probably try closing all instances of PowerShell and rerunning this uninstall from cmd.exe.
15+
"@
16+
17+
Write-Host "==============================================="
18+
Write-Host $message
19+
Write-Host "==============================================="
20+
throw
21+
}

MakeRelease.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ $version = (Get-ChildItem $targetDir\PSReadline.dll).VersionInfo.FileVersion
4444

4545
& $PSScriptRoot\Update-ModuleManifest.ps1 $targetDir\PSReadline.psd1 $version
4646

47+
#make sure chocolatey is installed and in the path
48+
if (gcm cpack -ea Ignore)
49+
{
50+
$chocolateyDir = "$PSScriptRoot\ChocolateyPackage"
51+
52+
if (Test-Path $chocolateyDir\PSReadline)
53+
{
54+
rm -re $chocolateyDir\PSReadline
55+
}
56+
57+
& $PSScriptRoot\Update-NuspecVersion.ps1 "$chocolateyDir\PSReadline.nuspec" $version
58+
59+
cp -r $targetDir $chocolateyDir\PSReadline
60+
61+
cpack "$chocolateyDir\PSReadline.nuspec"
62+
}
4763

4864
del $PSScriptRoot\PSReadline.zip -ea Ignore
4965
[System.IO.Compression.ZipFile]::CreateFromDirectory($targetDir, "$PSScriptRoot\PSReadline.zip")

Update-NuspecVersion.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
param (
2+
[Parameter(Mandatory=$TRUE)]
3+
[String] $FilePath,
4+
[Parameter(Mandatory=$TRUE)]
5+
[String] $Version
6+
)
7+
8+
if ((Test-Path $FilePath -PathType Leaf) -ne $TRUE) {
9+
Write-Error -Message ($FilePath + ' not found.') -Category InvalidArgument;
10+
exit 1;
11+
}
12+
13+
#normalize path
14+
$FilePath = (Resolve-Path $FilePath).Path;
15+
16+
$nuspecConfig = [xml] (Get-Content $FilePath);
17+
$nuspecConfig.DocumentElement.metadata.version = $Version;
18+
19+
if (!$?) {
20+
Write-Error -Message "Unable to perform update.";
21+
exit 1;
22+
}
23+
24+
$nuspecConfig.Save($FilePath);

0 commit comments

Comments
 (0)