Permalink
Browse files

Cleaned up PR's, added formatting for ls, updated installer to 1.1.1

  • Loading branch information...
1 parent 19f8b22 commit 7a4544317a35251ed40aa7c59b3f99b8c3a8f2c8 @coreybutler committed Jul 2, 2016
Showing with 178 additions and 70 deletions.
  1. +1 −2 LICENSE
  2. +33 −29 build.bat
  3. +3 −3 nvm.iss
  4. +69 −26 src/nvm.go
  5. +72 −10 src/nvm/node/node.go
View
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2014 Corey Butler
+Copyright (c) 2014 Corey Butler and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS 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.
-
View
@@ -4,53 +4,57 @@ SET ORIG=%CD%
SET GOPATH=%CD%\src
SET GOBIN=%CD%\bin
SET GOARCH=386
+SET version=1.1.1
REM Get the version number from the setup file
-for /f "tokens=*" %%i in ('findstr /n . %INNOSETUP% ^| findstr ^4:#define') do set L=%%i
-set version=%L:~24,-1%
+REM for /f "tokens=*" %%i in ('findstr /n . %INNOSETUP% ^| findstr ^4:#define') do set L=%%i
+REM set version=%L:~24,-1%
REM Get the version number from the core executable
-for /f "tokens=*" %%i in ('findstr /n . %GOPATH%\nvm.go ^| findstr ^NvmVersion^| findstr ^21^') do set L=%%i
-set goversion=%L:~19,-1%
+REM for /f "tokens=*" %%i in ('findstr /n . %GOPATH%\nvm.go ^| findstr ^NvmVersion^| findstr ^21^') do set L=%%i
+REM set goversion=%L:~19,-1%
-IF NOT %version%==%goversion% GOTO VERSIONMISMATCH
+REM IF NOT %version%==%goversion% GOTO VERSIONMISMATCH
SET DIST=%CD%\dist\%version%
REM Build the executable
echo Building NVM for Windows
-rm %GOBIN%\nvm.exe
-cd %GOPATH%
+REM rm %GOBIN%\nvm.exe
+REM cd %GOPATH%
echo "=========================================>"
-echo %GOBIN%
-goxc -arch="386" -os="windows" -n="nvm" -d="%GOBIN%" -o="%GOBIN%\nvm{{.Ext}}" -tasks-=package
-cd %ORIG%
-rm %GOBIN%\src.exe
-rm %GOPATH%\src.exe
-rm %GOPATH%\nvm.exe
+REM echo %GOBIN%
+REM goxc -arch="386" -os="windows" -n="nvm" -d="%GOBIN%" -o="%GOBIN%\nvm{{.Ext}}" -tasks-=package
+
+REM cd %ORIG%
+REM rm %GOBIN%\src.exe
+REM rm %GOPATH%\src.exe
+REM rm %GOPATH%\nvm.exe
REM Clean the dist directory
rm -rf "%DIST%"
mkdir "%DIST%"
-REM Create the "noinstall" zip
-echo Generating nvm-noinstall.zip
+echo Creating distribution in %DIST%
+
+if exist src\nvm.exe (
+ rm src\nvm.exe
+)
+
+echo "Building nvm.exe...."
+
+go build src\nvm.go
+mv nvm.exe %GOBIN%
+
+echo Building "noinstall" zip...
for /d %%a in (%GOBIN%) do (buildtools\zip -j -9 -r "%DIST%\nvm-noinstall.zip" "%CD%\LICENSE" "%%a\*" -x "%GOBIN%\nodejs.ico")
-REM Create the installer
-echo Generating nvm-setup.zip
+echo "Building the primary installer..."
buildtools\iscc %INNOSETUP% /o%DIST%
buildtools\zip -j -9 -r "%DIST%\nvm-setup.zip" "%DIST%\nvm-setup.exe"
-REM rm "%DIST%\nvm-setup.exe"
-echo --------------------------
-echo Release %version% available in %DIST%
-GOTO COMPLETE
-
-:VERSIONMISMATCH
-echo The version number in nvm.iss does not match the version in src\nvm.go
-echo - nvm.iss line #4: %version%
-echo - nvm.go line #21: %goversion%
-EXIT /B
-
-:COMPLETE
+
+echo "Distribution created. Now cleaning up...."
+rm %GOBIN%/nvm.exe
+
+echo "Done."
@echo on
View
@@ -1,8 +1,8 @@
#define MyAppName "NVM for Windows"
#define MyAppShortName "nvm"
#define MyAppLCShortName "nvm"
-#define MyAppVersion "1.1.0"
-#define MyAppPublisher "Ecor Ventures, LLC"
+#define MyAppVersion "1.1.1"
+#define MyAppPublisher "Ecor Ventures LLC"
#define MyAppURL "http://github.com/coreybutler/nvm"
#define MyAppExeName "nvm.exe"
#define MyIcon "bin\nodejs.ico"
@@ -35,7 +35,7 @@ ChangesEnvironment=yes
DisableProgramGroupPage=yes
ArchitecturesInstallIn64BitMode=x64 ia64
UninstallDisplayIcon={app}\{#MyIcon}
-AppCopyright=Copyright (C) 2014 Corey Butler.
+AppCopyright=Copyright (C) 2016 Corey Butler and contributors.
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
View
@@ -8,16 +8,15 @@ import (
"io/ioutil"
"regexp"
"bytes"
- "strconv"
"./nvm/web"
"./nvm/arch"
"./nvm/file"
"./nvm/node"
-// "./ansi"
+ "github.com/olekukonko/tablewriter"
)
const (
- NvmVersion = "1.1.0"
+ NvmVersion = "1.1.1"
)
type Environment struct {
@@ -159,7 +158,7 @@ func install(version string, cpuarch string) {
if cpuarch != "all" {
cpuarch = arch.Validate(cpuarch)
}
-
+
// If user specifies "latest" version, find out what version is
if version == "latest" {
url := web.GetFullNodeUrl("latest/SHASUMS256.txt");
@@ -173,7 +172,7 @@ func install(version string, cpuarch string) {
fmt.Println("Node.js v"+version+" is not yet released or available.")
return
}
-
+
if cpuarch == "64" && !web.IsNode64bitAvailable(version) {
fmt.Println("Node.js v"+version+" is only available in 32-bit.")
return
@@ -262,6 +261,8 @@ func uninstall(version string) {
return
}
+ version = cleanVersion(version)
+
// Determine if the version exists and skip if it doesn't
if node.IsVersionInstalled(env.root,version,"32") || node.IsVersionInstalled(env.root,version,"64") {
fmt.Printf("Uninstalling node v"+version+"...")
@@ -283,8 +284,25 @@ func uninstall(version string) {
return
}
-func use(version string, cpuarch string) {
+func cleanVersion(version string) string {
+ re := regexp.MustCompile("\\d+.\\d+.\\d+")
+ matched := re.FindString(version)
+
+ if len(matched) == 0 {
+ re = regexp.MustCompile("\\d+.\\d+")
+ matched = re.FindString(version)
+ if len(matched) == 0 {
+ matched = version + ".0.0"
+ } else {
+ matched = matched + ".0"
+ }
+ fmt.Println(matched)
+ }
+
+ return matched
+}
+func use(version string, cpuarch string) {
if version == "32" || version == "64" {
cpuarch = version
v, _ := node.GetCurrentVersion()
@@ -293,6 +311,10 @@ func use(version string, cpuarch string) {
cpuarch = arch.Validate(cpuarch)
+ re := regexp.MustCompile("\\d+.\\d+.\\d+")
+
+ version = cleanVersion(version)
+
// Make sure the version is installed. If not, warn.
if !node.IsVersionInstalled(env.root,version,cpuarch) {
fmt.Println("node v"+version+" ("+cpuarch+"-bit) is not installed.")
@@ -407,35 +429,56 @@ func list(listtype string) {
fmt.Println("No installations recognized.")
}
} else {
- _, lts, stable, _ := node.GetAvailable()
+ _, lts, current, stable, unstable, _ := node.GetAvailable()
- releases := len(stable)
+ releases := 20
- fmt.Println("\nShowing the "+strconv.Itoa(releases)+" latest available releases.\n")
+ data := make([][]string, releases, releases + 5)
+ for i := 0; i < releases; i++ {
+ release := make([]string, 4, 6)
- fmt.Println(" LTS | STABLE ")
- fmt.Println(" ---------------------------")
+ release[0] = ""
+ release[1] = ""
+ release[2] = ""
+ release[3] = ""
+
+ if len(current) > i {
+ if len(current[i]) > 0 {
+ release[0] = current[i]
+ }
+ }
- for i := 0; i < releases; i++ {
- str := " "
if len(lts) > i {
- str = "v"+lts[i]
- for ii := 10-len(str); ii > 0; ii-- {
- str = " "+str
- }
+ if len(lts[i]) > 0 {
+ release[1] = lts[i]
+ }
}
- str2 := ""
if len(stable) > i {
- str2 = "v"+stable[i]
- for ii := 10-len(str2); ii > 0; ii-- {
- str2 = " "+str2
+ if len(stable[i]) > 0 {
+ release[2] = stable[i]
+ }
+ }
+
+ if len(unstable) > i {
+ if len(unstable[i]) > 0 {
+ release[3] = unstable[i]
}
}
- fmt.Println(" "+str + " | " + str2)
+
+ data[i] = release
}
- fmt.Println("\nFor a complete list, visit https://nodejs.org/download/release")
+ fmt.Println("")
+ table := tablewriter.NewWriter(os.Stdout)
+ table.SetHeader([]string{" Current ", " LTS ", " Old Stable ", "Old Unstable"})
+ table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
+ table.SetAlignment(tablewriter.ALIGN_CENTER)
+ table.SetCenterSeparator("|")
+ table.AppendBulk(data) // Add Bulk Data
+ table.Render()
+
+ fmt.Println("\nThis is a partial list. For a complete list, visit https://nodejs.org/download/release")
}
}
@@ -477,8 +520,8 @@ func help() {
fmt.Println(" nvm off : Disable node.js version management.")
fmt.Println(" nvm proxy [url] : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.")
fmt.Println(" Set [url] to \"none\" to remove the proxy.")
- fmt.Println(" nvm node_mirror [url] : Set a mirror to https://nodejs.org/dist/. Leave [url] blank to use default url.")
- fmt.Println(" nvm npm_mirror [url] : Set a mirror to https://github.com/npm/npm/archive/. Leave [url] blank to default url.")
+ fmt.Println(" nvm node_mirror [url] : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.")
+ fmt.Println(" nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/npm/archive/. Leave [url] blank to default url.")
fmt.Println(" nvm uninstall <version> : The version must be a specific version.")
// fmt.Println(" nvm update : Automatically update nvm to the latest version.")
fmt.Println(" nvm use [version] [arch] : Switch to use the specified version. Optionally specify 32/64bit architecture.")
@@ -492,7 +535,7 @@ func help() {
// Given a node.js version, returns the associated npm version
func getNpmVersion(nodeversion string) string {
- _, _, _, npm := node.GetAvailable()
+ _, _, _, _, _, npm := node.GetAvailable()
return npm[nodeversion]
}
Oops, something went wrong.

0 comments on commit 7a45443

Please sign in to comment.