manifest

package
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package manifest defines the file format that describes a mod or modpack. The "minepkg.toml" manifest is the way minepkg defines packages. Packages can be mods or modpacks.

Learn More

For more details visit https://minepkg.io/docs/manifest

Index

Examples

Constants

View Source
const (
	// TypeMod indicates a package containing a single mod
	TypeMod = "mod"
	// TypeModpack indicates a package containing a list of mods (modpack)
	TypeModpack = "modpack"
)
View Source
const (
	ErrorLevelWarn = iota
	ErrorLevelFatal
)
View Source
const LockfileVersion = 1

LockfileVersion is the current version of the lockfile template

Variables

View Source
var (
	// ErrDependencyConflicts is returned when trying to add a dependency that is already present
	ErrDependencyConflicts = errors.New("a dependency with that name is already present")

	// DependencyLockTypeMod describes a mod dependency
	DependencyLockTypeMod = "mod"
	// DependencyLockTypeModpack describes a modpack dependency
	DependencyLockTypeModpack = "modpack"

	PlatformFabric  = "fabric"
	PlatformForge   = "forge"
	PlatformVanilla = "vanilla"
)
View Source
var (
	// ErrUnsupportedManifestVersion is returned when the manifest version is not supported.
	ErrUnsupportedManifestVersion = ValidationError{

		Path:  "manifestVersion",
		Level: ErrorLevelWarn,
		// contains filtered or unexported fields
	}
	// ErrNameEmpty is returned when the manifest name is empty.
	ErrNameEmpty = ValidationError{

		Path:  "package.name",
		Level: ErrorLevelWarn,
		// contains filtered or unexported fields
	}
	// ErrNameInvalid is returned when the manifest name is invalid.
	ErrNameInvalid = ValidationError{

		Path:  "package.name",
		Level: ErrorLevelWarn,
		// contains filtered or unexported fields
	}
	// ErrInvalidType is returned when the manifest type is not supported.
	ErrInvalidType = ValidationError{

		Path:  "package.type",
		Level: ErrorLevelFatal,
		// contains filtered or unexported fields
	}
	// ErrNoMinecraftRequirement is returned when the manifest does not contain a Minecraft requirement.
	ErrNoMinecraftRequirement = ValidationError{

		Path:  "requirements.minecraft",
		Level: ErrorLevelFatal,
		// contains filtered or unexported fields
	}
	// ErrInvalidMinecraftRequirement is returned when the manifest contains an invalid Minecraft requirement.
	ErrInvalidMinecraftRequirement = ValidationError{

		Path:  "requirements.minecraft",
		Level: ErrorLevelFatal,
		// contains filtered or unexported fields
	}
	// ErrNoLoaderRequirement is returned when the manifest does not contain a loader requirement.
	ErrNoLoaderRequirement = ValidationError{

		Path:  "requirements",
		Level: ErrorLevelFatal,
		// contains filtered or unexported fields
	}
	// ErrInvalidFabricLoaderRequirement is returned when the manifest contains an invalid Fabric loader requirement.
	ErrInvalidFabricLoaderRequirement = ValidationError{

		Path:  "requirements.fabric",
		Level: ErrorLevelFatal,
		// contains filtered or unexported fields
	}
)

Functions

This section is empty.

Types

type Dependencies

type Dependencies map[string]string

Dependencies are the dependencies of a mod or modpack as a map

type DependencyLock

type DependencyLock struct {
	Name        string `toml:"name" json:"name"`
	Version     string `toml:"version" json:"version"`
	VersionName string `toml:"versionName" json:"versionName"`
	Type        string `toml:"type" json:"type"`
	IPFSHash    string `toml:"ipfsHash" json:"ipfsHash"`
	Sha1        string `toml:"Sha1,omitempty" json:"Sha1,omitempty"`
	Sha256      string `toml:"Sha256,omitempty" json:"Sha256,omitempty"`
	Sha512      string `toml:"Sha512,omitempty" json:"Sha512,omitempty"`
	URL         string `toml:"url" json:"url"`
	// Provider usually is minepkg but can also be https
	Provider string `toml:"provider" json:"provider"`
	// Dependent is the package that requires this mod. can be _root if top package
	Dependent string `toml:"dependent" json:"dependent"`
	// IsDev is true if this is a dev dependency
	IsDev bool `toml:"isDev,omitempty" json:"isDev,omitempty"`
}

DependencyLock is a single resolved dependency

func (*DependencyLock) FileExt

func (d *DependencyLock) FileExt() string

FileExt returns ".jar" for mods and ".zip" for modpacks

func (*DependencyLock) Filename

func (d *DependencyLock) Filename() string

Filename returns the dependency in the "[name]-[version].jar" format

type FabricLock

type FabricLock struct {
	Minecraft    string `toml:"minecraft" json:"minecraft"`
	FabricLoader string `toml:"fabricLoader" json:"fabricLoader"`
	Mapping      string `toml:"mapping" json:"mapping"`
}

FabricLock describes resolved fabric requirements

func (*FabricLock) MinecraftVersion

func (f *FabricLock) MinecraftVersion() string

MinecraftVersion returns the minecraft version

func (*FabricLock) PlatformName

func (f *FabricLock) PlatformName() string

PlatformName returns the string fabric

func (*FabricLock) PlatformVersion

func (f *FabricLock) PlatformVersion() string

PlatformVersion returns the fabric mod loader version

type ForgeLock

type ForgeLock struct {
	Minecraft   string `toml:"minecraft" json:"minecraft"`
	ForgeLoader string `toml:"forgeLoader" json:"forgeLoader"`
}

ForgeLock describes resolved forge requirements this is not used for now, because forge does not provide a API to resolve this

func (*ForgeLock) MinecraftVersion

func (f *ForgeLock) MinecraftVersion() string

MinecraftVersion returns the minecraft version

func (*ForgeLock) PlatformName

func (f *ForgeLock) PlatformName() string

PlatformName returns the string vanilla

func (*ForgeLock) PlatformVersion

func (f *ForgeLock) PlatformVersion() string

MinecraftVersion returns the forge loader version

type InterpretedDependency

type InterpretedDependency struct {
	// Provider is the system that should be used to fetch this dependency.
	// This usually is `minepkg` and can also be `https`. There might be more providers in the future
	Provider string
	// Name is the name of the package
	Name string
	// Source is what `Provider` will need to fetch the given Dependency
	// In practice this is a version number for `Provider === "minepkg"` and
	// a https url for `Provider === "https"`
	Source string
	// IsDev is true if this is a dev dependency
	IsDev bool

	ID *pkgid.ID
}

InterpretedDependency is a key-value dependency that has been interpreted. It can help to fetch the dependency more easily

type Lockfile

type Lockfile struct {
	LockfileVersion int                        `toml:"lockfileVersion" json:"lockfileVersion"`
	Fabric          *FabricLock                `toml:"fabric,omitempty" json:"fabric,omitempty"`
	Forge           *ForgeLock                 `toml:"forge,omitempty" json:"forge,omitempty"`
	Vanilla         *VanillaLock               `toml:"vanilla,omitempty" json:"vanilla,omitempty"`
	Dependencies    map[string]*DependencyLock `toml:"dependencies,omitempty" json:"dependencies,omitempty"`
}

Lockfile includes resolved dependencies and requirements

func NewLockfile

func NewLockfile() *Lockfile

NewLockfile returns a new lockfile

func NewLockfileFromFile added in v0.1.5

func NewLockfileFromFile(filename string) (*Lockfile, error)

NewFromFile tries to parse a local lockfile file

func (*Lockfile) AddDependency

func (l *Lockfile) AddDependency(dep *DependencyLock)

AddDependency adds a new dependency to the lockfile

func (*Lockfile) Buffer

func (l *Lockfile) Buffer() *bytes.Buffer

Buffer returns the manifest as toml in Buffer form

func (*Lockfile) ClearDependencies

func (l *Lockfile) ClearDependencies()

ClearDependencies removes all dependencies

func (*Lockfile) HasRequirements

func (l *Lockfile) HasRequirements() bool

HasRequirements returns true if lockfile has some requirements

func (*Lockfile) McManifestName

func (l *Lockfile) McManifestName() string

McManifestName returns the Minecraft Launcher Manifest name

func (*Lockfile) MinecraftVersion

func (l *Lockfile) MinecraftVersion() string

MinecraftVersion returns the Minecraft version

func (*Lockfile) PlatformLock

func (l *Lockfile) PlatformLock() PlatformLock

PlatformLock returns the platform lock object (fabric, forge or vanilla lock)

func (*Lockfile) String

func (l *Lockfile) String() string

type Manifest

type Manifest struct {
	// ManifestVersion specifies the format version
	// This field is REQUIRED, current version is 0
	ManifestVersion int `toml:"manifestVersion" comment:"Preview of the minepkg.toml format! Could break anytime!" json:"manifestVersion"`
	Package         struct {
		// Type should be one of `TypeMod` ("mod") or `TypeModpack` ("modpack")
		// this field is REQUIRED
		Type string `toml:"type" json:"type"`
		// Name is the name of the package. It may NOT include spaces. It may ONLY consist of
		// alphanumeric chars but can also include `-` and `_`
		// Should be unique. (This will be enforced by the minepkg api)
		// This field is REQUIRED
		Name string `toml:"name" json:"name"`
		// Description can be any free text that describes this package. Should be short(ish)
		Description string `toml:"description" json:"description"`
		// Version is the version number of this package. A proceeding `v` (like `v2.1.1`) is NOT
		// allowed to preserve consistency
		// The version may include prerelease information like `1.2.2-beta.0` or build
		// related information `1.2.1+B7382-2018`.
		// The version can be omitted. Publishing will require a version number as flag in that case
		Version string `toml:"version,omitempty" json:"version,omitempty"`
		// Platform indicates the supported playform of this package. can be `fabric`, `forge` or `vanilla`
		Platform string `toml:"platform,omitempty" json:"platform,omitempty"`
		// Licence for this project. Should be a valid SPDX identifier if possible
		// see https://spdx.org/licenses/
		License string `toml:"license,omitempty" json:"license,omitempty"`
		// Source is an URL that should point to the source code repository of this package (if any)
		Source string `toml:"source,omitempty" json:"source,omitempty"`
		// Homepage is an URL that should point to the website of this package (if any)
		Homepage string `toml:"homepage,omitempty" json:"homepage,omitempty"`
		// Author in the form of "Full Name <email@example.com>". Email can be omitted and Full Name does not have to be a real name
		Author string `toml:"author,omitempty" json:"author,omitempty"`
		// BasedOn can be a another package that this one is based on.
		// Most notably, this field is used for instances to determine what modpack is actually running
		// This field is striped when publishing the package to the minepkg api
		BasedOn string `toml:"basedOn,omitempty" json:"basedOn,omitempty"`
		// Savegame can be the name of the primary savegame on this modpack. Not applicable for other package types.
		// This savegame will be used when launching this package via `minepkg try`.
		// This should be the folder name of the savegame
		Savegame string `toml:"savegame,omitempty" json:"savegame,omitempty"`
	} `toml:"package" json:"package"`
	Requirements struct {
		// Minecraft is a semver version string describing the required Minecraft version
		// The Minecraft version is binding and implementers should not install
		// Mods for non-matching Minecraft versions.
		// Modpack & Mod Authors are encouraged to use semver to allow a broader install range.
		// This field is REQUIRED
		Minecraft string `toml:"minecraft" json:"minecraft"`
		// FabricLoader is a semver version string describing the required FabricLoader version
		// Only one of `Forge` or `FabricLoader` may be used
		FabricLoader string `toml:"fabricLoader,omitempty" json:"fabricLoader,omitempty"`
		// ForgeLoader is the minimum forge version required
		// no semver here, because forge does not follow semver
		ForgeLoader string `toml:"forgeLoader,omitempty" json:"forgeLoader,omitempty"`
		// MinepkgCompanion is the version of the minepkg companion plugin that is going to be added to modpacks.
		// This has no effect on other types of packages
		// `latest` is assumed if this field is omitted. `none` can be used to exclude the companion
		// plugin from a modpack – but this is not recommended
		MinepkgCompanion string `toml:"minepkgCompanion,omitempty" json:"minepkgCompanion,omitempty"`
		// old names, are only here for migration
		Fabric string `toml:"fabric,omitempty" json:"fabric,omitempty"`
		Forge  string `toml:"forge,omitempty" json:"forge,omitempty"`
	} `toml:"requirements" comment:"These are global requirements" json:"requirements"`
	// Dependencies lists runtime dependencies of this package
	// this list can contain mods and modpacks
	Dependencies `toml:"dependencies" json:"dependencies,omitempty"`
	// Dev contains development & testing related options
	Dev struct {
		// BuildCommand is the command used for building this package (usually "./gradlew build")
		BuildCommand string `toml:"buildCommand,omitempty" json:"buildCommand,omitempty"`
		// Jar defines the target location glob to the built jar file for mods. Can be empty. Example: "lib/builds/my-mod-v*.jar"
		Jar string `toml:"jar,omitempty" json:"jar,omitempty"`
		// Dependencies inside the dev struct should only be installed if this package is defined locally.
		// They should never be installed for published packages
		Dependencies `toml:"dependencies,omitempty" json:"dependencies,omitempty"`
	} `toml:"dev" json:"dev"`
}

Manifest is a collection of data that describes a mod a modpack

Example (Marshal)

Marshal a struct to toml

package main

import (
	"fmt"

	"github.com/minepkg/minepkg/pkg/manifest"
)

func main() {
	manifest := manifest.New()
	manifest.Package.Name = "test-mansion"

	fmt.Println(manifest.String()) // or manifest.Buffer() to get it as a buffer
}
Output:

Example (Unmarshal)

Unmarshal a toml to a manifest struct

raw := []byte(`
	manifestVersion = 0
	[package]
	name="test-utils"
	version="1.0.0"
`)
var man manifest.Manifest
toml.Unmarshal(raw, &man)
fmt.Println(man.Package.Name)
Output:

test-utils

func New

func New() *Manifest

New returns a new manifest

func NewFromFile added in v0.1.5

func NewFromFile(filename string) (*Manifest, error)

NewFromFile tries to parse a local manifest file

func NewInstanceLike

func NewInstanceLike(from *Manifest) *Manifest

NewInstanceLike takes an existing manifest and copies most fields

func (*Manifest) AddDependency

func (m *Manifest) AddDependency(name string, version string)

AddDependency adds a new dependency to the manifest

func (*Manifest) AddDevDependency added in v0.0.61

func (m *Manifest) AddDevDependency(name string, version string)

AddDevDependency adds a new dev dependency to the manifest

func (*Manifest) AuthorEmail added in v0.0.62

func (m *Manifest) AuthorEmail() string

AuthorEmail returns the email of the author or empty string if none is set

func (*Manifest) AuthorName added in v0.0.62

func (m *Manifest) AuthorName() string

AuthorName returns the name of the author (excluding the email address if set)

func (*Manifest) Buffer

func (m *Manifest) Buffer() *bytes.Buffer

Buffer returns the manifest as toml in Buffer form

func (*Manifest) InterpretedDependencies

func (m *Manifest) InterpretedDependencies() []*InterpretedDependency

InterpretedDependencies returns the dependencies in a `[]*InterpretedDependency` slice. See `InterpretedDependency` for details

func (*Manifest) InterpretedDevDependencies added in v0.0.61

func (m *Manifest) InterpretedDevDependencies() []*InterpretedDependency

InterpretedDevDependencies returns the dev.dependencies in a `[]*InterpretedDependency` slice. See `InterpretedDependency` for details

func (*Manifest) PlatformString

func (m *Manifest) PlatformString() string

PlatformString returns the required platform as a string (vanilla, fabric or forge)

func (*Manifest) PlatformVersion

func (m *Manifest) PlatformVersion() string

PlatformVersion returns the required platform version

func (*Manifest) RemoveDependency

func (m *Manifest) RemoveDependency(name string)

RemoveDependency removes a dependency from the manifest

func (*Manifest) RemoveDevDependency added in v0.0.61

func (m *Manifest) RemoveDevDependency(name string)

RemoveDevDependency removes a dev dependency from the manifest

func (*Manifest) String

func (m *Manifest) String() string

func (*Manifest) Validate added in v0.1.3

func (m *Manifest) Validate() Problems

Validate checks the manifest for correctness.

type PlatformLock

type PlatformLock interface {
	PlatformName() string
	MinecraftVersion() string
	PlatformVersion() string
}

PlatformLock describes a queryable platform (fabric, forge)

type PlatformRequirement added in v0.1.13

type PlatformRequirement struct {
	Minecraft     string `toml:"minecraft"`
	LoaderName    string `toml:"loader"`
	LoaderVersion string `toml:"loader_version"`
}

func (*PlatformRequirement) MinecraftVersion added in v0.1.13

func (p *PlatformRequirement) MinecraftVersion() string

func (*PlatformRequirement) PlatformName added in v0.1.13

func (p *PlatformRequirement) PlatformName() string

func (*PlatformRequirement) PlatformVersion added in v0.1.13

func (p *PlatformRequirement) PlatformVersion() string

type Problems added in v0.1.3

type Problems []ValidationError

func (*Problems) Fatal added in v0.1.3

func (p *Problems) Fatal() error

Fatal returns the first fatal error in the list. If there are no fatal errors, it returns nil.

type ValidationError added in v0.1.3

type ValidationError struct {
	Path  string
	Level int
	// contains filtered or unexported fields
}

func (ValidationError) Error added in v0.1.3

func (e ValidationError) Error() string

type VanillaLock

type VanillaLock struct {
	Minecraft string `toml:"minecraft" json:"minecraft"`
}

VanillaLock describes resolved vanilla requirements

func (*VanillaLock) MinecraftVersion

func (v *VanillaLock) MinecraftVersion() string

MinecraftVersion returns the minecraft version

func (*VanillaLock) PlatformName

func (v *VanillaLock) PlatformName() string

PlatformName returns the string vanilla

func (*VanillaLock) PlatformVersion

func (f *VanillaLock) PlatformVersion() string

PlatformVersion returns ""

Jump to

Keyboard shortcuts

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