Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
风弥漫了夏天
nvm-windows
提交
39a1bea3
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,发现更多精彩内容 >>
提交
39a1bea3
编写于
4月 07, 2016
作者:
L
lijie371
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add node_mirror and npm_mirror config
上级
6edd36b4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
94 addition
and
42 deletion
+94
-42
build.bat
build.bat
+2
-2
nvm.iss
nvm.iss
+1
-1
src/nvm.go
src/nvm.go
+20
-17
src/nvm/node/node.go
src/nvm/node/node.go
+40
-14
src/nvm/web/web.go
src/nvm/web/web.go
+31
-8
未找到文件。
build.bat
浏览文件 @
39a1bea3
...
...
@@ -19,10 +19,10 @@ SET DIST=%CD%\dist\%version%
REM Build the executable
echo Building NVM for Windows
rm
%GOBIN%
\nvm.exe
REM
rm
%GOBIN%
\nvm.exe
cd
%GOPATH%
goxc -arch="386" -os="windows" -n="nvm" -d="
%GOBIN%
" -o="
%GOBIN%
\nvm{{.Ext}}" -tasks-=package
cd
%ORIG%
REM go build src/nvm.go -o=bin/nvm.exe
rm
%GOBIN%
\src.exe
rm
%GOPATH%
\src.exe
rm
%GOPATH%
\nvm.exe
...
...
nvm.iss
浏览文件 @
39a1bea3
...
...
@@ -6,7 +6,7 @@
#define MyAppURL "http://github.com/coreybutler/nvm"
#define MyAppExeName "nvm.exe"
#define MyIcon "bin\nodejs.ico"
#define ProjectRoot "
C:\Users\Corey\Documents\workspace\Applications\nvm
"
#define ProjectRoot "
E:\projects\go\src\nvm-windows
"
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
...
...
src/nvm.go
浏览文件 @
39a1bea3
...
...
@@ -8,7 +8,6 @@ import (
"io/ioutil"
"regexp"
"bytes"
"encoding/json"
"strconv"
"./nvm/web"
"./nvm/arch"
...
...
@@ -26,6 +25,8 @@ type Environment struct {
root
string
symlink
string
arch
string
node_mirror
string
npm_mirror
string
proxy
string
originalpath
string
originalversion
string
...
...
@@ -36,6 +37,8 @@ var env = &Environment{
root
:
""
,
symlink
:
os
.
Getenv
(
"NVM_SYMLINK"
),
arch
:
os
.
Getenv
(
"PROCESSOR_ARCHITECTURE"
),
node_mirror
:
""
,
npm_mirror
:
""
,
proxy
:
"none"
,
originalpath
:
""
,
originalversion
:
""
,
...
...
@@ -120,7 +123,9 @@ func update() {
}
func
CheckVersionExceedsLatest
(
version
string
)
bool
{
content
:=
web
.
GetRemoteTextFile
(
"http://nodejs.org/dist/latest/SHASUMS256.txt"
)
//content := web.GetRemoteTextFile("http://nodejs.org/dist/latest/SHASUMS256.txt")
url
:=
web
.
GetFullNodeUrl
(
"latest/SHASUMS256.txt"
);
content
:=
web
.
GetRemoteTextFile
(
url
)
re
:=
regexp
.
MustCompile
(
"node-v(.+)+msi"
)
reg
:=
regexp
.
MustCompile
(
"node-v|-x.+"
)
latest
:=
reg
.
ReplaceAllString
(
re
.
FindString
(
content
),
""
)
...
...
@@ -157,7 +162,8 @@ func install(version string, cpuarch string) {
// If user specifies "latest" version, find out what version is
if
version
==
"latest"
{
content
:=
web
.
GetRemoteTextFile
(
"http://nodejs.org/dist/latest/SHASUMS256.txt"
)
url
:=
web
.
GetFullNodeUrl
(
"latest/SHASUMS256.txt"
);
content
:=
web
.
GetRemoteTextFile
(
url
)
re
:=
regexp
.
MustCompile
(
"node-v(.+)+msi"
)
reg
:=
regexp
.
MustCompile
(
"node-v|-x.+"
)
version
=
reg
.
ReplaceAllString
(
re
.
FindString
(
content
),
""
)
...
...
@@ -403,7 +409,7 @@ func list(listtype string) {
}
else
{
_
,
stable
,
unstable
:=
node
.
GetAvailable
()
releases
:=
15
releases
:=
len
(
stable
)
fmt
.
Println
(
"
\n
Showing the "
+
strconv
.
Itoa
(
releases
)
+
" latest available releases.
\n
"
)
...
...
@@ -423,7 +429,7 @@ func list(listtype string) {
fmt
.
Println
(
" "
+
str
+
str2
)
}
fmt
.
Println
(
"
\n
For a complete list, visit http://coreybutler.github.io/nodedistro"
)
//
fmt.Println("\nFor a complete list, visit http://coreybutler.github.io/nodedistro")
}
}
...
...
@@ -465,6 +471,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 http://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 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."
)
...
...
@@ -477,17 +485,7 @@ func help() {
// Given a node.js version, returns the associated npm version
func
getNpmVersion
(
nodeversion
string
)
string
{
// Get raw text
text
:=
web
.
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
{})
npm
,
_
,
_
:=
node
.
GetAvailabeVersions
()
return
npm
[
nodeversion
]
.
(
string
)
}
...
...
@@ -505,6 +503,7 @@ func updateRootDir(path string) {
func
saveSettings
()
{
content
:=
"root: "
+
strings
.
Trim
(
env
.
root
,
"
\n\r
"
)
+
"
\r\n
arch: "
+
strings
.
Trim
(
env
.
arch
,
"
\n\r
"
)
+
"
\r\n
proxy: "
+
strings
.
Trim
(
env
.
proxy
,
"
\n\r
"
)
+
"
\r\n
originalpath: "
+
strings
.
Trim
(
env
.
originalpath
,
"
\n\r
"
)
+
"
\r\n
originalversion: "
+
strings
.
Trim
(
env
.
originalversion
,
"
\n\r
"
)
content
=
content
+
"node_mirror: "
+
strings
.
Trim
(
env
.
node_mirror
,
"
\n\r
"
)
+
"npm_mirror: "
+
strings
.
Trim
(
env
.
npm_mirror
,
"
\n\r
"
)
ioutil
.
WriteFile
(
env
.
settings
,
[]
byte
(
content
),
0644
)
}
...
...
@@ -525,6 +524,10 @@ func Setup() {
env
.
originalversion
=
strings
.
Trim
(
regexp
.
MustCompile
(
"originalversion:"
)
.
ReplaceAllString
(
line
,
""
),
"
\r\n
"
)
}
else
if
strings
.
Contains
(
line
,
"arch:"
){
env
.
arch
=
strings
.
Trim
(
regexp
.
MustCompile
(
"arch:"
)
.
ReplaceAllString
(
line
,
""
),
"
\r\n
"
)
}
else
if
strings
.
Contains
(
line
,
"node_mirror:"
){
env
.
node_mirror
=
strings
.
Trim
(
regexp
.
MustCompile
(
"node_mirror:"
)
.
ReplaceAllString
(
line
,
""
),
"
\r\n
"
)
}
else
if
strings
.
Contains
(
line
,
"npm_mirror:"
){
env
.
npm_mirror
=
strings
.
Trim
(
regexp
.
MustCompile
(
"npm_mirror:"
)
.
ReplaceAllString
(
line
,
""
),
"
\r\n
"
)
}
else
if
strings
.
Contains
(
line
,
"proxy:"
){
env
.
proxy
=
strings
.
Trim
(
regexp
.
MustCompile
(
"proxy:"
)
.
ReplaceAllString
(
line
,
""
),
"
\r\n
"
)
if
env
.
proxy
!=
"none"
&&
env
.
proxy
!=
""
{
...
...
@@ -535,7 +538,7 @@ func Setup() {
}
}
}
web
.
SetMirrors
(
env
.
node_mirror
,
env
.
npm_mirror
)
env
.
arch
=
arch
.
Validate
(
env
.
arch
)
// Make sure the directories exist
...
...
src/nvm/node/node.go
浏览文件 @
39a1bea3
...
...
@@ -17,7 +17,6 @@ import(
* Returns version, architecture
*/
func
GetCurrentVersion
()
(
string
,
string
)
{
cmd
:=
exec
.
Command
(
"node"
,
"-v"
)
str
,
err
:=
cmd
.
Output
()
if
err
==
nil
{
...
...
@@ -109,24 +108,51 @@ func (s BySemanticVersion) Less(i, j int) bool {
return
v1
.
GTE
(
v2
)
}
func
GetAvailabeVersions
()
(
map
[
string
]
interface
{},
map
[
string
]
interface
{},
map
[
string
]
interface
{}){
// Check the service to make sure the version is available
// modified by lzm at 4-7-2016, to chinese guys github maybe blocked at anytime.why not use the http://nodejs.org/dist/index.json?
//text := web.GetRemoteTextFile("https://raw.githubusercontent.com/coreybutler/nodedistro/master/nodeversions.json")
url
:=
web
.
GetFullNodeUrl
(
"index.json"
)
text
:=
web
.
GetRemoteTextFile
(
url
)
// Parse
var
data
interface
{}
json
.
Unmarshal
([]
byte
(
text
),
&
data
);
//body := data.(map[string]interface{})
//_all := body["all"]
//_stable := body["stable"]
//_unstable := body["unstable"]
//allkeys := _all.(map[string]interface{})
//stablekeys := _stable.(map[string]interface{})
//unstablekeys := _unstable.(map[string]interface{})
body
:=
data
.
([]
interface
{})
allkeys
:=
make
(
map
[
string
]
interface
{})
stablekeys
:=
make
(
map
[
string
]
interface
{})
unstablekeys
:=
make
(
map
[
string
]
interface
{})
for
_
,
temp
:=
range
body
{
item
:=
temp
.
(
map
[
string
]
interface
{})
key
:=
strings
.
TrimLeft
(
item
[
"version"
]
.
(
string
),
"v"
)
value
:=
item
[
"npm"
]
if
value
!=
nil
{
allkeys
[
key
]
=
value
.
(
string
)
version
,
_
:=
semver
.
New
(
key
)
if
(
version
.
Major
!=
0
&&
version
.
Major
%
2
==
0
)
||
version
.
Minor
%
2
==
0
{
stablekeys
[
key
]
=
value
.
(
string
)
}
else
{
unstablekeys
[
key
]
=
value
.
(
string
)
}
}
}
return
allkeys
,
stablekeys
,
unstablekeys
}
func
GetAvailable
()
([]
string
,
[]
string
,
[]
string
)
{
all
:=
make
([]
string
,
0
)
stable
:=
make
([]
string
,
0
)
unstable
:=
make
([]
string
,
0
)
// Check the service to make sure the version is available
text
:=
web
.
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"
]
_stable
:=
body
[
"stable"
]
_unstable
:=
body
[
"unstable"
]
allkeys
:=
_all
.
(
map
[
string
]
interface
{})
stablekeys
:=
_stable
.
(
map
[
string
]
interface
{})
unstablekeys
:=
_unstable
.
(
map
[
string
]
interface
{})
allkeys
,
stablekeys
,
unstablekeys
:=
GetAvailabeVersions
()
for
nodev
,
_
:=
range
allkeys
{
all
=
append
(
all
,
nodev
)
...
...
src/nvm/web/web.go
浏览文件 @
39a1bea3
...
...
@@ -14,6 +14,8 @@ import(
)
var
client
=
&
http
.
Client
{}
var
nodeBaseAddress
=
"http://nodejs.org/dist/"
var
npmBaseAddress
=
"https://github.com/npm/npm/archive/"
func
SetProxy
(
p
string
){
if
p
!=
""
&&
p
!=
"none"
{
...
...
@@ -24,6 +26,29 @@ func SetProxy(p string){
}
}
func
SetMirrors
(
node_mirror
string
,
npm_mirror
string
){
if
node_mirror
!=
""
&&
node_mirror
!=
"none"
{
nodeBaseAddress
=
node_mirror
;
if
strings
.
ToLower
(
nodeBaseAddress
[
0
:
4
])
!=
"http"
{
nodeBaseAddress
=
"http://"
+
nodeBaseAddress
}
}
if
npm_mirror
!=
""
&&
npm_mirror
!=
"none"
{
npmBaseAddress
=
npm_mirror
;
if
strings
.
ToLower
(
npmBaseAddress
[
0
:
4
])
!=
"http"
{
npmBaseAddress
=
"http://"
+
npmBaseAddress
}
}
}
func
GetFullNodeUrl
(
path
string
)
string
{
return
nodeBaseAddress
+
path
;
}
func
GetFullNpmUrl
(
path
string
)
string
{
return
npmBaseAddress
+
path
;
}
func
Download
(
url
string
,
target
string
)
bool
{
output
,
err
:=
os
.
Create
(
target
)
...
...
@@ -99,7 +124,8 @@ func GetNodeJS(root string, v string, a string) bool {
}
func
GetNpm
(
root
string
,
v
string
)
bool
{
url
:=
"https://github.com/npm/npm/archive/v"
+
v
+
".zip"
//url := "https://github.com/npm/npm/archive/v"+v+".zip"
url
:=
GetFullNpmUrl
(
"v"
+
v
+
".zip"
)
// temp directory to download the .zip file
tempDir
:=
root
+
"
\\
temp"
...
...
@@ -160,15 +186,12 @@ func IsNode64bitAvailable(v string) bool {
}
func
getNodeUrl
(
v
string
,
vpre
string
)
string
{
url
:=
"http://nodejs.org/dist/v"
+
v
+
"/"
+
vpre
+
"/node.exe"
//url := "http://nodejs.org/dist/v"+v+"/" + vpre + "/node.exe"
url
:=
GetFullNodeUrl
(
"v"
+
v
+
"/"
+
vpre
+
"/node.exe"
)
// Check online to see if a 64 bit version exists
res
,
err
:=
client
.
Head
(
url
)
_
,
err
:=
client
.
Head
(
url
)
if
err
!=
nil
{
return
""
}
if
res
.
StatusCode
==
200
{
return
url
}
else
{
return
""
}
return
url
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录