Eliminate Python dependency: embed frontend assets in odoo-go

- Copy all OWL frontend assets (JS/CSS/XML/fonts/images) into frontend/
  directory (2925 files, 43MB) — no more runtime reads from Python Odoo
- Replace OdooAddonsPath config with FrontendDir pointing to local frontend/
- Rewire bundle.go, static.go, templates.go, webclient.go to read from
  frontend/ instead of external Python Odoo addons directory
- Auto-detect frontend/ and build/ dirs relative to binary in main.go
- Delete obsolete Python helper scripts (tools/*.py)

The Go server is now fully self-contained: single binary + frontend/ folder.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Marc
2026-03-31 23:09:12 +02:00
parent 0ed29fe2fd
commit 8741282322
2933 changed files with 280644 additions and 264 deletions

View File

@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
)
// handleStatic serves static files from Odoo addon directories.
@@ -16,6 +17,16 @@ func (s *Server) handleStatic(w http.ResponseWriter, r *http.Request) {
return
}
// Serve the compiled XML templates bundle from memory (generated at
// startup by compileXMLTemplates) instead of reading the pre-compiled
// file from the build directory. This replaces the Python build step.
if r.URL.Path == "/web/static/src/xml_templates_bundle.js" {
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
w.Header().Set("Cache-Control", "public, max-age=3600")
w.Write([]byte(s.xmlTemplateBundle))
return
}
path := strings.TrimPrefix(r.URL.Path, "/")
parts := strings.SplitN(path, "/", 3)
if len(parts) < 3 || parts[1] != "static" {
@@ -32,8 +43,8 @@ func (s *Server) handleStatic(w http.ResponseWriter, r *http.Request) {
return
}
// For JS/CSS files: check build dir first (transpiled/compiled files)
if s.config.BuildDir != "" && (strings.HasSuffix(filePath, ".js") || strings.HasSuffix(filePath, ".css")) {
// For CSS files: check build dir first (compiled SCSS -> CSS)
if s.config.BuildDir != "" && strings.HasSuffix(filePath, ".css") {
buildPath := filepath.Join(s.config.BuildDir, addonName, "static", filePath)
if _, err := os.Stat(buildPath); err == nil {
w.Header().Set("Cache-Control", "public, max-age=3600")
@@ -42,9 +53,9 @@ func (s *Server) handleStatic(w http.ResponseWriter, r *http.Request) {
}
}
// Search through addon paths (original files)
for _, addonsDir := range s.config.OdooAddonsPath {
fullPath := filepath.Join(addonsDir, addonName, "static", filePath)
// Search in frontend directory
if s.config.FrontendDir != "" {
fullPath := filepath.Join(s.config.FrontendDir, addonName, "static", filePath)
if _, err := os.Stat(fullPath); err == nil {
w.Header().Set("Cache-Control", "public, max-age=3600")
@@ -56,6 +67,36 @@ func (s *Server) handleStatic(w http.ResponseWriter, r *http.Request) {
}
}
// Transpile ES module JS files on-the-fly when served
// individually (e.g. debug mode). The main bundle already
// contains transpiled versions, but individual file
// requests still need transpilation.
if strings.HasSuffix(fullPath, ".js") {
data, err := os.ReadFile(fullPath)
if err != nil {
http.NotFound(w, r)
return
}
content := string(data)
urlPath := "/" + addonName + "/static/" + filePath
if IsOdooModule(urlPath, content) {
content = TranspileJS(urlPath, content)
}
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
http.ServeContent(w, r, filePath, time.Time{}, strings.NewReader(content))
return
}
http.ServeFile(w, r, fullPath)
return
}
}
// Fallback: build dir for pre-compiled vendor assets
if s.config.BuildDir != "" {
fullPath := filepath.Join(s.config.BuildDir, addonName, "static", filePath)
if _, err := os.Stat(fullPath); err == nil {
w.Header().Set("Cache-Control", "public, max-age=3600")
http.ServeFile(w, r, fullPath)
return
}