Documentation
¶
Index ¶
- func FileWrite(pathFile string, data bytes.Buffer) error
- func GenerateExtractorMain(outputFile string, modules []Module) error
- func NewFaviconSvgHandler(ac *Config, outputName string) *asset
- func NewHtmlHandler(ac *Config, outputName, cssURL, jsURL, faviconURL string) *asset
- func NewSvgHandler(ac *Config, outputName string) *asset
- func ParseExistingHtmlContent(content string) (openContent, closeContent string)
- func RewriteAssetUrls(html string, newRoot string) string
- func StripLeadingUseStrict(b []byte) []byte
- type AssetMin
- func (c *AssetMin) ContainsCSS(substr string) bool
- func (c *AssetMin) ContainsHTML(substr string) bool
- func (c *AssetMin) ContainsJS(substr string) bool
- func (c *AssetMin) ContainsSVG(substr string) bool
- func (c *AssetMin) EnableSSRMode()
- func (c *AssetMin) EnsureOutputDirectoryExists()
- func (c *AssetMin) Execute()
- func (c *AssetMin) ExtractSSRAssetsWithContext(moduleDir string) (*SSRAssets, error)
- func (c *AssetMin) FlushToDisk() error
- func (c *AssetMin) GetCSSURLPath() string
- func (c *AssetMin) GetCachedHTML() []byte
- func (c *AssetMin) GetFaviconURLPath() string
- func (c *AssetMin) GetInitCodeJS() (string, error)
- func (c *AssetMin) GetJSURLPath() string
- func (c *AssetMin) GetMainCssPath() string
- func (c *AssetMin) GetMainHtmlPath() string
- func (c *AssetMin) GetMainJsPath() string
- func (c *AssetMin) GetMainSvgPath() string
- func (c *AssetMin) GetMinifiedCSS() ([]byte, error)
- func (c *AssetMin) GetMinifiedJS() ([]byte, error)
- func (c *AssetMin) GetSVGURLPath() string
- func (c *AssetMin) HasIcon(id string) bool
- func (c *AssetMin) InjectCSS(name string, content string)
- func (c *AssetMin) InjectHTML(html string)
- func (c *AssetMin) InjectJS(name string, content string)
- func (c *AssetMin) InjectSpriteIcon(id, svg string) error
- func (c *AssetMin) IsSSRMode() bool
- func (c *AssetMin) Label() string
- func (c *AssetMin) LoadSSRModules()
- func (c *AssetMin) Logger(messages ...any)
- func (c *AssetMin) MainInputFileRelativePath() string
- func (c *AssetMin) MainOutputFileAbsolutePath() string
- func (c *AssetMin) Name() string
- func (c *AssetMin) NewFileEvent(fileName, extension, filePath, event string) error
- func (c *AssetMin) RefreshJSAssets()
- func (c *AssetMin) RegenerateHTMLCache() error
- func (c *AssetMin) RegisterComponents(providers ...any) error
- func (c *AssetMin) RegisterRoutes(mux *http.ServeMux)
- func (c *AssetMin) ReloadSSRModule(moduleDir string) error
- func (c *AssetMin) ScheduleSSRLoad()
- func (c *AssetMin) SetListModulesFn(fn func(rootDir string) ([]string, error))
- func (c *AssetMin) SetLog(f func(message ...any))
- func (c *AssetMin) SetSSRCompiler(fn func() error)
- func (c *AssetMin) ShouldCompileToWasm(fileName, filePath string) bool
- func (c *AssetMin) SupportedExtensions() []string
- func (c *AssetMin) TestOnly_ModuleSubpackagesUsed(modulePath, moduleDir string, importedPaths map[string]bool) []string
- func (c *AssetMin) TestOnly_ScanImports() (map[string]bool, error)
- func (c *AssetMin) UnobservedFiles() []string
- func (c *AssetMin) UpdateFileContentInMemory(filePath, extension, event string, content []byte) (*asset, error)
- func (c *AssetMin) UpdateSSRModule(name string, css string, scripts []*js.Script, html string, ...) error
- func (c *AssetMin) UpdateSSRModuleInSlot(name string, css string, scripts []*js.Script, html string, ...) error
- func (c *AssetMin) WaitForSSRLoad(timeout time.Duration)
- type Config
- type ContentFile
- type Module
- type ModuleAlias
- type SSRAssets
- type ScriptOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FileWrite ¶
pathFile e.g., "theme/htmlMainFileName" data e.g., *bytes.Buffer NOTE: The buffer data will be cleared after writing the file
func GenerateExtractorMain ¶ added in v0.3.0
GenerateExtractorMain writes a main.go file that imports all modules and collects their assets.
func NewFaviconSvgHandler ¶
NewFaviconSvgHandler creates a handler for favicon.svg that simply minifies and copies the file without sprite wrapping. This handler processes standalone SVG files like favicon.svg
func NewHtmlHandler ¶
NewHtmlHandler creates an HTML asset handler using the provided output filename
func NewSvgHandler ¶
func ParseExistingHtmlContent ¶ added in v0.2.2
ParseExistingHtmlContent is a public wrapper for tests.
func RewriteAssetUrls ¶ added in v0.2.2
RewriteAssetUrls is a public wrapper for tests.
func StripLeadingUseStrict ¶ added in v0.2.2
StripLeadingUseStrict is a public wrapper for tests.
Types ¶
type AssetMin ¶
type AssetMin struct {
*Config
// contains filtered or unexported fields
}
func NewAssetMin ¶
func (*AssetMin) ContainsCSS ¶ added in v0.2.2
ContainsCSS checks if the CSS bundle contains the given substring.
func (*AssetMin) ContainsHTML ¶ added in v0.2.2
ContainsHTML checks if the HTML bundle contains the given substring.
func (*AssetMin) ContainsJS ¶ added in v0.2.2
ContainsJS checks if the JS bundle contains the given substring.
func (*AssetMin) ContainsSVG ¶ added in v0.2.2
ContainsSVG checks if the SVG sprite contains the given substring.
func (*AssetMin) EnableSSRMode ¶ added in v0.3.3
func (c *AssetMin) EnableSSRMode()
EnableSSRMode activates the SSR event branch unconditionally. Pure setter.
func (*AssetMin) EnsureOutputDirectoryExists ¶
func (c *AssetMin) EnsureOutputDirectoryExists()
func (*AssetMin) Execute ¶ added in v0.2.3
func (c *AssetMin) Execute()
Execute toggles minification and regenerates all assets.
func (*AssetMin) ExtractSSRAssetsWithContext ¶ added in v0.3.4
ExtractSSRAssetsWithContext uses the AssetMin's listModulesFn (if set) when discovering modules. This allows tests to mock module discovery without running actual go list commands.
func (*AssetMin) FlushToDisk ¶ added in v0.3.3
FlushToDisk snapshots all registered assets, writes them to disk (overwrite), and sets diskMirrored = true only on full success. Returns the first write error.
func (*AssetMin) GetCSSURLPath ¶ added in v0.2.2
GetCSSURLPath returns the URL path for the main CSS file.
func (*AssetMin) GetCachedHTML ¶ added in v0.2.2
GetCachedHTML returns the cached minified HTML content.
func (*AssetMin) GetFaviconURLPath ¶ added in v0.2.2
GetFaviconURLPath returns the URL path for the favicon file.
func (*AssetMin) GetInitCodeJS ¶ added in v0.2.2
GetInitCodeJS returns the init code for the JS bundle.
func (*AssetMin) GetJSURLPath ¶ added in v0.2.2
GetJSURLPath returns the URL path for the main JS file.
func (*AssetMin) GetMainCssPath ¶ added in v0.2.2
GetMainCssPath returns the output path of the main CSS file.
func (*AssetMin) GetMainHtmlPath ¶ added in v0.2.2
GetMainHtmlPath returns the output path of the main HTML file.
func (*AssetMin) GetMainJsPath ¶ added in v0.2.2
GetMainJsPath returns the output path of the main JS file.
func (*AssetMin) GetMainSvgPath ¶ added in v0.2.2
GetMainSvgPath returns the output path of the main SVG file.
func (*AssetMin) GetMinifiedCSS ¶ added in v0.2.2
GetMinifiedCSS returns the minified content of the CSS bundle.
func (*AssetMin) GetMinifiedJS ¶ added in v0.2.2
GetMinifiedJS returns the minified content of the JS bundle.
func (*AssetMin) GetSVGURLPath ¶ added in v0.2.2
GetSVGURLPath returns the URL path for the SVG sprite file.
func (*AssetMin) HasIcon ¶ added in v0.2.2
HasIcon checks if an icon with the given ID is registered.
func (*AssetMin) InjectCSS ¶ added in v0.0.81
AddCSS appends CSS content from providers to the bundle InjectCSS appends CSS content to the bundle. name is used for the virtual filename (e.g., "mycomponent.css"). AddCSS appends CSS content from providers to the bundle InjectCSS appends CSS content to the bundle. name is used for the virtual filename (e.g., "mycomponent.css").
func (*AssetMin) InjectHTML ¶ added in v0.0.81
InjectHTML appends HTML to the body
func (*AssetMin) InjectJS ¶ added in v0.0.81
AddJS appends JS content from providers to the bundle InjectJS appends JS content to the bundle. name is used for the virtual filename (e.g., "mycomponent.js").
func (*AssetMin) InjectSpriteIcon ¶ added in v0.0.81
AddIcon adds icons from providers to the bundle InjectSpriteIcon adds an icon to the sprite bundle. id: unique icon ID. svg: raw SVG content.
func (*AssetMin) IsSSRMode ¶ added in v0.2.2
IsSSRMode returns true if the package is being used as a dependency (SSR mode).
func (*AssetMin) Label ¶ added in v0.2.3
Label returns the TUI button label reflecting current minification state.
func (*AssetMin) LoadSSRModules ¶ added in v0.2.2
func (c *AssetMin) LoadSSRModules()
LoadSSRModules descubre todos los módulos e inyecta sus assets (asíncrono).
func (*AssetMin) MainInputFileRelativePath ¶ added in v0.0.70
MainInputFileRelativePath returns the main input file path. AssetMin manages multiple assets, so returns empty. Used by DevWatch for specific file watching logic.
func (*AssetMin) MainOutputFileAbsolutePath ¶ added in v0.0.70
MainOutputFileAbsolutePath returns the main output file path. AssetMin manages multiple outputs, so returns empty. Used by DevWatch for exclusion logic (handled by UnobservedFiles instead)
func (*AssetMin) NewFileEvent ¶
event: create, remove, write, rename
func (*AssetMin) RefreshJSAssets ¶ added in v0.2.7
func (c *AssetMin) RefreshJSAssets()
RefreshJSAssets triggers a refresh of JS assets. Call this when the WASM binary changes to ensure they are up to date.
func (*AssetMin) RegenerateHTMLCache ¶ added in v0.2.2
RegenerateHTMLCache forces regeneration of the HTML cache.
func (*AssetMin) RegisterComponents ¶ added in v0.2.2
RegisterComponents registra structs que implementan las interfaces SSR.
func (*AssetMin) RegisterRoutes ¶
RegisterRoutes registers the HTTP handlers for all assets.
func (*AssetMin) ReloadSSRModule ¶ added in v0.2.2
ReloadSSRModule re-extrae e inyecta los assets de un único módulo por su directorio.
func (*AssetMin) ScheduleSSRLoad ¶ added in v0.2.4
func (c *AssetMin) ScheduleSSRLoad()
ScheduleSSRLoad inicia la carga de módulos SSR en segundo plano de forma segura.
func (*AssetMin) SetListModulesFn ¶ added in v0.2.2
SetListModulesFn replaces the module discovery function. Only for tests — allows injecting dummy directories without network.
func (*AssetMin) SetSSRCompiler ¶ added in v0.3.3
SetSSRCompiler registers a Go compiler callback. Pure setter — does NOT invoke fn. Pass nil to unregister.
func (*AssetMin) ShouldCompileToWasm ¶ added in v0.0.70
ShouldCompileToWasm checks if the file triggers WASM compilation. AssetMin handles assets, not WASM, so always returns false.
func (*AssetMin) SupportedExtensions ¶
func (*AssetMin) TestOnly_ModuleSubpackagesUsed ¶ added in v0.2.3
func (c *AssetMin) TestOnly_ModuleSubpackagesUsed(modulePath, moduleDir string, importedPaths map[string]bool) []string
TestOnly_ModuleSubpackagesUsed is for testing the subpackage matcher.
func (*AssetMin) TestOnly_ScanImports ¶ added in v0.2.3
TestOnly_ScanImports is for testing the import scanner.
func (*AssetMin) UnobservedFiles ¶
func (*AssetMin) UpdateFileContentInMemory ¶
func (*AssetMin) UpdateSSRModule ¶ added in v0.2.2
func (c *AssetMin) UpdateSSRModule(name string, css string, scripts []*js.Script, html string, icons map[string]string) error
UpdateSSRModule inyecta o reemplaza los assets de un módulo por nombre en el slot por defecto (middle).
func (*AssetMin) UpdateSSRModuleInSlot ¶ added in v0.2.2
func (c *AssetMin) UpdateSSRModuleInSlot(name string, css string, scripts []*js.Script, html string, icons map[string]string, slot string) error
UpdateSSRModuleInSlot inyecta o reemplaza los assets de un módulo en el slot especificado.
func (*AssetMin) WaitForSSRLoad ¶ added in v0.2.2
WaitForSSRLoad espera a que LoadSSRModules termine, hasta el timeout dado.
type Config ¶
type Config struct {
OutputDir string // eg: web/static, web/public, web/assets
RootDir string // Root directory of the project where go.mod exists
AppName string // Application name for templates (default: "MyApp")
AssetsURLPrefix string // New: for HTTP routes
DevMode bool // If true, disables caching (default: false)
}
type ContentFile ¶ added in v0.2.2
type ContentFile struct {
Path string // eg: modules/module1/file.js
Content []byte /// eg: "console.log('hello world')"
}
ContentFile represents a file with its path and content
func (*ContentFile) WriteToDisk ¶ added in v0.2.2
func (f *ContentFile) WriteToDisk() error
WriteToDisk writes the content file to disk at the specified path It creates parent directories if they don't exist
type ModuleAlias ¶ added in v0.3.0
type ModuleAlias struct {
Path string
Alias string
ReceiverType string
HasRoot bool
HasRender bool
HasHTML bool
HasJS bool
HasIcons bool
}
func ModulesToAliases ¶ added in v0.3.0
func ModulesToAliases(modules []Module) []ModuleAlias
ModulesToAliases converts module information to alias mappings and detects features via regex.
func (ModuleAlias) HasAnyFeature ¶ added in v0.3.1
func (m ModuleAlias) HasAnyFeature() bool
type SSRAssets ¶ added in v0.2.2
type SSRAssets struct {
ModuleName string
RootCSS string
CSS string
JS []*js.Script
HTML string
Icons map[string]string
}
func ExtractSSRAssets ¶ added in v0.2.2
ExtractSSRAssets uses compile-and-invoke to extract assets from a module. moduleDir may be a sub-package; the project root (which contains go.mod) is found by traversing up.