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
- Variables
- func Defaults(parsers ...generate.Parser) []generate.Parser
- func GetHTTPClient(ctx context.Context) *http.Client
- func Git(ctx context.Context, destdir string, metadata *generate.Metadata) error
- func Golang(ctx context.Context, destdir string, metadata *generate.Metadata) error
- func Helm(ctx context.Context, destdir string, metadata *generate.Metadata) error
- func License(ctx context.Context, destdir string, metadata *generate.Metadata) error
- func Node(ctx context.Context, destdir string, metadata *generate.Metadata) error
- type Gomod
- type PackageJSON
Constants ¶
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" )
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 ¶
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") )
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 GetHTTPClient ¶
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 ¶
Git reads the input destdir directory remote.origin.url to retrieve various project information (git host, project name, etc.).
func Golang ¶
Golang handles the parsing of a golang repository at destdir.
A valid golang project must have a valid go.mod file.
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.