Improve JS workflow

Now we can launch Chrome from vscode and also set breakpoints and have
them be respected.

Work still to be done:

The "Launch Chrome" task should compile the typescript stuff.

It takes too long to rebuild the typescript stuff. It is bothersome
during development. If we can work around that with webpack, that's
great. If generating the gotty bundle is what makes it all time
consuming, we should skip the bundle generation for development and
change the index.html to point to a not-bundled version.

Partially fixes #3
This commit is contained in:
Søren L. Hansen 2022-11-26 14:51:10 -08:00
parent 48c794023a
commit 29c20dca06
9 changed files with 2661 additions and 130 deletions

13
.vscode/launch.json vendored
View File

@ -7,10 +7,21 @@
{ {
"name": "Launch GoTTY", "name": "Launch GoTTY",
"type": "go", "type": "go",
"buildFlags": "-tags=dev",
"request": "launch", "request": "launch",
"mode": "debug", "mode": "debug",
"program": "${workspaceFolder}", "program": "${workspaceFolder}",
"args": ["-a", "127.0.0.1", "-w", "bash"] "args": ["-a", "127.0.0.1", "-w", "bash"]
} },
{
"name": "Launch Chrome",
"type": "chrome",
"url": "http://127.0.0.1:8080",
"webRoot": "${workspaceFolder}/js",
"outFiles": [
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
],
},
] ]
} }

View File

@ -2,7 +2,14 @@ OUTPUT_DIR = ./builds
GIT_COMMIT = `git rev-parse HEAD | cut -c1-7` GIT_COMMIT = `git rev-parse HEAD | cut -c1-7`
VERSION = $(shell git describe --tags) VERSION = $(shell git describe --tags)
BUILD_OPTIONS = -ldflags "-X main.Version=$(VERSION)" BUILD_OPTIONS = -ldflags "-X main.Version=$(VERSION)"
ifeq ($(DEV), 1)
BUILD_OPTIONS += -tags dev
WEBPACK_MODE = development
else
WEBPACK_MODE = production WEBPACK_MODE = production
endif
export CGO_ENABLED=0 export CGO_ENABLED=0
gotty: main.go assets server/*.go webtty/*.go backend/*.go Makefile gotty: main.go assets server/*.go webtty/*.go backend/*.go Makefile

View File

@ -1,3 +1,5 @@
//go:build !dev
package bindata package bindata
import "embed" import "embed"

28
bindata/bindata_dev.go Normal file
View File

@ -0,0 +1,28 @@
//go:build dev
package bindata
import (
"io"
"io/fs"
"os"
)
type GottyFS struct {
fs.FS
}
var Fs GottyFS
func (gfs *GottyFS) ReadFile(name string) ([]byte, error) {
fp, err := gfs.Open(name)
if err != nil {
return nil, err
}
return io.ReadAll(fp)
}
func init() {
Fs = GottyFS{os.DirFS("bindata")}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2728
js/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,7 @@
"preact": "^10.7.1", "preact": "^10.7.1",
"react-bootstrap": "^2.2.3", "react-bootstrap": "^2.2.3",
"style-loader": "^2.0.0", "style-loader": "^2.0.0",
"webpack-dev-server": "^4.11.1",
"xterm": "^4.12.0", "xterm": "^4.12.0",
"xterm-addon-fit": "^0.5.0", "xterm-addon-fit": "^0.5.0",
"xterm-addon-web-links": "^0.4.0", "xterm-addon-web-links": "^0.4.0",

View File

@ -10,7 +10,7 @@ module.exports = {
output: { output: {
path: path.resolve(__dirname, '../bindata/static/js/'), path: path.resolve(__dirname, '../bindata/static/js/'),
}, },
devtool: "source-map", devtool: "inline-source-map",
resolve: { resolve: {
extensions: [".ts", ".tsx", ".js"], extensions: [".ts", ".tsx", ".js"],
}, },