Skip to content

Commit 5f97125

Browse files
jamalcgopherbot
authored andcommitted
godev/content: use esbuild devtool for styles and scripts
To match the behavior of go telemetry view and allow us to remove the esbuild dependency from internal/content, the static assets are generated with the esbuild devtool. Change-Id: If1b798f12e28b33142cb3c325b8d05f17521a674 Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/524198 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Jamal Carvalho <[email protected]> Auto-Submit: Jamal Carvalho <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 5e8de8b commit 5f97125

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+361
-197
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
],
77
"parser": "@typescript-eslint/parser",
88
"plugins": ["@typescript-eslint"],
9-
"root": true
9+
"root": true,
10+
"ignorePatterns": ["*.min.js"]
1011
}

.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.stylelintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
},
77
"unit-disallowed-list": ["px"],
88
"selector-class-pattern": "^[a-zA-Z\\-]+$"
9-
}
9+
},
10+
"ignoreFiles": ["**/*.min.css"]
1011
}

CONTRIBUTING.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ It is the work of hundreds of contributors. We appreciate your help!
66

77
## Filing issues
88

9-
When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions:
9+
When [filing an issue](https://golang.org/issue/new), make sure to answer these
10+
five questions:
1011

1112
1. What version of Go are you using (`go version`)?
1213
2. What operating system and processor architecture are you using?
1314
3. What did you do?
1415
4. What did you expect to see?
1516
5. What did you see instead?
1617

17-
General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
18-
The gophers there will answer or ask you to file an issue if you've tripped over a bug.
18+
General questions should go to the
19+
[golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead
20+
of the issue tracker. The gophers there will answer or ask you to file an issue
21+
if you've tripped over a bug.
1922

2023
## Contributing code
2124

22-
Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
23-
before sending patches.
25+
Please read the
26+
[Contribution Guidelines](https://golang.org/doc/contribute.html) before sending
27+
patches.
2428

25-
Unless otherwise noted, the Go source files are distributed under
26-
the BSD-style license found in the LICENSE file.
29+
Unless otherwise noted, the Go source files are distributed under the BSD-style
30+
license found in the LICENSE file.

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
This repository holds the Go Telemetry server code and libraries.
44

5-
## TypeScript Support
6-
7-
TypeScript files served from content directories are transformed into
8-
JavaScript. Reference .ts files in html templates as module code.
9-
10-
`<script type="module" src="/filename.ts">`
11-
125
## Linting & Formatting
136

147
This repository uses [eslint](https://eslint.org/) to format TS files,
@@ -38,5 +31,5 @@ This repository uses Gerrit for code changes. To learn how to submit changes to
3831
this repository, see https://golang.org/doc/contribute.html.
3932

4033
The main issue tracker for the time repository is located at
41-
https://github.com/golang/go/issues. Prefix your issue with "x/telemetry:" in the
42-
subject line, so it is easy to find.
34+
https://github.com/golang/go/issues. Prefix your issue with "x/telemetry:" in
35+
the subject line, so it is easy to find.

cmd/gotelemetry/internal/view/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ and active counter files.
77

88
## Development
99

10-
The static files are generated with a generator command in
11-
[`./main.go`](./main.go). You can edit the source files and run go generate to
12-
rebuild them.
10+
The static files are generated with a generator command. You can edit the source
11+
files and run go generate to rebuild them.
1312

14-
go generate ./cmd/gotelemetry/view
13+
go generate ./content
1514

1615
Running the server with the `--dev` flag will watch and rebuild the static files
1716
on save.

cmd/gotelemetry/internal/view/static/index.min.css

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

cmd/gotelemetry/internal/view/view.go

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package view
88

99
import (
1010
"bytes"
11-
"embed"
1211
"encoding/json"
1312
"flag"
1413
"fmt"
@@ -19,7 +18,6 @@ import (
1918
"net"
2019
"net/http"
2120
"os"
22-
"os/exec"
2321
"path"
2422
"sort"
2523
"strconv"
@@ -30,27 +28,32 @@ import (
3028
"golang.org/x/telemetry/cmd/gotelemetry/internal/browser"
3129
"golang.org/x/telemetry/internal/config"
3230
"golang.org/x/telemetry/internal/configstore"
31+
contentfs "golang.org/x/telemetry/internal/content"
3332
tcounter "golang.org/x/telemetry/internal/counter"
3433
it "golang.org/x/telemetry/internal/telemetry"
34+
"golang.org/x/telemetry/internal/unionfs"
3535
)
3636

3737
var (
3838
addr = flag.String("addr", "localhost:4040", "server listens on the given TCP network address")
3939
dev = flag.Bool("dev", false, "rebuild static assets on save")
4040
fsConfig = flag.String("config", "", "load a config from the filesystem")
4141
open = flag.Bool("open", true, "open the browser to the server address")
42-
43-
//go:embed *
44-
content embed.FS
4542
)
4643

4744
func Start() {
4845
flag.Parse()
49-
var fsys fs.FS = content
46+
var fsys fs.FS = contentfs.FS
5047
if *dev {
51-
fsys = os.DirFS("cmd/gotelemetry/internal/view")
52-
watchStatic()
48+
fsys = os.DirFS("internal/content")
49+
contentfs.WatchStatic()
50+
}
51+
var err error
52+
fsys, err = unionfs.Sub(fsys, "gotelemetryview", "shared")
53+
if err != nil {
54+
log.Fatal(err)
5355
}
56+
5457
mux := http.NewServeMux()
5558
mux.Handle("/", handleIndex(fsys))
5659
listener, err := net.Listen("tcp", *addr)
@@ -65,25 +68,6 @@ func Start() {
6568
log.Fatal(http.Serve(listener, mux))
6669
}
6770

68-
//go:generate go run golang.org/x/telemetry/godev/devtools/cmd/esbuild --outdir static
69-
70-
// watchStatic runs the same command as the generator above when the server is
71-
// started in dev mode, rebuilding static assets on save.
72-
func watchStatic() {
73-
cmd := exec.Command("go", "run", "golang.org/x/telemetry/godev/devtools/cmd/esbuild", "--outdir", "static", "--watch")
74-
cmd.Dir = "cmd/gotelemetry/internal/view"
75-
cmd.Stderr = os.Stderr
76-
cmd.Stdout = os.Stdout
77-
if err := cmd.Start(); err != nil {
78-
log.Fatal(err)
79-
}
80-
go func() {
81-
if err := cmd.Wait(); err != nil {
82-
log.Fatal(err)
83-
}
84-
}()
85-
}
86-
8771
type page struct {
8872
// Config is the config used to render the requested page.
8973
Config *config.Config

godev/cmd/telemetrygodev/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
For local development, simply build and run. It serves on localhost:8080.
66

7-
go run ./cmd/telemetrygodev
7+
go run ./godev/cmd/telemetrygodev
88

99
By default, the server will use the filesystem for storage object I/O. Run the
1010
cloud storage emulator and use the -gcs flag to use the Cloud Storage API.
1111

12-
./devtools/localstorage.sh
13-
go run ./cmd/telemetrygodev --gcs
12+
./godev/devtools/localstorage.sh
13+
go run ./godev/cmd/telemetrygodev --gcs
1414

1515
### Environment Variables
1616

godev/cmd/telemetrygodev/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import (
2424
"golang.org/x/exp/slog"
2525
"golang.org/x/mod/semver"
2626
"golang.org/x/telemetry"
27-
"golang.org/x/telemetry/godev"
2827
"golang.org/x/telemetry/godev/internal/config"
2928
"golang.org/x/telemetry/godev/internal/content"
3029
"golang.org/x/telemetry/godev/internal/middleware"
3130
"golang.org/x/telemetry/godev/internal/storage"
3231
tconfig "golang.org/x/telemetry/internal/config"
32+
contentfs "golang.org/x/telemetry/internal/content"
3333
"golang.org/x/telemetry/internal/unionfs"
3434
)
3535

@@ -209,11 +209,12 @@ func validate(r *telemetry.Report, cfg *tconfig.Config) error {
209209
}
210210

211211
func fsys(fromOS bool) fs.FS {
212-
var f fs.FS = godev.FS
212+
var f fs.FS = contentfs.FS
213213
if fromOS {
214-
f = os.DirFS(".")
214+
f = os.DirFS("internal/content")
215+
contentfs.WatchStatic()
215216
}
216-
f, err := unionfs.Sub(f, "content/telemetrygodev", "content/shared")
217+
f, err := unionfs.Sub(f, "telemetrygodev", "shared")
217218
if err != nil {
218219
log.Fatal(err)
219220
}

godev/cmd/worker/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ in generated the report and the location of the chart data.
1919

2020
For local development, simply build and run. It serves on localhost:8082.
2121

22-
go run ./cmd/worker
22+
go run ./godev/cmd/worker
2323

2424
By default, the server will use the filesystem for storage object I/O. Run the
2525
cloud storage emulator and use the -gcs flag to use the Cloud Storage API.
2626

27-
./devtools/localstorage.sh
28-
go run ./cmd/worker --gcs
27+
./godev/devtools/localstorage.sh
28+
go run ./godev/cmd/worker --gcs
2929

3030
### Environment Variables
3131

godev/cmd/worker/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import (
2121
"golang.org/x/exp/slog"
2222
"golang.org/x/mod/semver"
2323
"golang.org/x/telemetry"
24-
"golang.org/x/telemetry/godev"
2524
"golang.org/x/telemetry/godev/internal/config"
2625
"golang.org/x/telemetry/godev/internal/content"
2726
"golang.org/x/telemetry/godev/internal/middleware"
2827
"golang.org/x/telemetry/godev/internal/storage"
2928
tconfig "golang.org/x/telemetry/internal/config"
29+
contentfs "golang.org/x/telemetry/internal/content"
3030
"golang.org/x/telemetry/internal/unionfs"
3131
)
3232

@@ -447,11 +447,11 @@ func cutInt(x string) (n, rest string, ok bool) {
447447
}
448448

449449
func fsys(fromOS bool) fs.FS {
450-
var f fs.FS = godev.FS
450+
var f fs.FS = contentfs.FS
451451
if fromOS {
452-
f = os.DirFS(".")
452+
f = os.DirFS("internal/content")
453453
}
454-
f, err := unionfs.Sub(f, "content/worker", "content/shared")
454+
f, err := unionfs.Sub(f, "worker", "shared")
455455
if err != nil {
456456
log.Fatal(err)
457457
}

godev/content.go

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

godev/content/shared/favicon.ico

-5.55 KB
Binary file not shown.

0 commit comments

Comments
 (0)