internal

package
v0.3.12 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultNamespace = "local"

	// InstallDirEnvVar is the environment variable that overrides the package directory.
	InstallDirEnvVar = "GOTPM_INSTALL_DIR"
	// InstallDirFlag is the cobra flag name used to override the package directory.
	InstallDirFlag = "install-dir"
)
View Source
const (
	MAJOR string = "major"
	MINOR string = "minor"
	PATCH string = "patch"
)
View Source
const (
	CacheTTL = time.Hour
)
View Source
const TypstPackageEndpoint string = "https://api.github.com/repos/typst/packages/contents/packages/preview/"
View Source
const TypstPackageIndexURL string = "https://packages.typst.org/preview/index.json"

Variables

View Source
var (
	ErrManifestNotFound = errors.New("not found 'typst.toml': not a typst package directory")
	ErrInvalidManifest  = errors.New("invalid 'typst.toml'")
)
View Source
var (
	Blue    = charmtone.Malibu
	Green   = charmtone.Bok
	Yellow  = charmtone.Zest
	Red     = charmtone.Coral
	Violet  = charmtone.Charple
	Magenta = charmtone.Cheeky
	Normal  = lipgloss.White
	Muted   = charmtone.Squid
	Accent  = charmtone.Ash
)
View Source
var (
	StyleBlueBold    = lipgloss.NewStyle().Foreground(Blue).Bold(true)
	StyleBlue        = lipgloss.NewStyle().Foreground(Blue)
	StyleGreen       = lipgloss.NewStyle().Foreground(Green)
	StyleYellow      = lipgloss.NewStyle().Foreground(Yellow).Bold(true)
	StyleRed         = lipgloss.NewStyle().Foreground(Red)
	StyleNormal      = lipgloss.NewStyle().Foreground(Normal)
	StyleMuted       = lipgloss.NewStyle().Foreground(Muted)
	StyleAccent      = lipgloss.NewStyle().Foreground(Accent).Bold(true)
	StyleDescription = lipgloss.NewStyle().Foreground(Magenta)
)
View Source
var ErrDataDirNotResolvable = errors.New("could not resolve typst local package directory")
View Source
var ErrInvalidIncrement = errors.New("invalid version incrementation, must be one of [major|minor|patch]")
View Source
var ErrInvalidVersion = errors.New("not a valid semantic version")

Functions

func BuildVersionIndex added in v0.3.6

func BuildVersionIndex(entries []TypstIndexEntry) map[string]string

BuildVersionIndex reduces a list of index entries to a map of package name to its latest version string.

func CompareVersions

func CompareVersions(a, b Version) int

CompareVersions compares two Version structs. Useful for sorting. Returns 1 if a > b, -1 if a < b, 0 if equal.

func ConfigurableUpdateToml

func ConfigurableUpdateToml(w io.Writer, p PackageMeta, data []byte, unmarshal Unmarshaler, indent bool) error

ConfigurableUpdateToml writes the package metadata (name, version, entrypoint) back into the TOML document represented by data, using the provided writer and unmarshal function. The unmarshal parameter exists for testing.

func EnsureDir

func EnsureDir(path string) error

EnsureDir creates dir and all necessary parents.

func FormatImportStmt

func FormatImportStmt(namespace, name, version string) string

func GetLatestVersion

func GetLatestVersion(versions []*ResponseModel) (string, error)

func IsSemVer

func IsSemVer(s string) bool

IsSemVer reports whether s is a valid semantic version (e.g. 0.1.0). Only non-negative integers separated by dots are accepted.

func Must

func Must[T any](t T, err error) T

Must returns t, or exits the process with a fatal log entry if err is non-nil.

func PrintInfo

func PrintInfo(format string, a ...any)

func PrintWarn

func PrintWarn(format string, a ...any)

func ResolveCachePath added in v0.3.12

func ResolveCachePath() (string, error)

func ResolveDarwinDataDir

func ResolveDarwinDataDir() (string, error)

func ResolveLinuxDataDir

func ResolveLinuxDataDir() (string, error)

func ResolveLocalPackageDir

func ResolveLocalPackageDir() (string, error)

ResolveLocalPackageDir returns the path to the typst packages directory, creating it if it does not exist.

func ResolveLocalPackageDirPath

func ResolveLocalPackageDirPath() (string, error)

ResolveLocalPackageDirPath returns the path to the typst packages directory without creating it. Respects the $TYPST_PACKAGE_PATH override.

func ResolvePackageDirPath added in v0.3.9

func ResolvePackageDirPath(cmd *cobra.Command) (path string, overridden bool, err error)

ResolvePackageDirPath returns the package directory path without creating it, and whether an override was provided (flag or env). Resolution order: --install-dir flag > $GOTPM_INSTALL_DIR env > OS default. When overridden, the returned path is the final destination — callers must not append namespace/name/version sub-directories.

func ResolveWindowsDataDir

func ResolveWindowsDataDir() (string, error)

func SaveIndexCache added in v0.3.12

func SaveIndexCache(index map[string]string) error

SaveIndexCache writes the index to disk with the current timestamp.

func SetupLogger

func SetupLogger(cmd *cobra.Command) *log.Logger

SetupLogger creates a logger whose level is controlled by the --verbose flag.

func SetupSpinner

func SetupSpinner() *spinner.Spinner

SetupSpinner returns a spinner ready to start.

func UpdateTOML

func UpdateTOML(w io.Writer, p PackageMeta, data []byte, indent bool) error

UpdateTOML writes the package metadata (name, version, entrypoint) back into the TOML document represented by data, using the provided writer.

Types

type IndexCache added in v0.3.12

type IndexCache struct {
	Timestamp time.Time         `json:"timestamp"`
	Index     map[string]string `json:"index"`
}

func LoadIndexCache added in v0.3.12

func LoadIndexCache() (*IndexCache, error)

LoadIndexCache reads the on-disk cache. Returns nil, nil when the file does not exist.

func (*IndexCache) IsValid added in v0.3.12

func (c *IndexCache) IsValid() bool

type Manifest

type Manifest struct {
	Package PackageMeta `toml:"package"`
}

func LoadManifest

func LoadManifest(dir string) (Manifest, error)

LoadManifest reads and validates the typst.toml in the given directory.

type PackageMeta

type PackageMeta struct {
	Name       string `toml:"name"`
	Version    string `toml:"version"`
	Entrypoint string `toml:"entrypoint"`
}

func (*PackageMeta) Bump

func (p *PackageMeta) Bump(increment string) error

Bump updates the package version by the given increment or sets it to an exact semver string.

func (*PackageMeta) ValidateVersion

func (p *PackageMeta) ValidateVersion() bool

ValidateVersion reports whether the package version is a valid semver string.

type ResponseModel

type ResponseModel struct {
	Name string `json:"name" validate:"semver"`
}

func FetchDataFromGitHub

func FetchDataFromGitHub(url string, ctx context.Context) ([]*ResponseModel, error)

type TypstIndexEntry added in v0.3.6

type TypstIndexEntry struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

func FetchTypstIndex added in v0.3.6

func FetchTypstIndex(ctx context.Context) ([]TypstIndexEntry, error)

FetchTypstIndex fetches the full package index from packages.typst.org.

type Unmarshaler

type Unmarshaler func([]byte, any) error

Unmarshaler is a function that decodes TOML bytes into a value.

type Version

type Version struct {
	Major uint64
	Minor uint64
	Patch uint64
}

Version is a semantic version where only positive integers are allowed.

func NewVersion

func NewVersion() Version

NewVersion returns a Version with all fields set to zero.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses a string into a Version struct.

func (*Version) Bump

func (v *Version) Bump(increment string) error

Bump increments the Version by the given increment (major, minor, patch). Returns ErrInvalidIncrement if an unrecognized increment is used.

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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