-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac07896
commit 06dc872
Showing
2 changed files
with
68 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,62 @@ | ||
package node | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
) | ||
|
||
func SetPath(path string) { | ||
if runtime.GOOS == "windows" { | ||
SetPathWindows(path) | ||
} else if runtime.GOOS == "linux" || runtime.GOOS == "darwin" { | ||
SetPathLinux(path) | ||
} else { | ||
fmt.Println("Not implemented for this OS") | ||
} | ||
} | ||
|
||
func Use(version string) { | ||
path, err := GetVersionPath(version) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
f, err := os.OpenFile(filepath.Join(GetHome(), ".vmn", "current"), os.O_RDWR|os.O_CREATE, 0755) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer f.Close() | ||
|
||
if _, err := f.Stat(); err == nil { | ||
f.Truncate(0) | ||
f.Seek(0, 0) | ||
f.WriteString(path) | ||
} | ||
|
||
if _, err := os.Stat(path); err == nil { | ||
fmt.Println("Setting VMN_VERSION to " + version + " ... ") | ||
SetPath(path) | ||
} else { | ||
fmt.Println("Node.js version " + version + " is not installed") | ||
} | ||
} | ||
|
||
func UseLatest() { | ||
Use(GetLatestVersion()) | ||
} | ||
|
||
func UseLatestLTS() { | ||
Use(GetLatestLTSVersion()) | ||
} | ||
|
||
func UseSpecific(version string) { | ||
Use(GetLatestVersionOfVersion(version)) | ||
} | ||
package node | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
) | ||
|
||
func SetPath(path string) { | ||
if runtime.GOOS == "windows" { | ||
SetPathWindows(path) | ||
} else if runtime.GOOS == "linux" || runtime.GOOS == "darwin" { | ||
SetPathLinux(path) | ||
} else { | ||
fmt.Println("Not implemented for this OS") | ||
} | ||
} | ||
|
||
func Use(version string) { | ||
path, err := GetVersionPath(version) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if _, err := os.Stat(filepath.Join(GetHome(), ".vmn")); os.IsNotExist(err) { | ||
if err := os.MkdirAll(filepath.Join(GetHome(), ".vmn"), 0755); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
f, err := os.OpenFile(filepath.Join(GetHome(), ".vmn", "current"), os.O_RDWR|os.O_CREATE, 0755) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer f.Close() | ||
|
||
if _, err := f.Stat(); err == nil { | ||
f.Truncate(0) | ||
f.Seek(0, 0) | ||
f.WriteString(path) | ||
} | ||
|
||
if _, err := os.Stat(path); err == nil { | ||
fmt.Println("Setting VMN_VERSION to " + version + " ... ") | ||
SetPath(path) | ||
} else { | ||
fmt.Println("Node.js version " + version + " is not installed") | ||
} | ||
} | ||
|
||
func UseLatest() { | ||
Use(GetLatestVersion()) | ||
} | ||
|
||
func UseLatestLTS() { | ||
Use(GetLatestLTSVersion()) | ||
} | ||
|
||
func UseSpecific(version string) { | ||
Use(GetLatestVersionOfVersion(version)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters