Skip to content

Commit

Permalink
New: Add chocolatey files (#91)
Browse files Browse the repository at this point in the history
Fix #31
  • Loading branch information
molant authored and jasongin committed Jun 17, 2018
1 parent 133bbbd commit 5237fd2
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
!/doc/
!/tools/
!/setup/
!/chocolatey/

# Temporary files generated during testing
/test/temp
Expand All @@ -30,5 +31,8 @@
# Nuget packages
packages/

# Generated chocolatey package
*.nupkg

# Other excluded files
*.suo
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down
14 changes: 14 additions & 0 deletions chocolatey/README.md
Original file line number Diff line number Diff line change
@@ -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)
48 changes: 48 additions & 0 deletions chocolatey/nvs.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Read this before creating packages: https://chocolatey.org/docs/create-packages -->
<!-- It is especially important to read the above link to understand additional requirements when publishing packages to the community feed aka dot org (https://chocolatey.org/packages). -->

<!-- Test your packages in a test environment: https://github.com/chocolatey/chocolatey-test-environment -->

<!--
This is a nuspec. It mostly adheres to https://docs.nuget.org/create/Nuspec-Reference. Chocolatey uses a special version of NuGet.Core that allows us to do more than was initially possible. As such there are certain things to be aware of:
* the package xmlns schema url may cause issues with nuget.exe
* Any of the following elements can ONLY be used by choco tools - projectSourceUrl, docsUrl, mailingListUrl, bugTrackerUrl, packageSourceUrl, provides, conflicts, replaces
* nuget.exe can still install packages with those elements but they are ignored. Any authoring tools or commands will error on those elements
-->

<!-- Do not remove this test for UTF-8: if “Ω” doesn’t appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one. -->
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<!-- == PACKAGE SPECIFIC SECTION == -->
<id>nvs</id>
<version>1.4.2</version>
<packageSourceUrl>https://github.com/jasongin/nvs</packageSourceUrl>
<owners>jasongin molant</owners>
<!-- ============================== -->

<!-- == SOFTWARE SPECIFIC SECTION == -->
<!-- This section is about the software itself -->
<title>NVS</title>
<authors>jasongin</authors>
<projectUrl>https://github.com/jasongin/nvs</projectUrl>
<!--<iconUrl>http://cdn.rawgit.com/__REPLACE_YOUR_REPO__/master/icons/nvs.png</iconUrl>-->
<copyright>Microsoft 2018</copyright>
<!-- If there is a license Url available, it is required for the community feed -->
<licenseUrl>https://github.com/jasongin/nvs/blob/master/LICENSE.txt</licenseUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<projectSourceUrl>https://github.com/jasongin/nvs</projectSourceUrl>
<docsUrl>https://github.com/jasongin/nvs/tree/master/doc</docsUrl>
<bugTrackerUrl>https://github.com/jasongin/nvs/issues</bugTrackerUrl>
<tags>nvs nodejs node</tags>
<summary>Node Version Switcher - A cross-platform tool for switching between versions and forks of Node.js </summary>
<description>NVS is a cross-platform utility for switching between different versions and forks of [Node.js](http://nodejs.org/).
NVS will get installed in `%LOCALAPPDATA%\nvs\` and added to your `PATH`.
For more information about the usage please visit [NVS's docs](https://github.com/jasongin/nvs/blob/master/README.md)</description>
</metadata>
<files>
<!-- this section controls what actually gets packaged into the Chocolatey package -->
<file src="tools\**" target="tools" />
</files>
</package>
21 changes: 21 additions & 0 deletions chocolatey/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$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

$packageArgs = @{
packageName = $env:ChocolateyPackageName
unzipLocation = $toolsDir
fileType = 'msi' #only one of these: exe, msi, msu
url = $url

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

# 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
37 changes: 37 additions & 0 deletions chocolatey/tools/chocolateyuninstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
$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
}

[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)"}
}

0 comments on commit 5237fd2

Please sign in to comment.