builder

package
v0.0.0-...-41600d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheTypeSSR = iota
	CacheTypeBrowser
)

Variables

This section is empty.

Functions

func CreateComponentTree

func CreateComponentTree(path string) (*componentTree, error)

CreateComponentTree creates a componentTree based on the absolute Path it performs a depth-first search through all subdirectories under the specified Path

Types

type BrowserBuilder

type BrowserBuilder struct {
	// contains filtered or unexported fields
}

func NewBrowserBuilder

func NewBrowserBuilder(
	logger utils.Logger,
	vm js.VM,
	cache Cache,
	workingDir string,
) *BrowserBuilder

func (*BrowserBuilder) BuildDev

func (b *BrowserBuilder) BuildDev(allViews []*View) (map[string]StaticAsset, error)

BuildDev creates assets for embedding into the rendered view references to those assets are added to the View object for the entrypoint svelte file

type Cache

type Cache interface {
	Finished()
	Persist() error
	GetContent(path string) *string
	DependsOn(pathA, pathB string) error
	AddCache(path string, content *string)
	Invalidate(path string) error
}

type CompiledResult

type CompiledResult struct {
	JS        []byte
	CSS       []byte
	SourceMap []byte
}

type Component

type Component struct {
	Name string

	//Path is absolute
	Path string

	Layout *Layout

	// ParentTree represents the directory this component belongs in
	ParentTree *componentTree
	// contains filtered or unexported fields
}

func (*Component) ApplicableLayouts

func (c *Component) ApplicableLayouts() []*Layout

ApplicableLayouts returns a flattened layout hierarchy of layouts applicable to this component. Layout index determines its proximity to the component in the hierarchy

func (*Component) RelativePath

func (c *Component) RelativePath() string

RelativePath returns the relative Path of the component to the views directory

type ComponentTree

type ComponentTree interface {
	ResolveLayoutByName(name string) *Layout
	Path() string
	GetAllComponents() []*Component
	GetAllLayouts() []*Layout
	GetAllDescendantPaths() []string
}

type Layout

type Layout struct {
	Name string

	//Path is absolute
	Path string

	// nil if no parent layout exists
	ParentLayout *Layout

	// ParentTree represents the directory this layout belongs in
	ParentTree *componentTree
	// contains filtered or unexported fields
}

func (*Layout) ApplicableLayouts

func (l *Layout) ApplicableLayouts() []*Layout

func (*Layout) RelativePath

func (l *Layout) RelativePath() string

RelativePath returns the relative Path of the layout to the views directory

type SSRBuilder

type SSRBuilder struct {
	// contains filtered or unexported fields
}

func NewSSRBuilder

func NewSSRBuilder(
	logger utils.Logger,
	vm js.VM,
	cache Cache,
	workingDir string,
) *SSRBuilder

func (*SSRBuilder) DevBuild

func (s *SSRBuilder) DevBuild(allViews []*View) (*CompiledResult, error)

type StaticAsset

type StaticAsset struct {
	MimeType string
	Content  []byte
}

type SvelteBuildOutput

type SvelteBuildOutput struct {
	CSSCode string
	JSCode  string

	JSSourceMap  string
	CSSSourceMap string
}

type SvelteCompilerFunc

type SvelteCompilerFunc func(string, []byte) (*SvelteBuildOutput, error)

type View

type View struct {
	ComponentName string

	//UniqueName is the PascalCase of the Path relative to views directory
	UniqueName string

	//WrappedUniqueName prefixes the unique name with "__AviatorWrapped_"
	//i.e __AviatorWrapped{UniqueName}
	//This is used to disambiguate the layout wrapped component from the component itself
	WrappedUniqueName string
	Path              string

	//RelPath is the relative Path from the project's views directory
	RelPath string

	//A view can represent either a Component or a Layout
	Component *Component
	Layout    *Layout

	IsLayout bool

	//If the view is a svelte Component and starts with a capital letter, it will be
	//treated as an entrypoint for both SSR and Browser JS
	IsEntrypoint bool

	//ApplicableLayouts is a slice of Views that represent layouts that apply to this
	//view. Lower index means the layout is closer to this view in the ancestral hierarchy
	ApplicableLayoutViews []*View

	//the imports are generated during the browser build step and are injected into
	// the HTML at render time
	JSImports  []string
	CSSImports []string
	// contains filtered or unexported fields
}

View objects are passed to the go-template file responsible for creating the virtual __aviator_ssr.js file in the SSR Plugin A View object can represent both a Component or a Layout

type ViewManager

type ViewManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewViewManager

func NewViewManager(
	logger utils.Logger,
	vm js.VM,
	tree ComponentTree,
	htmlGenerator *template.Template,
	isDevMode bool,
	cacheDir string,
	viewsDir string,
	staticAssetsRoute string,
	htmlLang string,
) (*ViewManager, error)

func (*ViewManager) AllViews

func (v *ViewManager) AllViews() []*View

AllViews returns all views

func (*ViewManager) Build

func (v *ViewManager) Build() error

func (*ViewManager) GetStaticAsset

func (v *ViewManager) GetStaticAsset(name string) (StaticAsset, bool)

func (*ViewManager) Render

func (v *ViewManager) Render(
	_ context.Context,
	viewPath string,
	props interface{},
) (string, error)

func (*ViewManager) StartWatch

func (v *ViewManager) StartWatch() error

StartWatch starts watching views directory for changes

func (*ViewManager) ViewByRelPath

func (v *ViewManager) ViewByRelPath(path string) *View

ViewByRelPath returns a view by the relative Path

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL