Added isVersionAvailable(). Fixes and closes #1.

This commit is contained in:
Corey Butler
2014-09-24 20:41:28 -05:00
parent beb7e4a218
commit a8a04173e7

View File

@@ -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
}