Documentation
¶
Overview ¶
Package serve implements the development server for custom element demos
Index ¶
- type CSSConfig
- type Config
- type DemosConfig
- type ErrorMessage
- type FileEvent
- type FileWatcher
- type LogMessage
- type Logger
- type ReloadMessage
- type Server
- func (s *Server) BroadcastError(title, message, file string) error
- func (s *Server) BroadcastReload(files []string, reason string) error
- func (s *Server) Close() error
- func (s *Server) CreateReloadMessage(files []string, reason string) ([]byte, error)
- func (s *Server) DebounceDuration() time.Duration
- func (s *Server) DemoRenderingMode() string
- func (s *Server) DemoRoutes() map[string]*middleware.DemoRouteEntry
- func (s *Server) Done() <-chan struct{}
- func (s *Server) FileSystem() platform.FileSystem
- func (s *Server) Handler() http.Handler
- func (s *Server) ImportMap() middleware.ImportMap
- func (s *Server) InitializeWorkspaceMode() error
- func (s *Server) IsRunning() bool
- func (s *Server) IsWorkspace() bool
- func (s *Server) Logger() middleware.Logger
- func (s *Server) Manifest() ([]byte, error)
- func (s *Server) PackageJSON() (*middleware.PackageJSON, error)
- func (s *Server) PathResolver() middleware.PathResolver
- func (s *Server) Port() int
- func (s *Server) RebuildPathResolverForTest() error
- func (s *Server) RegenerateManifest() (int, error)
- func (s *Server) RegenerateManifestIncremental(changedFiles []string) (int, error)
- func (s *Server) SetLogger(log Logger)
- func (s *Server) SetManifest(manifest []byte) error
- func (s *Server) SetWatchDir(dir string) error
- func (s *Server) SourceControlRootURL() string
- func (s *Server) Start() error
- func (s *Server) TryLoadExistingManifest() (int, error)
- func (s *Server) TsconfigRaw() string
- func (s *Server) URLRewrites() []config.URLRewrite
- func (s *Server) WatchDir() string
- func (s *Server) WebSocketManager() WebSocketManager
- func (s *Server) WorkspacePackages() []middleware.WorkspacePackage
- type TransformConfig
- type TypeScriptConfig
- type WebSocketManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CSSConfig ¶
type CSSConfig struct {
Enabled bool
Include []string // Glob patterns to include
Exclude []string // Glob patterns to exclude
}
CSSConfig holds CSS transform configuration
type Config ¶
type Config struct {
Port int
Reload bool
Target transform.Target // Transform target (default: ES2022) - deprecated, use Transforms.TypeScript.Target
Transforms TransformConfig // Transform configuration
ImportMap types.ImportMapConfig // Import map override configuration
Demos DemosConfig // Demo rendering configuration
ConfigFile string // Path to config file (for error reporting)
WatchIgnore []string // Glob patterns to ignore in file watcher (e.g., ["_site/**", "dist/**"])
SourceControlRootURL string // Source control root URL for demo routing (e.g., "https://github.com/user/repo/tree/main/")
FS platform.FileSystem // Optional filesystem for testing (defaults to os package)
URLRewrites []config.URLRewrite // URL rewrites for request path mapping (e.g., "/dist/:path*" -> "/src/{{.path}}")
WebSocketManager WebSocketManager // Optional WebSocket manager for testing (created automatically if nil and Reload=true)
}
Config represents the dev server configuration
type DemosConfig ¶ added in v0.8.0
type DemosConfig struct {
Rendering string // Default rendering mode: "light", "shadow", or "iframe"
}
DemosConfig holds demo rendering configuration
type ErrorMessage ¶
type ErrorMessage struct {
Type string `json:"type"`
Title string `json:"title"`
Message string `json:"message"`
File string `json:"file,omitempty"`
}
ErrorMessage represents a WebSocket error notification (e.g., transform errors)
type FileEvent ¶
type FileEvent struct {
Path string // Primary file path (for single file events)
Paths []string // All changed file paths (for batched events)
EventType string // Event type for primary file (create/delete/modify)
HasCreates bool // True if any files were created
HasDeletes bool // True if any files were deleted
HasPackageJSON bool // True if package.json was modified
Timestamp time.Time
}
FileEvent represents a file system event
type FileWatcher ¶
type FileWatcher interface {
Watch(path string) error
Events() <-chan FileEvent
Close() error
SetIgnorePatterns(watchDir string, patterns []string)
}
FileWatcher watches files for changes
type LogMessage ¶
LogMessage represents a WebSocket log update
type ReloadMessage ¶
type ReloadMessage struct {
Type string `json:"type"`
Reason string `json:"reason"`
Files []string `json:"files"`
}
ReloadMessage represents a WebSocket reload event
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the development server
func NewServerWithConfig ¶
NewServerWithConfig creates a new server with the given config
func (*Server) BroadcastError ¶
BroadcastError broadcasts an error notification to all WebSocket clients
func (*Server) BroadcastReload ¶
BroadcastReload broadcasts a reload event to all WebSocket clients
func (*Server) CreateReloadMessage ¶
CreateReloadMessage creates a reload message JSON
func (*Server) DebounceDuration ¶
DebounceDuration returns the debounce duration for file watching
func (*Server) DemoRenderingMode ¶ added in v0.8.0
DemoRenderingMode returns the configured default rendering mode for demos
func (*Server) DemoRoutes ¶
func (s *Server) DemoRoutes() map[string]*middleware.DemoRouteEntry
DemoRoutes returns the pre-computed demo routing table (both workspace and single-package mode)
func (*Server) Done ¶
func (s *Server) Done() <-chan struct{}
Done returns a channel that's closed when the server shuts down. This allows goroutines to gracefully cancel work during shutdown.
func (*Server) FileSystem ¶
func (s *Server) FileSystem() platform.FileSystem
FileSystem returns the filesystem abstraction
func (*Server) ImportMap ¶
func (s *Server) ImportMap() middleware.ImportMap
ImportMap returns the cached import map (may be nil)
func (*Server) InitializeWorkspaceMode ¶
InitializeWorkspaceMode detects and initializes workspace mode if applicable
func (*Server) IsWorkspace ¶
IsWorkspace returns true if server is running in workspace mode
func (*Server) Logger ¶
func (s *Server) Logger() middleware.Logger
Logger returns the server logger
func (*Server) PackageJSON ¶
func (s *Server) PackageJSON() (*middleware.PackageJSON, error)
PackageJSON returns parsed package.json from the watch directory
func (*Server) PathResolver ¶ added in v0.8.0
func (s *Server) PathResolver() middleware.PathResolver
PathResolver returns the cached path resolver for efficient URL rewriting
func (*Server) RebuildPathResolverForTest ¶ added in v0.8.0
RebuildPathResolverForTest exposes rebuildPathResolver for testing. This is a test-only wrapper that allows tests to trigger path resolver rebuilds.
func (*Server) RegenerateManifest ¶
RegenerateManifest performs a full manifest regeneration Returns the manifest size in bytes and any error
func (*Server) RegenerateManifestIncremental ¶
RegenerateManifestIncremental incrementally updates the manifest for changed files Returns the manifest size in bytes and any error
func (*Server) SetManifest ¶
SetManifest sets the current manifest and builds the routing table
func (*Server) SetWatchDir ¶
SetWatchDir sets the directory to watch for file changes
func (*Server) SourceControlRootURL ¶
SourceControlRootURL returns the source control root URL for demo routing
func (*Server) TryLoadExistingManifest ¶
TryLoadExistingManifest attempts to load a manifest from disk Returns the manifest size in bytes and any error Returns 0, nil if no manifest file exists (not an error condition)
func (*Server) TsconfigRaw ¶
TsconfigRaw returns the current tsconfig.json content
func (*Server) URLRewrites ¶ added in v0.8.0
func (s *Server) URLRewrites() []config.URLRewrite
URLRewrites returns the configured URL rewrites for request path resolution
func (*Server) WebSocketManager ¶
func (s *Server) WebSocketManager() WebSocketManager
WebSocketManager returns the WebSocket manager (nil if reload disabled)
func (*Server) WorkspacePackages ¶
func (s *Server) WorkspacePackages() []middleware.WorkspacePackage
WorkspacePackages returns discovered workspace packages (workspace mode only)
type TransformConfig ¶
type TransformConfig struct {
TypeScript TypeScriptConfig
CSS CSSConfig
}
TransformConfig holds transform-specific configuration
type TypeScriptConfig ¶
TypeScriptConfig holds TypeScript transform configuration
type WebSocketManager ¶
type WebSocketManager interface {
ConnectionCount() int
Broadcast(message []byte) error
BroadcastToPages(message []byte, pageURLs []string) error
BroadcastShutdown() error
CloseAll() error
HandleConnection(w http.ResponseWriter, r *http.Request)
SetLogger(logger Logger)
}
WebSocketManager manages WebSocket connections for live reload
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
urlutil
Package urlutil provides utility functions for URL path matching and manipulation.
|
Package urlutil provides utility functions for URL path matching and manipulation. |
|
types
Package types provides shared interfaces and types for middleware packages
|
Package types provides shared interfaces and types for middleware packages |