Documentation
¶
Index ¶
- Constants
- Variables
- func BuildVersionIndex(entries []TypstIndexEntry) map[string]string
- func CompareVersions(a, b Version) int
- func ConfigurableUpdateToml(w io.Writer, p PackageMeta, data []byte, unmarshal Unmarshaler, indent bool) error
- func EnsureDir(path string) error
- func FormatImportStmt(namespace, name, version string) string
- func GetLatestVersion(versions []*ResponseModel) (string, error)
- func IsSemVer(s string) bool
- func Must[T any](t T, err error) T
- func PrintInfo(format string, a ...any)
- func PrintWarn(format string, a ...any)
- func ResolveCachePath() (string, error)
- func ResolveDarwinDataDir() (string, error)
- func ResolveLinuxDataDir() (string, error)
- func ResolveLocalPackageDir() (string, error)
- func ResolveLocalPackageDirPath() (string, error)
- func ResolvePackageDirPath(cmd *cobra.Command) (path string, overridden bool, err error)
- func ResolveWindowsDataDir() (string, error)
- func SaveIndexCache(index map[string]string) error
- func SetupLogger(cmd *cobra.Command) *log.Logger
- func SetupSpinner() *spinner.Spinner
- func UpdateTOML(w io.Writer, p PackageMeta, data []byte, indent bool) error
- type IndexCache
- type Manifest
- type PackageMeta
- type ResponseModel
- type TypstIndexEntry
- type Unmarshaler
- type Version
Constants ¶
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" )
const ( MAJOR string = "major" MINOR string = "minor" PATCH string = "patch" )
const (
CacheTTL = time.Hour
)
const TypstPackageEndpoint string = "https://api.github.com/repos/typst/packages/contents/packages/preview/"
const TypstPackageIndexURL string = "https://packages.typst.org/preview/index.json"
Variables ¶
var ( ErrManifestNotFound = errors.New("not found 'typst.toml': not a typst package directory") ErrInvalidManifest = errors.New("invalid 'typst.toml'") )
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 )
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) StyleLogo = lipgloss.NewStyle().Foreground(Violet) StyleDescription = lipgloss.NewStyle().Foreground(Magenta) )
var ErrDataDirNotResolvable = errors.New("could not resolve typst local package directory")
var ErrInvalidIncrement = errors.New("invalid version incrementation, must be one of [major|minor|patch]")
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 ¶
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 FormatImportStmt ¶
func GetLatestVersion ¶
func GetLatestVersion(versions []*ResponseModel) (string, error)
func IsSemVer ¶
IsSemVer reports whether s is a valid semantic version (e.g. 0.1.0). Only non-negative integers separated by dots are accepted.
func ResolveCachePath ¶ added in v0.3.12
func ResolveDarwinDataDir ¶
func ResolveLinuxDataDir ¶
func ResolveLocalPackageDir ¶
ResolveLocalPackageDir returns the path to the typst packages directory, creating it if it does not exist.
func ResolveLocalPackageDirPath ¶
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
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 SaveIndexCache ¶ added in v0.3.12
SaveIndexCache writes the index to disk with the current timestamp.
func SetupLogger ¶
SetupLogger creates a logger whose level is controlled by the --verbose flag.
func SetupSpinner ¶
SetupSpinner returns a spinner ready to start.
func UpdateTOML ¶
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 ¶
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
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 ¶
Unmarshaler is a function that decodes TOML bytes into a value.
type Version ¶
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 ¶
ParseVersion parses a string into a Version struct.