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.
View Source
const LocalesDir = "src/locales"
LocalesDir holds the app's messages, one <locale>.json per language.
Variables ¶
View Source
var ServiceWorkerSources = []string{"src/service-worker.ts", "src/service-worker.js"}
ServiceWorkerSources are the files that define an app's service worker.
Functions ¶
func FindServiceWorker ¶ added in v1.1.0
FindServiceWorker returns the service worker source in root, or "".
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"`
// I18n configures translations in src/locales, if the app has them.
I18n struct {
// DefaultLocale is used when no other locale fits, and for messages
// missing from a locale. It defaults to "en", or the first locale.
DefaultLocale string `json:"defaultLocale"`
} `json:"i18n"`
// ServiceWorker configures src/service-worker.ts, if the app has one.
ServiceWorker struct {
// Register is whether the client registers the service worker. It
// defaults to true; set it to false to register it yourself.
Register *bool `json:"register"`
} `json:"serviceWorker"`
}
Config is the contents of tern.json.
func LoadConfig ¶ added in v1.0.0
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
// Warnings are problems that do not stop the build, such as missing
// translations.
Warnings []string
}
Result describes what Generate produced.
Click to show internal directories.
Click to hide internal directories.