codegen

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package codegen generates the code that connects a Tern app's routes to the runtime: tern.gen.go for the Go server, the client route manifest for Vite, and TypeScript types for every route.

Index

Constants

View Source
const (
	RoutesDir   = "src/routes"
	AppHTML     = "src/app.html"
	GenDir      = ".tern"
	GoFile      = "tern.gen.go"
	ClientEntry = ".tern/generated/client.js"
	ClientOut   = ".tern/output/client"
	ServerEntry = ".tern/generated/server.js"
	ServerOut   = ".tern/output/server"
)

Project layout conventions.

View Source
const ConfigFile = "tern.json"

ConfigFile is the optional project configuration, shared by the code generator, the Vite plugin and the runtime.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.0.0

type Config struct {
	// BasePath serves the app under a URL prefix such as "/app". It must
	// start with a slash and must not end with one. The default is "".
	BasePath string `json:"basePath"`
}

Config is the contents of tern.json.

func LoadConfig added in v1.0.0

func LoadConfig(root string) (Config, error)

LoadConfig reads tern.json from root. A missing file is an empty config.

type Result

type Result struct {
	Manifest *routes.Manifest
	// Changed lists the files that were written because their content changed.
	Changed []string
	// GoChanged reports whether Go code changed, so the server must be rebuilt.
	GoChanged bool
	// Prerender reports whether any route is prerendered at build time.
	Prerender bool
}

Result describes what Generate produced.

func Generate

func Generate(root string) (*Result, error)

Generate scans the project at root and writes all generated files. Files whose content is unchanged are not rewritten, so file watchers only see real changes.

Jump to

Keyboard shortcuts

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