pawnpackage

package
v0.0.0-...-e289d49 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: GPL-3.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Package

type Package struct {
	// Parent indicates that this package is a "working" package that the user has explicitly
	// created and is developing. The opposite of this would be packages that exist in the
	// `dependencies` directory that have been downloaded as a result of an Ensure.
	Parent bool `json:"-" yaml:"-"`
	// LocalPath indicates the Package object represents a local copy which is a directory
	// containing a `samp.json`/`samp.yaml` file and a set of Pawn source code files.
	// If this field is not set, then the Package is just an in-memory pointer to a remote package.
	LocalPath string `json:"-" yaml:"-"`
	// The vendor directory - for simple packages with no sub-dependencies, this is simply
	// `<local>/dependencies` but for nested dependencies, this needs to be set.
	Vendor string `json:"-" yaml:"-"`
	// format stores the original format of the package definition file, either `json` or `yaml`
	Format string `json:"-" yaml:"-"`

	// Inferred metadata, not always explicitly set via JSON/YAML but inferred from the dependency path
	versioning.DependencyMeta `yaml:"-,inline"`

	// Metadata, set by the package author to describe the package
	Contributors []string `json:"contributors,omitempty" yaml:"contributors,omitempty"` // list of contributors
	Website      string   `json:"website,omitempty" yaml:"website,omitempty"`           // website or forum topic associated with the package

	// Functional, set by the package author to declare relevant files and dependencies
	Entry        string                        `json:"entry,omitempty" yaml:"entry,omitempty"`                       // entry point script to compile the project
	Output       string                        `json:"output,omitempty" yaml:"output,omitempty"`                     // output amx file
	Dependencies []versioning.DependencyString `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`         // list of packages that the package depends on
	Development  []versioning.DependencyString `json:"dev_dependencies,omitempty" yaml:"dev_dependencies,omitempty"` // list of packages that only the package builds depend on
	Local        bool                          `json:"local,omitempty" yaml:"local,omitempty"`                       // run package in local dir instead of in a temporary runtime
	Runtime      *run.Runtime                  `json:"runtime,omitempty" yaml:"runtime,omitempty"`                   // runtime configuration
	Runtimes     []*run.Runtime                `json:"runtimes,omitempty" yaml:"runtimes,omitempty"`                 // multiple runtime configurations
	Build        *build.Config                 `json:"build,omitempty" yaml:"build,omitempty"`                       // build configuration
	Builds       []*build.Config               `json:"builds,omitempty" yaml:"builds,omitempty"`                     // multiple build configurations
	IncludePath  string                        `json:"include_path,omitempty" yaml:"include_path,omitempty"`         // include path within the repository, so users don't need to specify the path explicitly
	Resources    []resource.Resource           `json:"resources,omitempty" yaml:"resources,omitempty"`               // list of additional resources associated with the package
}

Package represents a definition for a Pawn package and can either be used to define a build or as a description of a package in a repository. This is akin to npm's package.json and combines a project's dependencies with a description of that project.

For example, a gamemode that includes a library does not need to define the User, Repo, Version, Contributors and Include fields at all, it can just define the Dependencies list in order to build correctly.

On the flip side, a library written in pure Pawn should define some contributors and a web URL but, being written in pure Pawn, has no dependencies.

Finally, if a repository stores its package source files in a subdirectory, that directory should be specified in the Include field. This is common practice for plugins that store the plugin source code in the root and the Pawn source in a subdirectory called 'include'. nolint:lll

func GetCachedPackage

func GetCachedPackage(meta versioning.DependencyMeta, cacheDir string) (pkg Package, err error)

GetCachedPackage returns a package using the cached copy, if it exists

func GetRemotePackage

func GetRemotePackage(
	ctx context.Context,
	client *github.Client,
	meta versioning.DependencyMeta,
) (pkg Package, err error)

GetRemotePackage attempts to get a package definition for the given dependency meta. It first checks the the sampctl central repository, if that fails it falls back to using the repository for the package itself. This means upstream changes to plugins can be first staged in the official central repository before being pulled to the package specific repository.

func PackageFromDep

func PackageFromDep(depString versioning.DependencyString) (pkg Package, err error)

PackageFromDep creates a Package object from a Dependency String

func PackageFromDir

func PackageFromDir(dir string) (pkg Package, err error)

PackageFromDir attempts to parse a pawn.json or pawn.yaml file from a directory

func PackageFromOfficialRepo

func PackageFromOfficialRepo(
	ctx context.Context,
	client *github.Client,
	meta versioning.DependencyMeta,
) (pkg Package, err error)

PackageFromOfficialRepo attempts to get a package from the sampctl/plugins official repository this repo is mainly only used for testing plugins before being PR'd into their respective repos.

func PackageFromRepo

func PackageFromRepo(
	ctx context.Context,
	client *github.Client,
	meta versioning.DependencyMeta,
) (pkg Package, err error)

PackageFromRepo attempts to get a package from the given package definition's public repo

func (Package) GetAllDependencies

func (pkg Package) GetAllDependencies() (result []versioning.DependencyString)

GetAllDependencies returns the Dependencies and the Development dependencies in one list

func (Package) GetBuildConfig

func (pkg Package) GetBuildConfig(name string) (config *build.Config)

GetBuildConfig returns a matching build by name from the package build list. If no name is specified, the first build is returned. If the package has no build definitions, a default configuration is returned.

func (Package) GetRuntimeConfig

func (pkg Package) GetRuntimeConfig(name string) (config run.Runtime, err error)

GetRuntimeConfig returns a matching runtime config by name from the package runtime list. If no name is specified, the first config is returned. If the package has no configurations, a default configuration is returned.

func (Package) String

func (pkg Package) String() string

func (Package) Validate

func (pkg Package) Validate() (err error)

Validate checks a package for missing fields

func (Package) WriteDefinition

func (pkg Package) WriteDefinition() (err error)

WriteDefinition creates a JSON or YAML file for a package object, the format depends on the `Format` field of the package.

Jump to

Keyboard shortcuts

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