Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

inital

  • Loading branch information...
commit daf603ddaecb5c43d30a84a96094997f0d7981ed 0 parents
@Bonuspunkt authored
Showing with 246 additions and 0 deletions.
  1. +23 −0 README.md
  2. +24 −0 UNLICENSE
  3. +199 −0 wnave.ps1
23 README.md
@@ -0,0 +1,23 @@
+# wnave
+like (nave)[https://github.com/isaacs/nave] but for windows (powershell) with a partial feature set
+
+## instructions
+1. download the wnave.ps1
+2. open a powershell
+3. run wnave.ps1
+
+
+## commands
+```
+ install <version> Install node the version passed (ex: 0.6.0)
+ uninstall <version> Delete the install for <version>
+ use <version> enter a subshell where <version> is being used
+ ls list local installed versions
+ ls-remote remote available versions
+
+ npm-install <version> Install npm the version passed (ex 1.1.60)
+ npm-ls list remote available npm versions
+
+<version> can be the string "latest" to get the latest distribution.
+<version> can be the string "stable" to get the latest stable version.
+```
24 UNLICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
199 wnave.ps1
@@ -0,0 +1,199 @@
+# init
+$wnaveRoot = Join-Path $Env:UserProfile '.wnave'
+if (!(Test-Path $wnaveRoot)) {
+ New-Item -ItemType directory -Path $wnaveRoot
+}
+
+
+################################################################################
+## node stuff
+################################################################################
+function getNodeVersionList() {
+ $distList = (New-Object System.Net.WebClient).DownloadString('http://nodejs.org/dist/')
+ $versionPattern = New-Object System.Text.RegularExpressions.Regex('"v(?<version>\d+\.\d+\.\d+)/\"')
+ $nodeVersions = $versionPattern.Matches($distList) | %{New-Object System.Version($_.Groups[1].Value) }
+
+ return $nodeVersions | Sort-Object -Descending
+}
+
+function getNodeVersion($version) {
+ # determine version to load
+ if ($version -eq 'latest') {
+ $version = getNodeVersionList | select -index 0
+ }
+ elseif ($version -eq 'stable') {
+ $version = getNodeVersionList | where { ($_.Minor % 2) -eq 0 } | select -index 0
+ }
+ else {
+ # todo: ex: 0.8 should install hightest 0.8 version
+ try {
+ $version = New-Object System.Version($version)
+ } catch {
+ Write-Host $version is not a valid version string
+ exit
+ }
+ }
+ return $version
+}
+
+function installNode($version) {
+
+ $version = getNodeVersion($version)
+
+ $urls = @(
+ 'http://nodejs.org/dist/v' + $version + '/node.exe'
+ )
+ if ($env:PROCESSOR_ARCHITECTURE -eq 'AMD64') {
+ $url = 'http://nodejs.org/dist/v' + $version + '/x64/node.exe'
+ $urls = ,$url + $urls
+ }
+
+ # create directory
+ $destDir = Join-Path $wnaveRoot $version;
+
+ if (!(Test-Path $destDir)) {
+ Write-Host directory $destDir created
+ $noDisplay = New-Item -ItemType directory -Path $destDir
+ } else {
+ Write-Host directory $destDir already exists
+ }
+
+ #download node
+ $node = Join-Path $destDir 'node.exe'
+ if (Test-Path $node -PathType Leaf) {
+ Write-Host already installed
+ return
+ }
+ $success = $false
+ foreach ($url in $urls) {
+ try {
+ Write-Host trying to download $url to $node
+ (New-Object System.Net.WebClient).DownLoadFile($url, $node);
+ $success = $true
+ break;
+ } catch {
+ Write-Host download of $url failed
+ }
+ }
+
+ # download failed
+ if (!($success)) {
+ Write-Host could not install node $version
+ Remove-Item $destDir -Recurse
+ exit
+ }
+
+ Write-Host successfully installed node from $url
+
+ # write PowerShell script
+ $init = Join-Path $destDir 'init.ps1'
+ '# modify path' > $init
+ '$env:Path = "' + $destDir + ';" + $env:Path' >> $init
+ '# set environment variables' >> $init
+ '$env:NAVEVERSION = "' + $version + '"' >> $init
+ 'Write-Host using ' + $version >> $init
+}
+
+function uninstallNode($version) {
+ $target = Join-Path $wnaveRoot $version
+ Remove-Item $target -Recurse
+}
+
+function useNode($version) {
+ $version = getNodeVersion($version);
+ $nodeDir = Join-Path $wnaveRoot $version
+
+ if (!(Test-Path $nodeDir -PathType Container)) {
+ installNode($version)
+ }
+
+ $init = Join-Path $nodeDir 'init.ps1'
+ powershell -noexit $init
+}
+
+function listInstalled {
+ # TODO: better listing?
+ $items = Get-ChildItem $wnaveRoot
+ $items
+}
+
+function listRemote {
+ # TODO: better listing?
+ getNodeVersionList
+}
+
+################################################################################
+## npm stuff
+################################################################################
+function getNpmVersionList() {
+ $npmList = (New-Object System.Net.WebClient).DownloadString('http://nodejs.org/dist/npm/')
+ $npmVPattern = New-Object System.Text.RegularExpressions.Regex('"npm-(?<version>\d+\.\d+\.\d+)\.zip"')
+ $npmVersions = $npmVPattern.Matches($npmList) | %{New-Object System.Version($_.Groups[1].Value) }
+
+ return $npmVersions | Sort-Object -Descending
+}
+
+function getNpmVersion($version) {
+ # determine version to load
+ if ($version -eq 'latest') {
+ $version = getNpmVersionList | select -index 0
+ }
+ else {
+ try {
+ $version = New-Object System.Version($version)
+ } catch {
+ Write-Host $version is not a valid version string
+ exit
+ }
+ }
+ return $version
+}
+
+function installNpm($version) {
+ $version = getNpmVersion($version)
+
+ $node = (Get-Command node).Definition
+ $node_dir = (get-item $node).DirectoryName
+
+ # download npm
+ $filename = 'npm-' + $version + '.zip'
+ $downloaded = [System.Environment]::ExpandEnvironmentVariables('%temp%\' + $filename)
+ $url = 'http://nodejs.org/dist/npm/' + $filename;
+ (New-Object System.Net.WebClient).DownLoadFile($url, $downloaded);
+
+ # extract files
+ $zip = new-object -com shell.application
+ $source = $zip.namespace($downloaded);
+ $target = $zip.namespace($node_dir);
+ $target.CopyHere($source.items())
+
+ Write-Host yay i''m done
+}
+
+
+################################################################################
+## CLI
+################################################################################
+switch ($args[0]) {
+ 'install' { installNode($args[1]) }
+ 'uninstall' { uninstallNode($args[1]) }
+ 'use' { useNode($args[1]) }
+ 'ls' { listInstalled }
+ 'ls-remote' { listRemote }
+ 'npm' { installNpm($args[1]) }
+ 'ls-npm' { getNpmVersionList }
+ default {
+ Write-Host == commands ==
+ Write-Host ' install <version> Install the version passed (ex: 0.6.0)'
+ Write-Host ' uninstall <version> Delete the install for <version>'
+ Write-Host ' use <version> nter a subshell where <version> is being used'
+ Write-Host ' ls list local installed versions'
+ Write-Host ' ls-remote remote available versions'
+ Write-Host
+ Write-Host ' npm-install <version> Install npm the version passed (ex 1.1.60)'
+ Write-Host ' npm-ls list remote available npm versions'
+ Write-Host
+ Write-Host '<version> can be the string "latest" to get the latest distribution.'
+ Write-Host '<version> can be the string "stable" to get the latest stable version.'
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.