modules

package
v0.59.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2019 License: Apache-2.0 Imports: 25 Imported by: 11

Documentation

Overview

Package modules provides a client that can be used to manage Hugo Components, what's referred to as Hugo Modules. Hugo Modules is built on top of Go Modules, but also supports vendoring and components stored directly in the themes dir.

Index

Constants

This section is empty.

Variables

View Source
var DefaultModuleConfig = Config{

	Proxy: "direct",

	NoProxy: "none",

	Private: "*.*",
}
View Source
var ErrNotExist = errors.New("module does not exist")

Functions

func ApplyProjectConfigDefaults

func ApplyProjectConfigDefaults(cfg config.Provider, mod Module) error

ApplyProjectConfigDefaults applies default/missing module configuration for the main project.

func IsNotExist

func IsNotExist(err error) bool

IsNotExist returns whether an error means that a module could not be found.

Types

type Client

type Client struct {

	// Set when Go modules are initialized in the current repo, that is:
	// a go.mod file exists.
	GoModulesFilename string
	// contains filtered or unexported fields
}

Client contains most of the API provided by this package.

func NewClient

func NewClient(cfg ClientConfig) *Client

NewClient creates a new Client that can be used to manage the Hugo Components in a given workingDir. The Client will resolve the dependencies recursively, but needs the top level imports to start out.

func (*Client) Collect

func (h *Client) Collect() (ModulesConfig, error)

func (*Client) Get

func (c *Client) Get(args ...string) error

Get runs "go get" with the supplied arguments.

func (*Client) Graph

func (c *Client) Graph(w io.Writer) error

Graph writes a module dependenchy graph to the given writer.

func (*Client) Init

func (c *Client) Init(path string) error

Init initializes this as a Go Module with the given path. If path is empty, Go will try to guess. If this succeeds, this project will be marked as Go Module.

func (*Client) Tidy

func (c *Client) Tidy() error

Tidy can be used to remove unused dependencies from go.mod and go.sum.

func (*Client) Vendor

func (c *Client) Vendor() error

Vendor writes all the module dependencies to a _vendor folder.

Unlike Go, we support it for any level.

We, by default, use the /_vendor folder first, if found. To disable, run with

hugo --ignoreVendor

Given a module tree, Hugo will pick the first module for a given path, meaning that if the top-level module is vendored, that will be the full set of dependencies.

type ClientConfig

type ClientConfig struct {
	Fs     afero.Fs
	Logger *loggers.Logger

	// If set, it will be run before we do any duplicate checks for modules
	// etc.
	HookBeforeFinalize func(m *ModulesConfig) error

	// Ignore any _vendor directory.
	IgnoreVendor bool

	// Absolute path to the project dir.
	WorkingDir string

	// Absolute path to the project's themes dir.
	ThemesDir string

	CacheDir     string // Module cache
	ModuleConfig Config
}

ClientConfig configures the module Client.

type Config

type Config struct {
	Mounts  []Mount
	Imports []Import

	// Meta info about this module (license information etc.).
	Params map[string]interface{}

	// Will be validated against the running Hugo version.
	HugoVersion HugoVersion

	// Configures GOPROXY.
	Proxy string
	// Configures GONOPROXY.
	NoProxy string
	// Configures GOPRIVATE.
	Private string
}

Config holds a module config.

func DecodeConfig

func DecodeConfig(cfg config.Provider) (Config, error)

DecodeConfig creates a modules Config from a given Hugo configuration.

type HugoVersion

type HugoVersion struct {
	// The minimum Hugo version that this module works with.
	Min hugo.VersionString

	// The maxium Hugo version that this module works with.
	Max hugo.VersionString

	// Set if the extended version is needed.
	Extended bool
}

HugoVersion holds Hugo binary version requirements for a module.

func (HugoVersion) IsValid

func (v HugoVersion) IsValid() bool

IsValid reports whether this version is valid compared to the running Hugo binary.

func (HugoVersion) String

func (v HugoVersion) String() string

type Import

type Import struct {
	Path         string // Module path
	IgnoreConfig bool   // Ignore any config.toml found.
	Disable      bool   // Turn off this module.
	Mounts       []Mount
}

type Module

type Module interface {

	// Optional config read from the configFilename above.
	Cfg() config.Provider

	// The decoded module config and mounts.
	Config() Config

	// Optional configuration filename (e.g. "/themes/mytheme/config.json").
	// This will be added to the special configuration watch list when in
	// server mode.
	ConfigFilename() string

	// Directory holding files for this module.
	Dir() string

	// This module is disabled.
	Disabled() bool

	// Returns whether this is a Go Module.
	IsGoMod() bool

	// Any directory remappings.
	Mounts() []Mount

	// In the dependency tree, this is the first module that defines this module
	// as a dependency.
	Owner() Module

	// Returns the path to this module.
	// This will either be the module path, e.g. "github.com/gohugoio/myshortcodes",
	// or the path below your /theme folder, e.g. "mytheme".
	Path() string

	// Replaced by this module.
	Replace() Module

	// Returns whether Dir points below the _vendor dir.
	Vendor() bool

	// The module version.
	Version() string

	// Whether this module's dir is a watch candidate.
	Watch() bool
}

func CreateProjectModule

func CreateProjectModule(cfg config.Provider) (Module, error)

CreateProjectModule creates modules from the given config. This is used in tests only.

type Modules

type Modules []Module

type ModulesConfig

type ModulesConfig struct {
	// All modules, including any disabled.
	AllModules Modules

	// All active modules.
	ActiveModules Modules

	// Set if this is a Go modules enabled project.
	GoModulesFilename string
}

type Mount

type Mount struct {
	Source string // relative path in source repo, e.g. "scss"
	Target string // relative target path, e.g. "assets/bootstrap/scss"

	Lang string // any language code associated with this mount.
}

func (Mount) Component

func (m Mount) Component() string

Jump to

Keyboard shortcuts

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