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 ResolveDarwinDataDir() (string, error)
- func ResolveLinuxDataDir() (string, error)
- func ResolveLocalPackageDir() (string, error)
- func ResolveLocalPackageDirPath() (string, error)
- func ResolveWindowsDataDir() (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 ValidateVersion(resp ResponseModel) (bool, error)
- type Manifest
- type PackageMeta
- type ResponseModel
- type TypstIndexEntry
- type Unmarshaler
- type Version
Constants ¶
const ( MAJOR string = "major" MINOR string = "minor" PATCH string = "patch" )
const (
DefaultNamespace = "local"
)
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 = charmtone.Smoke 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) 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 ErrInvalidValidation = errors.New("invalid validation")
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 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 ResolveWindowsDataDir ¶
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.
func ValidateVersion ¶
func ValidateVersion(resp ResponseModel) (bool, error)
Validate that a given response from the github api of the typst package repository only contains valid semver strings.
Types ¶
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.