From a8a04173e787d69068533dffdbccb72236bcff3c Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Wed, 24 Sep 2014 20:41:28 -0500 Subject: [PATCH] Added isVersionAvailable(). Fixes and closes #1. --- src/nvm.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/nvm.go b/src/nvm.go index 4139a34..5661045 100644 --- a/src/nvm.go +++ b/src/nvm.go @@ -73,6 +73,13 @@ func install(version string) { // Check to see if the version is already installed if !isVersionInstalled(version) { + if !isVersionAvailable(version){ + fmt.Println("Version "+version+" is not available. If you are attempting to download a \"just released\" version,") + fmt.Println("it may not be recognized by the nvm service yet (updated hourly). If you feel this is in error and") + fmt.Println("you know the version exists, please visit http://github.com/coreybutler/nodedistro and submit a PR.") + return + } + // Make the output directories os.Mkdir(root+"\\v"+version,os.ModeDir) os.Mkdir(root+"\\v"+version+"\\node_modules",os.ModeDir) @@ -468,3 +475,17 @@ func setRootDir() { p=p } } + +func isVersionAvailable(v string) bool { + // Check the service to make sure the version is available + text := getRemoteTextFile("https://raw.githubusercontent.com/coreybutler/nodedistro/master/nodeversions.json") + + // Parse + var data interface{} + json.Unmarshal([]byte(text), &data); + body := data.(map[string]interface{}) + all := body["all"] + npm := all.(map[string]interface{}) + + return npm[v] != nil +} -- GitLab