This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support editing sail Dockerfile inside code-server
Closes #98 Only thing left to do is switch to using a output pane instead of a terminal and blocking the save on the dockerfile while the reload is in progress.
- Loading branch information
Showing
4 changed files
with
79 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
let reloadInProgress = false | ||
let tty | ||
window.addEventListener("ide-ready", (ev) => { | ||
window.ide.workbench.onFileSaved((ev) => { | ||
if (!ev.endsWith(".sail/Dockerfile")) { | ||
return | ||
} | ||
|
||
if (reloadInProgress) { | ||
alert("reload is still in progress") | ||
return | ||
} | ||
reloadInProgress = true | ||
|
||
const srv = window.ide.workbench.terminalService | ||
|
||
if (tty == null) { | ||
tty = srv.createTerminal({ | ||
name: "sail", | ||
isRendererOnly: true, | ||
}, false) | ||
} else { | ||
tty.clear() | ||
} | ||
let oldTTY = srv.getActiveInstance() | ||
srv.setActiveInstance(tty) | ||
|
||
const ws = new WebSocket("ws://" + location.host + "/sail/api/v1/reload") | ||
ws.onmessage = (ev) => { | ||
const msg = JSON.parse(ev.data) | ||
const out = atob(msg.v).replace(/\n/g, "\n\r") | ||
tty.write(out) | ||
} | ||
ws.onclose = (ev) => { | ||
if (ev.code === 1000) { | ||
srv.setActiveInstance(oldTTY) | ||
} else { | ||
alert("reload failed; please see logs in sail terminal") | ||
} | ||
reloadInProgress = false | ||
} | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package main | ||
|
||
//go:generate go run sail.js_gen.go | ||
const sailJS = "let reloadInProgress = false\nlet tty\nwindow.addEventListener(\"ide-ready\", (ev) => {\n window.ide.workbench.onFileSaved((ev) => {\n if (!ev.endsWith(\".sail/Dockerfile\")) {\n return\n }\n\n if (reloadInProgress) {\n alert(\"reload is still in progress\")\n return\n }\n reloadInProgress = true\n\n const srv = window.ide.workbench.terminalService\n\n if (tty == null) {\n tty = srv.createTerminal({\n name: \"sail\",\n isRendererOnly: true,\n }, false)\n } else {\n tty.clear()\n }\n let oldTTY = srv.getActiveInstance()\n srv.setActiveInstance(tty)\n\n const ws = new WebSocket(\"ws://\" + location.host + \"/sail/api/v1/reload\")\n ws.onmessage = (ev) => {\n const msg = JSON.parse(ev.data)\n const out = atob(msg.v).replace(/\\n/g, \"\\n\\r\")\n tty.write(out)\n }\n ws.onclose = (ev) => {\n if (ev.code == 1000) {\n srv.setActiveInstance(oldTTY)\n alert(\"success\")\n } else {\n alert(\"reload failed; please see logs in sail terminal\")\n }\n reloadInProgress = false\n }\n })\n})\n" |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
) | ||
|
||
func main() { | ||
sailJS, err := ioutil.ReadFile("sail.js") | ||
if err != nil { | ||
log.Fatalf("failed to read sail.js: %v", err) | ||
} | ||
|
||
err = ioutil.WriteFile("sail.js.go", genFile(sailJS), 0644) | ||
if err != nil { | ||
log.Fatalf("failed to write sail.js: %v", err) | ||
} | ||
} | ||
|
||
func genFile(sailJS []byte) []byte { | ||
tmpl := `package main | ||
//go:generate go run sail.js_gen.go | ||
const sailJS = %q | ||
` | ||
|
||
return []byte(fmt.Sprintf(tmpl, sailJS)) | ||
} |