Merge branch 'master' of https://github.com/b3log/wide
This commit is contained in:
commit
bd7eaff974
|
@ -262,7 +262,30 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if data["succ"].(bool) {
|
if !data["succ"].(bool) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
channelRet := map[string]interface{}{}
|
||||||
|
|
||||||
|
if nil != session.OutputWS[sid] {
|
||||||
|
// 在前端 output 中显示“开始构建”
|
||||||
|
|
||||||
|
channelRet["output"] = "go build"
|
||||||
|
channelRet["cmd"] = "pre-build"
|
||||||
|
|
||||||
|
wsChannel := session.OutputWS[sid]
|
||||||
|
|
||||||
|
err := wsChannel.Conn.WriteJSON(&channelRet)
|
||||||
|
if nil != err {
|
||||||
|
glog.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新通道最近使用时间
|
||||||
|
wsChannel.Time = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
reader := io.MultiReader(stdout, stderr)
|
reader := io.MultiReader(stdout, stderr)
|
||||||
|
|
||||||
if err := cmd.Start(); nil != err {
|
if err := cmd.Start(); nil != err {
|
||||||
|
@ -283,13 +306,13 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
count, _ := reader.Read(buf)
|
count, _ := reader.Read(buf)
|
||||||
|
|
||||||
channelRet := map[string]interface{}{}
|
channelRet := map[string]interface{}{}
|
||||||
channelRet["output"] = string(buf[:count])
|
|
||||||
channelRet["cmd"] = "build"
|
channelRet["cmd"] = "build"
|
||||||
channelRet["executable"] = executable
|
channelRet["executable"] = executable
|
||||||
|
|
||||||
if 0 == count { // 说明构建成功,没有错误信息输出
|
if 0 == count { // 说明构建成功,没有错误信息输出
|
||||||
// 设置下一次执行命令(前端会根据这个发送请求)
|
// 设置下一次执行命令(前端会根据这个发送请求)
|
||||||
channelRet["nextCmd"] = args["nextCmd"]
|
channelRet["nextCmd"] = args["nextCmd"]
|
||||||
|
channelRet["output"] = "Build Succ"
|
||||||
|
|
||||||
go func() { // 运行 go install,生成的库用于 gocode lib-path
|
go func() { // 运行 go install,生成的库用于 gocode lib-path
|
||||||
cmd := exec.Command("go", "install")
|
cmd := exec.Command("go", "install")
|
||||||
|
@ -305,6 +328,8 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
} else { // 构建失败
|
} else { // 构建失败
|
||||||
// 解析错误信息,返回给编辑器 gutter lint
|
// 解析错误信息,返回给编辑器 gutter lint
|
||||||
errOut := string(buf[:count])
|
errOut := string(buf[:count])
|
||||||
|
channelRet["output"] = "Build Failed\n" + errOut
|
||||||
|
|
||||||
lines := strings.Split(errOut, "\n")
|
lines := strings.Split(errOut, "\n")
|
||||||
|
|
||||||
if lines[0][0] == '#' {
|
if lines[0][0] == '#' {
|
||||||
|
@ -362,7 +387,6 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
}(rand.Int())
|
}(rand.Int())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// go install.
|
// go install.
|
||||||
func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
|
func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -330,6 +330,8 @@ var wide = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: 重构成 switch-case
|
||||||
|
|
||||||
if ('run' === data.cmd) { // 正在运行
|
if ('run' === data.cmd) { // 正在运行
|
||||||
wide.fillOutput($('.bottom-window-group .output').text() + data.output);
|
wide.fillOutput($('.bottom-window-group .output').text() + data.output);
|
||||||
wide.curProcessId = data.pid;
|
wide.curProcessId = data.pid;
|
||||||
|
@ -358,6 +360,8 @@ var wide = {
|
||||||
CodeMirror.signal(wide.curEditor, "change", wide.curEditor);
|
CodeMirror.signal(wide.curEditor, "change", wide.curEditor);
|
||||||
} else if ('go get' === data.cmd || 'go install' === data.cmd) {
|
} else if ('go get' === data.cmd || 'go install' === data.cmd) {
|
||||||
wide.fillOutput($('.bottom-window-group .output').text() + data.output);
|
wide.fillOutput($('.bottom-window-group .output').text() + data.output);
|
||||||
|
} else if ('pre-build' === data.cmd) {
|
||||||
|
wide.fillOutput(data.output);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
outputWS.onclose = function (e) {
|
outputWS.onclose = function (e) {
|
||||||
|
|
Loading…
Reference in New Issue