aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2023-08-24 14:28:48 -0400
committerMichael Matloob <matloob@golang.org>2023-08-25 19:10:21 +0000
commitecfc750c92e7b14f5f963fa20865251bcdf5f2ca (patch)
treefa8b69d11c237fa3c1b7367d8ba02fafcc600879 /cmd
parentc1de6c58cffb7d62c85e8c9a41823f0d0015a9f9 (diff)
downloadgo-x-pkgsite-ecfc750c92e7b14f5f963fa20865251bcdf5f2ca.tar.xz
cmd/frontend: move typescript compile watching into main
To remove the dependency from cmd/pkgsite on to github.com/evanw/esbuild, this change moves the code that starts the watcher for recompiling typescript files into cmd/frontend. This means the dev mode functionality in cmd/pkgsite for watching and recompiling typescript files is gone. For golang/go#61399 Change-Id: If1325461de30dfd2f71b63d810cab8e9b4cdeb06 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/522735 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> kokoro-CI: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/frontend/main.go18
-rw-r--r--cmd/pkgsite/main.go1
2 files changed, 17 insertions, 2 deletions
diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go
index 2a05e14c..13324a3c 100644
--- a/cmd/frontend/main.go
+++ b/cmd/frontend/main.go
@@ -32,6 +32,7 @@ import (
"golang.org/x/pkgsite/internal/queue"
"golang.org/x/pkgsite/internal/queue/gcpqueue"
"golang.org/x/pkgsite/internal/source"
+ "golang.org/x/pkgsite/internal/static"
"golang.org/x/pkgsite/internal/vuln"
)
@@ -115,6 +116,22 @@ func main() {
log.Fatalf(ctx, "vuln.NewClient: %v", err)
}
staticSource := template.TrustedSourceFromFlag(flag.Lookup("static").Value)
+ if *devMode {
+ // In dev mode compile TypeScript files into minified JavaScript files
+ // and rebuild them on file changes.
+ if *staticFlag == "" {
+ panic("staticPath is empty in dev mode; cannot rebuild static files")
+ }
+ ctx := context.Background()
+ if err := static.Build(static.Config{
+ EntryPoint: *staticFlag + "/frontend",
+ Watch: true,
+ Bundle: true,
+ }); err != nil {
+ log.Error(ctx, err)
+ }
+ }
+
// TODO: Can we use a separate queue for the fetchServer and for the Server?
// It would help differentiate ownership.
fetchServer := &fetchserver.FetchServer{
@@ -128,7 +145,6 @@ func main() {
Queue: fetchQueue,
TemplateFS: template.TrustedFSFromTrustedSource(staticSource),
StaticFS: os.DirFS(*staticFlag),
- StaticPath: *staticFlag,
ThirdPartyFS: os.DirFS(*thirdPartyPath),
DevMode: *devMode,
LocalMode: *localMode,
diff --git a/cmd/pkgsite/main.go b/cmd/pkgsite/main.go
index 9bf74930..9f5eaefd 100644
--- a/cmd/pkgsite/main.go
+++ b/cmd/pkgsite/main.go
@@ -427,7 +427,6 @@ func newServer(getters []fetch.ModuleGetter, localModules []frontend.LocalModule
DevMode: *devMode,
LocalMode: true,
LocalModules: localModules,
- StaticPath: *staticFlag,
ThirdPartyFS: thirdparty.FS,
})
if err != nil {