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 PrintInfof(format string, a ...any)
- func PrintWarnf(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) (string, bool, 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
- func WriteFile(path string, data []byte) error
- type IndexCache
- type Manifest
- type PackageMeta
- type ResponseModel
- type TypstIndexEntry
- type Unmarshaler
- type Version
Constants ¶
const ( DirPerm fs.FileMode = 0o750 FilePerm fs.FileMode = 0o644 )
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 ( TypstPackageEndpoint string = "https://api.github.com/repos/typst/packages/contents/packages/preview/" TypstPackageIndexURL string = "https://packages.typst.org/preview/index.json" Timeout time.Duration = 5 * time.Second )
const ( MAJOR string = "major" MINOR string = "minor" PATCH string = "patch" )
const (
CacheTTL = time.Hour
)
Variables ¶
var ( ErrManifestNotFound = errors.New("not a typst package directory, no typst.toml") ErrInvalidManifest = errors.New("invalid 'typst.toml'") ErrMissingName = errors.New("missing required field: package.name") ErrMissingVersion = errors.New("missing required field: package.version") ErrMissingEntrypoint = errors.New("missing required field: package.entrypoint") )
var ( Blue = charmtone.Malibu Green = charmtone.Bok Yellow = charmtone.Zest Red = lipgloss.Red Violet = charmtone.Charple Magenta = charmtone.Cheeky Normal = lipgloss.White Muted = charmtone.Squid Accent = charmtone.Ash ANSIGreen = lipgloss.Green )
var ( StyleBlueBold = lipgloss.NewStyle().Foreground(Blue).Bold(true) StyleBlue = lipgloss.NewStyle().Foreground(Blue) StyleGreen = lipgloss.NewStyle().Foreground(Green) StyleANSIGreen = lipgloss.NewStyle().Foreground(ANSIGreen).Bold(true) StyleYellow = lipgloss.NewStyle().Foreground(Yellow).Bold(true) StyleRed = lipgloss.NewStyle().Foreground(Red) StyleRedBold = lipgloss.NewStyle().Foreground(Red).Bold(true) 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 ( ErrInvalidIncrement = errors.New("invalid version incrementation, must be one of [major|minor|patch]") ErrInvalidVersion = errors.New("not a valid semantic version") )
var ErrDataDirNotResolvable = errors.New("could not resolve typst local package directory")
var ErrHTTPFailedRequest = errors.New("http request failed")
Functions ¶
func BuildVersionIndex ¶
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 PrintInfof ¶
func PrintWarnf ¶
func ResolveCachePath ¶
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 ¶
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 ¶
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 ¶
type IndexCache struct {
Timestamp time.Time `json:"timestamp"`
Index map[string]string `json:"index"`
}
func LoadIndexCache ¶
func LoadIndexCache() (*IndexCache, error)
LoadIndexCache reads the on-disk cache.
func (*IndexCache) IsValid ¶
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 ¶
func FetchTypstIndex ¶
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.