Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
风弥漫了夏天
nvm-windows
提交
f355b501
N
nvm-windows
项目概览
风弥漫了夏天
/
nvm-windows
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nvm-windows
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f355b501
编写于
9月 23, 2014
作者:
C
Corey Butler
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finished list command, removed 'available' feature (unnecessary)
上级
8e6cecd6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
100 addition
and
27 deletion
+100
-27
src/nvm.go
src/nvm.go
+100
-27
未找到文件。
src/nvm.go
浏览文件 @
f355b501
...
@@ -19,6 +19,7 @@ import (
...
@@ -19,6 +19,7 @@ import (
var
root
=
""
var
root
=
""
var
symlink
=
""
var
symlink
=
""
var
settingsFile
=
os
.
Getenv
(
"APPDATA"
)
+
"
\\
nvm
\\
settings.txt"
func
main
()
{
func
main
()
{
args
:=
os
.
Args
args
:=
os
.
Args
...
@@ -42,12 +43,16 @@ func main() {
...
@@ -42,12 +43,16 @@ func main() {
case
"uninstall"
:
uninstall
(
detail
)
case
"uninstall"
:
uninstall
(
detail
)
case
"use"
:
use
(
detail
)
case
"use"
:
use
(
detail
)
case
"list"
:
list
(
detail
)
case
"list"
:
list
(
detail
)
case
"enable"
:
enable
()
case
"on"
:
enable
()
case
"disable"
:
disable
()
case
"off"
:
disable
()
//case "root": setRootDir(detail)
case
"root"
:
if
len
(
args
)
==
3
{
updateRootDir
(
args
[
2
])
}
else
{
fmt
.
Println
(
"
\n
Current Root: "
+
root
)
}
default
:
help
()
default
:
help
()
}
}
}
}
func
install
(
version
string
)
{
func
install
(
version
string
)
{
...
@@ -103,10 +108,7 @@ func install(version string) {
...
@@ -103,10 +108,7 @@ func install(version string) {
}
else
{
}
else
{
fmt
.
Println
(
"Could not download node.js executable for version "
+
version
+
"."
)
fmt
.
Println
(
"Could not download node.js executable for version "
+
version
+
"."
)
}
}
return
// Move node and npm to their directory, then update the symlink
// Remember to set the symlink path in the PATH during the installation
// If this is ever shipped for Mac, it should use homebrew.
// If this is ever shipped for Mac, it should use homebrew.
// If this ever ships on Linux, it should be on bintray so it can use yum, apt-get, etc.
// If this ever ships on Linux, it should be on bintray so it can use yum, apt-get, etc.
...
@@ -150,8 +152,8 @@ func use(version string) {
...
@@ -150,8 +152,8 @@ func use(version string) {
// Create or update the symlink
// Create or update the symlink
sym
,
serr
:=
os
.
Stat
(
symlink
)
sym
,
serr
:=
os
.
Stat
(
symlink
)
s
ym
=
sym
s
err
=
serr
if
s
err
=
=
nil
{
if
s
ym
!
=
nil
{
cmd
:=
exec
.
Command
(
root
+
"
\\
elevate.cmd"
,
"cmd"
,
"/C"
,
"rmdir"
,
symlink
)
cmd
:=
exec
.
Command
(
root
+
"
\\
elevate.cmd"
,
"cmd"
,
"/C"
,
"rmdir"
,
symlink
)
var
output
bytes
.
Buffer
var
output
bytes
.
Buffer
var
_stderr
bytes
.
Buffer
var
_stderr
bytes
.
Buffer
...
@@ -178,25 +180,76 @@ func use(version string) {
...
@@ -178,25 +180,76 @@ func use(version string) {
}
}
func
list
(
listtype
string
)
{
func
list
(
listtype
string
)
{
if
listtype
==
""
{
//
if listtype == "" {
listtype
=
"installed"
listtype
=
"installed"
// }
// if listtype != "installed" && listtype != "available" {
// fmt.Println("\nInvalid list option.\n\nPlease use on of the following\n - nvm list\n - nvm list installed\n - nvm list available")
// help()
// return
// }
if
listtype
==
"installed"
{
fmt
.
Println
(
""
)
vers
:=
""
cmd
:=
exec
.
Command
(
"node"
,
"-v"
)
str
,
err
:=
cmd
.
Output
()
if
err
==
nil
{
vers
=
strings
.
Trim
(
string
(
str
),
"
\n\r
"
)
}
dir
:=
""
files
,
_
:=
ioutil
.
ReadDir
(
root
)
for
_
,
f
:=
range
files
{
if
f
.
IsDir
()
{
isnode
,
verr
:=
regexp
.
MatchString
(
"v"
,
f
.
Name
())
verr
=
verr
if
isnode
{
dir
=
f
.
Name
()
if
f
.
Name
()
==
vers
{
fmt
.
Printf
(
" * "
)
}
else
{
fmt
.
Printf
(
" "
)
}
fmt
.
Printf
(
regexp
.
MustCompile
(
"v"
)
.
ReplaceAllString
(
f
.
Name
(),
""
))
if
f
.
Name
()
==
vers
{
fmt
.
Printf
(
" (In Use)"
)
}
fmt
.
Printf
(
"
\n
"
)
}
}
}
if
len
(
strings
.
Trim
(
dir
,
"
\n\r
"
))
==
0
{
fmt
.
Println
(
"No installations recognized."
)
}
// } else {
// fmt.Printf("List "+listtype)
}
}
if
listtype
!=
"installed"
&&
listtype
!=
"available"
{
fmt
.
Println
(
"
\n
Invalid list option.
\n\n
Please use on of the following
\n
- nvm list
\n
- nvm list installed
\n
- nvm list available"
)
help
()
return
}
fmt
.
Printf
(
"List "
+
listtype
)
}
}
func
enable
()
{
func
enable
()
{
// Prompt user, warning them what they're going to do
dir
:=
""
fmt
.
Printf
(
"Enable by setting the PATH to use the root with a symlink"
)
files
,
_
:=
ioutil
.
ReadDir
(
root
)
for
_
,
f
:=
range
files
{
if
f
.
IsDir
()
{
isnode
,
verr
:=
regexp
.
MatchString
(
"v"
,
f
.
Name
())
verr
=
verr
if
isnode
{
dir
=
f
.
Name
()
}
}
}
fmt
.
Println
(
"nvm enabled"
)
if
dir
!=
""
{
use
(
strings
.
Trim
(
regexp
.
MustCompile
(
"v"
)
.
ReplaceAllString
(
dir
,
""
),
"
\n\r
"
))
}
else
{
fmt
.
Println
(
"No versions of node.js found. Try installing the latest by typing nvm install latest"
)
}
}
}
func
disable
()
{
func
disable
()
{
// Prompt user, warning them what they're going to do
cmd
:=
exec
.
Command
(
root
+
"
\\
elevate.cmd"
,
"cmd"
,
"/C"
,
"rmdir"
,
symlink
)
fmt
.
Printf
(
"Disable by removing the symlink in PATH var"
)
cmd
.
Run
()
fmt
.
Println
(
"nvm disabled"
)
}
}
func
help
()
{
func
help
()
{
...
@@ -204,12 +257,10 @@ func help() {
...
@@ -204,12 +257,10 @@ func help() {
fmt
.
Println
(
" nvm install <version> : The version can be a node.js version or
\"
latest
\"
for the latest stable version."
)
fmt
.
Println
(
" nvm install <version> : The version can be a node.js version or
\"
latest
\"
for the latest stable version."
)
fmt
.
Println
(
" nvm uninstall <version> : The version must be a specific version."
)
fmt
.
Println
(
" nvm uninstall <version> : The version must be a specific version."
)
fmt
.
Println
(
" nvm use <version> : Switch to use the specified version."
)
fmt
.
Println
(
" nvm use <version> : Switch to use the specified version."
)
fmt
.
Println
(
" nvm list [type] : type can be
\"
available
\"
(from nodejs.org),"
)
fmt
.
Println
(
" nvm list : List what is currently installed."
)
fmt
.
Println
(
"
\"
installed
\"
(what is currently on the computer),"
)
fmt
.
Println
(
" or left blank (same as
\"
installed
\"
)."
)
fmt
.
Println
(
" nvm on : Enable node.js version management."
)
fmt
.
Println
(
" nvm on : Enable node.js version management."
)
fmt
.
Println
(
" nvm off : Disable node.js version management."
)
fmt
.
Println
(
" nvm off : Disable node.js version management."
)
fmt
.
Println
(
" nvm root <path> : Set the directory where
wnvm should install different node.js version
s."
)
fmt
.
Println
(
" nvm root <path> : Set the directory where
nvm should store different versions of node.j
s."
)
fmt
.
Println
(
" If <path> is not set, the current root will be displayed.
\n
"
)
fmt
.
Println
(
" If <path> is not set, the current root will be displayed.
\n
"
)
}
}
...
@@ -379,8 +430,22 @@ func readLines(path string) ([]string, error) {
...
@@ -379,8 +430,22 @@ func readLines(path string) ([]string, error) {
return
lines
,
scanner
.
Err
()
return
lines
,
scanner
.
Err
()
}
}
func
updateRootDir
(
path
string
)
{
ok
,
err
:=
os
.
Stat
(
path
)
if
err
!=
nil
{
fmt
.
Println
(
path
+
" does not exist or could not be found."
)
return
}
ok
=
ok
content
:=
"root: "
+
strings
.
Trim
(
path
,
"
\n\r
"
)
+
"
\r\n
path: "
+
strings
.
Trim
(
symlink
,
"
\n\r
"
)
ioutil
.
WriteFile
(
settingsFile
,
[]
byte
(
content
),
0644
)
root
=
path
fmt
.
Println
(
"
\n
Root has been set to "
+
path
)
}
func
setRootDir
()
{
func
setRootDir
()
{
lines
,
err
:=
readLines
(
os
.
Getenv
(
"APPDATA"
)
+
"
\\
nvm
\\
settings.txt"
)
lines
,
err
:=
readLines
(
settingsFile
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"
\n
ERROR"
,
err
)
fmt
.
Println
(
"
\n
ERROR"
,
err
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
...
@@ -389,9 +454,17 @@ func setRootDir() {
...
@@ -389,9 +454,17 @@ func setRootDir() {
// Process each line and extract the value
// Process each line and extract the value
for
_
,
line
:=
range
lines
{
for
_
,
line
:=
range
lines
{
if
strings
.
Contains
(
line
,
"root:"
)
{
if
strings
.
Contains
(
line
,
"root:"
)
{
root
=
strings
.
Trim
(
regexp
.
MustCompile
(
"root:"
)
.
ReplaceAllString
(
line
,
""
),
" "
)
root
=
strings
.
Trim
(
regexp
.
MustCompile
(
"root:"
)
.
ReplaceAllString
(
line
,
""
),
"
\r\n
"
)
}
else
if
strings
.
Contains
(
line
,
"path:"
)
{
}
else
if
strings
.
Contains
(
line
,
"path:"
)
{
symlink
=
strings
.
Trim
(
regexp
.
MustCompile
(
"path:"
)
.
ReplaceAllString
(
line
,
""
),
" "
)
symlink
=
strings
.
Trim
(
regexp
.
MustCompile
(
"path:"
)
.
ReplaceAllString
(
line
,
""
),
"
\r\n
"
)
}
}
}
}
// Make sure the directories exist
p
,
e
:=
os
.
Stat
(
root
)
if
e
!=
nil
{
fmt
.
Println
(
root
+
" could not be found or does not exist. Exiting."
)
return
p
=
p
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录