parser

package
v1.0.0-beta.17 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package parser provides a bunch of implementations for Parser function from generate package.

Either those can be used indivually to enrich metadata given in input of every parser or as a whole with Defaults function.

Example:

// one specific parser
func main() {
	handlers, err := parser.Git(ctx, "path/to/dir", metadata) // metadata is updated in the process
	// handle err
}

// as a whole
func main() {
	for _, p := range parser.Defaults() {
		handlers, err := p(ctx, "path/to/dir", metadata) // metadata is updated in the process
		// handle err
	}
}

// fully used with generate.Run
func main() {
	// config (craft.Configuration) is updated during the process
	// and returned updated at the end
	config, err := generate.Run(ctx, config, generate.WithParsers(parser.Defaults()...))
	// handle err
}

Index

Constants

View Source
const (
	// GitLabURL is the default GitLab API URL.
	GitLabURL = "https://gitlab.com/api/v4"

	// GitHubURL is the default GitHub API URL.
	GitHubURL = "https://api.github.com"
)
View Source
const HTTPClientKey httpClientKeyType = "http_client"

HTTPClientKey is the context key for the http client.

It is used during License parsing in case a custom http client needs to be provided. Example:

ctx := context.WithValue(context.Background(), parser.HTTPClientKey, &http.Client{})

Variables

View Source
var (
	// ErrMissingModuleStatement is the error returned when module statement is missing from go.mod.
	ErrMissingModuleStatement = errors.New("invalid go.mod, module statement is missing")

	// ErrMissingGoStatement is the error returned when go statement is missing from go.mod.
	ErrMissingGoStatement = errors.New("invalid go.mod, go statement is missing")
)
View Source
var (
	// ErrInvalidStaticDeployment represents the returned error when static deployment is provided in craft configuration
	// but current node project doesn't have a main file provided in package.json.
	ErrInvalidStaticDeployment = errors.New("package.json 'main' isn't provided but a static deployment is configured")

	// ErrInvalidPackageManager is the error returned when packageManager is missing or invalid in package.json.
	ErrInvalidPackageManager = errors.New("package.json 'packageManager' is missing or isn't valid")
)

Functions

func Defaults

func Defaults(parsers ...generate.Parser) []generate.Parser

Defaults returns the full slice of handlers implemented in parser package.

func GetHTTPClient

func GetHTTPClient(ctx context.Context) *http.Client

GetHTTPClient returns the context http client.

By default it will be cleanhttp.DefaultClient, but it can be set following this example:

ctx := context.WithValue(context.Background(), parser.HTTPClientKey, &http.Client{})

func Git

func Git(ctx context.Context, destdir string, metadata *generate.Metadata) error

Git reads the input destdir directory remote.origin.url to retrieve various project information (git host, project name, etc.).

func Golang

func Golang(ctx context.Context, destdir string, metadata *generate.Metadata) error

Golang handles the parsing of a golang repository at destdir.

A valid golang project must have a valid go.mod file.

func Helm

func Helm(ctx context.Context, destdir string, metadata *generate.Metadata) error

Helm parses helm partin destdir repository.

func License

func License(ctx context.Context, destdir string, metadata *generate.Metadata) error

License generates the LICENSE file in case input configuration asks for a LICENSE file.

func Node

func Node(ctx context.Context, destdir string, metadata *generate.Metadata) error

Node handles node repository parsing at destdir.

It scans the project for a package.json and validates it.

Types

type Gomod

type Gomod struct {
	LangVersion string
	Platform    string
	ProjectHost string
	ProjectName string
	ProjectPath string
}

Gomod represents the parsed struct for go.mod file

type PackageJSON

type PackageJSON struct {
	Author         *string  `json:"author,omitempty"`
	Description    *string  `json:"description,omitempty"`
	Files          []string `json:"files,omitempty"`
	Keywords       []string `json:"keywords,omitempty"`
	License        *string  `json:"license,omitempty"`
	Main           *string  `json:"main,omitempty"`
	Module         string   `json:"module,omitempty"`
	Name           string   `json:"name,omitempty"           validate:"required"`
	PackageManager string   `json:"packageManager,omitempty" validate:"required"`
	Private        bool     `json:"private,omitempty"`
	PublishConfig  struct {
		Access     string `json:"access,omitempty"`
		Provenance bool   `json:"provenance,omitempty"`
		Registry   string `json:"registry,omitempty"`
		Tag        string `json:"tag,omitempty"`
	} `json:"publishConfig,omitempty"`
	Repository *struct {
		URL string `json:"url,omitempty" validate:"required"`
	} `json:"repository,omitempty" validate:"required_if=Private false"`
	Scripts map[string]string `json:"scripts,omitempty"`
	Version string            `json:"version,omitempty"`
}

PackageJSON represents the node package json descriptor.

func (*PackageJSON) Validate

func (p *PackageJSON) Validate() error

Validate validates the given PackageJSON struct.

Jump to

Keyboard shortcuts

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