core

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package core provides the verless business logic.

Each verless sub-command maintains its own file in the core package, like build.go for `verless build`. This file provides a function in the form Run<Sub-Command>, e.g. RunBuild, serving as an entry point for other packages.

Sub-commands of sub-commands like `verless create project` don't require an own file, they can just be grouped together in a common file like create.go.

An entry point function either implements the business logic itself like RunVersion does, or prepares components and passes them to an inner core package for more complex scenarios.

Typically, a verless command has multiple options. These options are types in the core package, declared in the command's file. They have to be initialized by the caller - for example the cli package - and then passed to the entry point function. The name of an option type must be in the form <Sub-Command>Options like BuildOptions. Options for sub-commands of sub-commands like `verless create project` must have a name in the form <Sub-Command><Sub-Command>Options, like CreateProjectOptions.

As a result, most entry point functions accept a dedicated options instance. Some of them also require an initialized config instance or fixed command line arguments - see RunBuild as an example.

Core functions typically shouldn't have outgoing dependencies except for dependencies like the fs or model packages. Instead, they should define their dependencies as interfaces which can be implemented by outside packages. A good example for this is build.Parser implemented by parser.Markdown.

It is the entry point function's job to initialize those external dependencies, like calling parser.NewMarkdown, and passing it to the particular core function. Again, RunBuild is good example for this.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCannotOverwrite states that verless isn't allowed to
	// delete or overwrite the output directory.
	ErrCannotOverwrite = errors.New(`Cannot overwrite the output directory.
Consider using the --overwrite flag or enabled build.overwrite in the configuration file.`)
)

Functions

func RunBuild

func RunBuild(fs afero.Fs, path string, options BuildOptions, cfg config.Config) error

RunBuild triggers a build using the provided options and user configuration.

See doc.go for more information on the core architecture.

func RunCreateProject

func RunCreateProject(path string, options CreateProjectOptions) error

RunCreateProject creates a new verless project. If the specified project path already exists, RunCreateProject returns an error unless --overwrite has been used.

func RunServe added in v0.3.0

func RunServe(path string, options ServeOptions) error

RunServe serves a verless project using a simple file server. It can build the project automatically if ServeOptions.Build is true and even watch the whole project directory for changes if ServeOptions.Watch is true.

func RunVersion

func RunVersion(options VersionOptions) error

RunVersion prints verless version information.

Types

type BuildOptions

type BuildOptions struct {
	// OutputDir sets the output directory. If this field is empty,
	// config.OutputDir will be used.
	OutputDir string
	// Overwrite specifies that the output folder can be overwritten.
	Overwrite bool
	// RecompileTemplates forces a recompilation of all templates.
	RecompileTemplates bool
}

BuildOptions represents options for running a verless build.

type CreateProjectOptions

type CreateProjectOptions struct {
	Overwrite bool
}

CreateProjectOptions represents options for creating a new verless project.

type ServeOptions added in v0.3.0

type ServeOptions struct {
	// BuildOptions stores all options for re-builds when watching the site.
	BuildOptions

	// Port specifies the port to run the server at.
	Port uint16

	// IP specifies the IP to listen on in combination with the port.
	IP net.IP

	// Watch enables automatic re-builds when a file changes.
	Watch bool
}

ServeOptions represents options for running a verless serve command.

type VersionOptions

type VersionOptions struct {
	// Quiet only prints the plain version number.
	Quiet bool
}

VersionOptions represents options for the version command.

Directories

Path Synopsis
Package build provides verless' core build functionality.
Package build provides verless' core build functionality.
Package serve provides verless' core serve functionality.
Package serve provides verless' core serve functionality.
Package watch provides verless' ability to watch a project and react to changes in a verless project.
Package watch provides verless' ability to watch a project and react to changes in a verless project.

Jump to

Keyboard shortcuts

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