Skip to content

Commit c75887d

Browse files
authored
Migrate front-end from vue2+js to vue3+ts
1 parent 01d57d8 commit c75887d

35 files changed

+7218
-8918
lines changed

.circleci/config.yml

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ version: 2
22
jobs:
33
frontend:
44
docker:
5-
- image: circleci/node:16.13.1
5+
- image: cimg/node:lts
66
steps:
77
- checkout
88
- run:
99
name: "Install dependencies"
10-
command: yarn install
10+
working_directory: frontend
11+
command: npm install
1112
- run:
1213
name: "Build"
13-
command: yarn build
14+
working_directory: frontend
15+
command: npm run build
1416
- persist_to_workspace:
1517
root: .
1618
paths:
17-
- dist/*
19+
- frontend/dist/*
1820

1921
backend:
2022
docker:
21-
- image: circleci/golang:1.17
22-
23-
working_directory: /go/src/github.com/RoboCup-SSL/ssl-vision-client
23+
- image: cimg/go:1.20
2424
steps:
2525
- checkout
2626
- attach_workspace:
@@ -30,10 +30,9 @@ jobs:
3030
- run:
3131
working_directory: cmd/ssl-vision-client
3232
command: |
33-
go get -v github.com/gobuffalo/packr/packr
34-
GOOS=linux GOARCH=amd64 packr build -o ../../release/ssl-vision-client_linux_amd64
35-
GOOS=darwin GOARCH=amd64 packr build -o ../../release/ssl-vision-client_darwin_amd64
36-
GOOS=windows GOARCH=amd64 packr build -o ../../release/ssl-vision-client_windows_amd64.exe
33+
GOOS=linux GOARCH=amd64 go build -o ../../release/ssl-vision-client_linux_amd64
34+
GOOS=darwin GOARCH=amd64 go build -o ../../release/ssl-vision-client_darwin_amd64
35+
GOOS=windows GOARCH=amd64 go build -o ../../release/ssl-vision-client_windows_amd64.exe
3736
- run:
3837
working_directory: cmd/ssl-vision-cli
3938
command: |
@@ -47,25 +46,43 @@ jobs:
4746

4847
publish-github-release:
4948
docker:
50-
- image: circleci/golang:1.17
49+
- image: cimg/go:1.20
5150
steps:
5251
- attach_workspace:
5352
at: .
5453
- run:
5554
name: "Prepare artifacts"
5655
working_directory: release
5756
command: |
58-
mv ssl-vision-client_linux_amd64 ssl-vision-client_${CIRCLE_TAG}_linux_amd64
59-
mv ssl-vision-client_darwin_amd64 ssl-vision-client_${CIRCLE_TAG}_darwin_amd64
60-
mv ssl-vision-client_windows_amd64.exe ssl-vision-client_${CIRCLE_TAG}_windows_amd64.exe
61-
mv ssl-vision-cli_linux_amd64 ssl-vision-cli_${CIRCLE_TAG}_linux_amd64
62-
mv ssl-vision-cli_darwin_amd64 ssl-vision-cli_${CIRCLE_TAG}_darwin_amd64
63-
mv ssl-vision-cli_windows_amd64.exe ssl-vision-cli_${CIRCLE_TAG}_windows_amd64.exe
57+
mkdir gh
58+
mv ssl-vision-client_linux_amd64 gh/ssl-vision-client_${CIRCLE_TAG}_linux_amd64
59+
mv ssl-vision-client_darwin_amd64 gh/ssl-vision-client_${CIRCLE_TAG}_darwin_amd64
60+
mv ssl-vision-client_windows_amd64.exe gh/ssl-vision-client_${CIRCLE_TAG}_windows_amd64.exe
61+
mv ssl-vision-cli_linux_amd64 gh/ssl-vision-cli_${CIRCLE_TAG}_linux_amd64
62+
mv ssl-vision-cli_darwin_amd64 gh/ssl-vision-cli_${CIRCLE_TAG}_darwin_amd64
63+
mv ssl-vision-cli_windows_amd64.exe gh/ssl-vision-cli_${CIRCLE_TAG}_windows_amd64.exe
6464
- run:
6565
name: "Publish Release on GitHub"
6666
command: |
67-
go get github.com/tcnksm/ghr
68-
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${CIRCLE_TAG} ./release/
67+
go install github.com/tcnksm/[email protected]
68+
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${CIRCLE_TAG} ./release/gh/
69+
70+
docker:
71+
docker:
72+
- image: cimg/base:2023.02
73+
steps:
74+
- checkout
75+
- setup_remote_docker:
76+
version: 20.10.18
77+
- run: |
78+
TAG=${CIRCLE_TAG:1}
79+
TAG=${TAG:-latest}
80+
docker build -t robocupssl/ssl-vision-client:$TAG .
81+
docker login -u "${DOCKER_HUB_USERNAME}" -p "${DOCKER_HUB_PASSWORD}"
82+
docker push robocupssl/ssl-vision-client:$TAG
83+
docker build -t robocupssl/ssl-vision-cli:$TAG .
84+
docker login -u "${DOCKER_HUB_USERNAME}" -p "${DOCKER_HUB_PASSWORD}"
85+
docker push robocupssl/ssl-vision-cli:$TAG
6986
7087
workflows:
7188
version: 2
@@ -82,10 +99,18 @@ workflows:
8299
tags:
83100
only: /.*/
84101
- publish-github-release:
102+
context: github
85103
requires:
86104
- backend
87105
filters:
88106
branches:
89107
ignore: /.*/
90108
tags:
91109
only: /^v.*/
110+
- docker:
111+
context: docker hub
112+
filters:
113+
branches:
114+
only: master
115+
tags:
116+
only: /^v.*/

.github/renovate.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": [
3+
"config:base",
4+
"schedule:monthly"
5+
]
6+
}

README.md

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,27 @@ By default, the UI is available at http://localhost:8082
2222

2323
## Development
2424

25-
### Requirements
26-
You need to install following dependencies first:
27-
* Go >= 1.17
28-
* Node >= 10
29-
* Yarn
30-
31-
### Prepare
32-
Download and install to [GOPATH](https://github.com/golang/go/wiki/GOPATH):
33-
```bash
34-
go get -u github.com/RoboCup-SSL/ssl-vision-client/...
35-
```
36-
Switch to project root directory
37-
```bash
38-
cd $GOPATH/src/github.com/RoboCup-SSL/ssl-vision-client/
39-
```
40-
Download dependencies for frontend
41-
```bash
42-
yarn install
43-
```
25+
You need to install following dependencies first:
26+
27+
* Go
28+
* Node
29+
30+
See [.circleci/config.yml](.circleci/config.yml) for required versions.
31+
32+
### Frontend
33+
34+
See [frontend/README.md](frontend/README.md)
4435

4536
### Run
37+
4638
Run the backend:
47-
```bash
48-
go run cmd/ssl-vision-client/main.go
49-
```
5039

51-
Run the UI:
5240
```bash
53-
# compile and hot-reload
54-
yarn serve
41+
go run cmd/ssl-vision-client/main.go
5542
```
56-
Or use the provided IntelliJ run configurations.
5743

5844
### Build self-contained release binary
59-
First, build the UI resources
60-
```bash
61-
# compile and minify UI
62-
yarn build
63-
```
64-
Then build the backend with `packr`
45+
6546
```bash
66-
# get packr
67-
go get github.com/gobuffalo/packr/packr
68-
# install the binary
69-
cd cmd/ssl-vision-client
70-
packr install
47+
./install.sh
7148
```

babel.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

cmd/ssl-vision-client/main.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package main
22

33
import (
44
"flag"
5+
"github.com/RoboCup-SSL/ssl-vision-client/frontend"
56
"github.com/RoboCup-SSL/ssl-vision-client/pkg/client"
67
"github.com/RoboCup-SSL/ssl-vision-client/pkg/tracked"
78
"github.com/RoboCup-SSL/ssl-vision-client/pkg/vision"
89
"github.com/RoboCup-SSL/ssl-vision-client/pkg/visualization"
9-
"github.com/gobuffalo/packr"
1010
"log"
1111
"net/http"
1212
"strings"
@@ -23,7 +23,10 @@ func main() {
2323
flag.Parse()
2424

2525
setupVisionClient()
26-
setupUi()
26+
frontend.HandleUi()
27+
28+
log.Printf("UI is available at %v", formattedAddress())
29+
2730
err := http.ListenAndServe(*address, nil)
2831
if err != nil {
2932
log.Fatal(err)
@@ -85,22 +88,9 @@ func parseSkipInterfaces() []string {
8588
return strings.Split(*skipInterfaces, ",")
8689
}
8790

88-
func setupUi() {
89-
box := packr.NewBox("../../dist")
90-
91-
withResponseHeaders := func(h http.Handler) http.HandlerFunc {
92-
return func(w http.ResponseWriter, r *http.Request) {
93-
// Set some header.
94-
w.Header().Add("Access-Control-Allow-Origin", "*")
95-
// Serve with the actual handler.
96-
h.ServeHTTP(w, r)
97-
}
98-
}
99-
100-
http.Handle("/", withResponseHeaders(http.FileServer(box)))
101-
if box.Has("index.html") {
102-
log.Printf("UI is available at http://%v", *address)
103-
} else {
104-
log.Print("Backend-only version started. Run the UI separately or get a binary that has the UI included")
91+
func formattedAddress() string {
92+
if strings.HasPrefix(*address, ":") {
93+
return "http://localhost" + *address
10594
}
95+
return "http://" + *address
10696
}

frontend/.eslintrc.cjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-env node */
2+
require('@rushstack/eslint-patch/modern-module-resolution')
3+
4+
module.exports = {
5+
root: true,
6+
'extends': [
7+
'plugin:vue/vue3-essential',
8+
'eslint:recommended',
9+
'@vue/eslint-config-typescript'
10+
],
11+
parserOptions: {
12+
ecmaVersion: 'latest'
13+
}
14+
}

frontend/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
/cypress/videos/
18+
/cypress/screenshots/
19+
20+
# Editor directories and files
21+
.vscode/*
22+
!.vscode/extensions.json
23+
.idea
24+
*.suo
25+
*.ntvs*
26+
*.njsproj
27+
*.sln
28+
*.sw?

frontend/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frontend
2+
3+
## Project Setup
4+
5+
```sh
6+
npm install
7+
```
8+
9+
### Compile and Hot-Reload for Development
10+
11+
```sh
12+
npm run dev
13+
```
14+
15+
### Type-Check, Compile and Minify for Production
16+
17+
```sh
18+
npm run build
19+
```
20+
21+
### Lint with [ESLint](https://eslint.org/)
22+
23+
```sh
24+
npm run lint
25+
```

frontend/embed.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package frontend
2+
3+
import (
4+
"embed"
5+
"io/fs"
6+
"net/http"
7+
)
8+
9+
//go:embed dist/*
10+
var content embed.FS
11+
12+
func HandleUi() {
13+
dist, err := fs.Sub(content, "dist")
14+
if err != nil {
15+
panic(err)
16+
}
17+
18+
withResponseHeaders := func(h http.Handler) http.HandlerFunc {
19+
return func(w http.ResponseWriter, r *http.Request) {
20+
// Set some header.
21+
w.Header().Add("Access-Control-Allow-Origin", "*")
22+
// Serve with the actual handler.
23+
h.ServeHTTP(w, r)
24+
}
25+
}
26+
27+
http.Handle("/", withResponseHeaders(http.FileServer(http.FS(dist))))
28+
}

frontend/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

0 commit comments

Comments
 (0)