diff --git a/.gitignore b/.gitignore index 31bb18d..2db03d7 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ !/doc/ !/tools/ !/setup/ +!/chocolatey/ # Temporary files generated during testing /test/temp diff --git a/README.md b/README.md index 6e85e8b..ca3ae90 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ Following are basic setup instructions. [For more details and options for settin ### Windows A Windows Installer (MSI) package is available from the [NVS releases page on GitHub](https://github.com/jasongin/nvs/releases). +You can also use [chocolatey](https://chocolatey.org) to install it: +``` +choco install nvs +``` + ### Mac, Linux Specify the installation path, clone the repo, and *source* the `install` command: ``` diff --git a/chocolatey/README.md b/chocolatey/README.md new file mode 100644 index 0000000..c640a4e --- /dev/null +++ b/chocolatey/README.md @@ -0,0 +1,14 @@ +# nvs chocolatey package + +Chocolatey package for [nvs](https://github.com/jasongin/nvs/) + +## Test the package locally + +To test this package locally you will need to: + +1. Install [Chocolatey](https://chocolatey.org/install) +1. Open an elevated PowerShell window +1. From the root of the project, execute `choco pack` +1. Then run `choco install nvs -dv -s .` + +For more information you can check the [Chocolatey documentation](https://chocolatey.org/docs/create-packages) diff --git a/chocolatey/nvs.nuspec b/chocolatey/nvs.nuspec new file mode 100644 index 0000000..4ecada7 --- /dev/null +++ b/chocolatey/nvs.nuspec @@ -0,0 +1,47 @@ + + + + + + + + + + + + + nvs + 1.4.2 + https://github.com/jasongin/nvs + jasongin molant + + + + + nvs + jasongin + https://github.com/jasongin/nvs + + Microsoft 2018 + + https://github.com/jasongin/nvs/blob/master/LICENSE.txt + true + https://github.com/jasongin/nvs + https://github.com/jasongin/nvs/tree/master/doc + https://github.com/jasongin/nvs/issues + nvs nodejs node + Node Version Switcher - A cross-platform tool for switching between versions and forks of Node.js + NVS is a cross-platform utility for switching between different versions and forks of [Node.js](http://nodejs.org/). NVS is itself written in node JavaScript. +This tool is obviously inspired by other node version manager tools, especially [nvm](https://github.com/creationix/nvm), from which it borrows a lot of ideas and some command-line syntax. + + + + + + diff --git a/chocolatey/tools/chocolateyinstall.ps1 b/chocolatey/tools/chocolateyinstall.ps1 new file mode 100644 index 0000000..5f0d408 --- /dev/null +++ b/chocolatey/tools/chocolateyinstall.ps1 @@ -0,0 +1,26 @@ +$ErrorActionPreference = 'Stop'; # stop on all errors +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +$url = 'https://github.com/jasongin/nvs/releases/download/v1.4.2/nvs-1.4.2.msi' # download url, HTTPS preferred +# $url64 = '' # 64bit URL here (HTTPS preferred) or remove - if installer contains both (very rare), use $url + +$packageArgs = @{ + packageName = $env:ChocolateyPackageName + unzipLocation = $toolsDir + fileType = 'msi' #only one of these: exe, msi, msu + url = $url + # url64bit = $url64 + #file = $fileLocation + + softwareName = 'nvs' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique + + checksum = '87fa567001baea5604e4be03188d6d11ae2a2e055781e5168da5ea2f0f8fb5479aa0c3511b641f5147ef7bbffe03cbff1a36588c1f37a8dd2c27010e24d0d3f9' + checksumType = 'sha512' #default is md5, can also be sha1, sha256 or sha512 + # checksum64 = '' + # checksumType64= 'sha256' #default is checksumType + + # MSI + silentArgs = "/quiet" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0 + validExitCodes= @(0, 3010, 1641) +} + +Install-ChocolateyPackage @packageArgs # https://chocolatey.org/docs/helpers-install-chocolatey-package diff --git a/chocolatey/tools/chocolateyuninstall.ps1 b/chocolatey/tools/chocolateyuninstall.ps1 new file mode 100644 index 0000000..e586f60 --- /dev/null +++ b/chocolatey/tools/chocolateyuninstall.ps1 @@ -0,0 +1,39 @@ +$ErrorActionPreference = 'Stop'; # stop on all errors +$packageArgs = @{ + packageName = $env:ChocolateyPackageName + softwareName = 'nvs' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique + fileType = 'msi' #only one of these: MSI or EXE (ignore MSU for now) + # MSI + silentArgs = "/qn /norestart" + validExitCodes= @(0, 3010, 1605, 1614, 1641) # https://msdn.microsoft.com/en-us/library/aa376931(v=vs.85).aspx +} + +$uninstalled = $false + +[array]$key = Get-UninstallRegistryKey -SoftwareName $packageArgs['softwareName'] + +if ($key.Count -eq 1) { + $key | % { + $packageArgs['file'] = "$($_.UninstallString)" + if ($packageArgs['fileType'] -eq 'MSI') { + # The Product Code GUID is all that should be passed for MSI, and very + # FIRST, because it comes directly after /x, which is already set in the + # Uninstall-ChocolateyPackage msiargs (facepalm). + $packageArgs['silentArgs'] = "$($_.PSChildName) $($packageArgs['silentArgs'])" + + # Don't pass anything for file, it is ignored for msi (facepalm number 2) + # Alternatively if you need to pass a path to an msi, determine that and + # use it instead of the above in silentArgs, still very first + $packageArgs['file'] = '' + } + + Uninstall-ChocolateyPackage @packageArgs + } +} elseif ($key.Count -eq 0) { + Write-Warning "$packageName has already been uninstalled by other means." +} elseif ($key.Count -gt 1) { + Write-Warning "$($key.Count) matches found!" + Write-Warning "To prevent accidental data loss, no programs will be uninstalled." + Write-Warning "Please alert package maintainer the following keys were matched:" + $key | % {Write-Warning "- $($_.DisplayName)"} +}