Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add package.json and git files

  • Loading branch information...
commit 851c40fa9c4b0e514302e997917c304dd51007b5 1 parent e647465
Bonuspunkt authored
Showing with 251 additions and 221 deletions.
  1. +4 −0 .gitattributes
  2. +1 −0  .gitignore
  3. +22 −23 README.md
  4. +16 −0 package.json
  5. +208 −198 wnave.ps1
4 .gitattributes
View
@@ -0,0 +1,4 @@
+# Set default behaviour
+* text eol=lf
+
+*.ps1 crlf
1  .gitignore
View
@@ -0,0 +1 @@
+npm-debug.log
45 README.md
View
@@ -1,23 +1,22 @@
-# 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.
-```
+# 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.
+```
16 package.json
View
@@ -0,0 +1,16 @@
+{
+ "name": "wnave",
+ "description": "Virtual Environments for Node on windows",
+ "version": "0.0.0",
+ "preferGlobal": true,
+ "bin": {
+ "wnave": "./wnave.ps1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Bonuspunkt/wnave.git"
+ },
+ "author": "Bonuspunkt",
+ "license": "UNLICENSE",
+ "readmeFilename": "README.md"
+}
406 wnave.ps1
View
@@ -1,199 +1,209 @@
-# 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.'
- }
+#!powershell
+
+# 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?
+ Get-ChildItem $wnaveRoot
+}
+
+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 installed npm $version
+}
+
+
+################################################################################
+## CLI
+################################################################################
+switch ($args[0]) {
+ <#
+ 'addToPath' {
+ $workingDir = (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent);
+ $env:Path = "$env:Path;$workingDir"
+
+ Write-Host added wnave to path
+ }
+ #>
+ 'install' { installNode($args[1]) }
+ 'uninstall' { uninstallNode($args[1]) }
+ 'use' { useNode($args[1]) }
+ 'ls' { listInstalled }
+ 'ls-remote' { listRemote }
+ 'npm-install' { installNpm($args[1]) }
+ 'npm-ls' { 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.'
+ Write-Host ' stable is not available for install-npm'
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.