Documentation
¶
Overview ¶
Package gosu is a project build tool for Go in the spirit of Rake, Grunt, Gulp and others. Gosu supports watching, tasks and restarting go apps.
To install
go get -u github.com/mgutz/gosu/cmd/gosu
As an example, create a file 'tasks/Gosufile.go' wit this content
package main
import (
. "github.com/mgutz/gosu"
)
func Tasks(p *Project) {
p.Task("default", D{"hello, "views"})
p.Task("hello", func() {
Run(`bash -c "echo Hello $USER!"`)
})
p.Task("views", "Compiles razor templates", W{"**/*.go.html"}, func(c *Context) {
Run('razor views')
})
p.Task("server", D{"views"}, W{"**/*.go}, Debounce(3000), func() {
// Start recompiles and restarts on changes when watching
Start("main.go", M{"Dir": "example"})
})
}
func main() {
Gosu(Tasks)
}
To run "views" task from terminal
gosu views
To rerun "views" whenever any `*.go.html` file changes
gosu views --watch
To run the "default" task which runs "hello" and "views"
gosu
Task names may add a "?" suffix to indicate run only once
// run once regardless of number of dependees
p.Task("build?", func() {})
Task options
D{} or Dependencies{} - dependent tasks which run before task
Debounce - minimum milliseconds before task can run again
W{} or Watches{} - array of glob file patterns to watch
/**/ - match zero or more directories
{a,b} - match a or b, no spaces
* - match any non-separator char
? - match a single non-separator char
**/ - match any directory, start of pattern only
/** - match any this directory, end of pattern only
! - removes files from resultset, start of pattern only
Task handlers
func() {} - Simple function handler
func(c *Context) {} - Handler which accepts the current context
Index ¶
- Variables
- func Glob(patterns []string) ([]*FileAsset, []*RegexpInfo, error)
- func Globexp(glob string) *regexp.Regexp
- func Gosu(tasksFunc func(*Project))
- func Run(command string, options ...map[string]interface{})
- func Start(command string, options ...map[string]interface{})
- func StartAsync(isAsync bool, command string, options ...map[string]interface{}) error
- type Context
- type D
- type Debounce
- type Dependencies
- type FileAsset
- type M
- type Project
- func (project *Project) Define(fn func(*Project))
- func (project *Project) Run(name string)
- func (project *Project) Task(name string, args ...interface{}) *Task
- func (project *Project) Usage()
- func (project *Project) Use(namespace string, tasksFunc func(*Project))
- func (project *Project) Watch(names []string, isParent bool)
- type RegexpInfo
- type Task
- type W
- type Watch
Constants ¶
This section is empty.
Variables ¶
var DebounceMs int64
DebounceMs is the default time (1500 ms) to debounce task events in watch mode.
Functions ¶
func Glob ¶
func Glob(patterns []string) ([]*FileAsset, []*RegexpInfo, error)
Glob returns files and dirctories that match patterns. Patterns must use slashes, even Windows.
Special chars.
/**/ - match zero or more directories
{a,b} - match a or b, no spaces
* - match any non-separator char
? - match a single non-separator char
**/ - match any directory, start of pattern only
/** - match any this directory, end of pattern only
! - removes files from resultset, start of pattern only
func Globexp ¶
Globexp builds a regular express from from extended glob pattern and then returns a Regexp object from the pattern.
func Run ¶
Run is simple way to execute a CLI utility. `command` is parsed for arguments. args is optional and unparsed.
Types ¶
type Context ¶
type Context struct {
// Task is the currently running task.
Task *Task
// FileEvent is an event from the watcher with change details.
FileEvent *watcher.FileEvent
}
Context is the data passed to a task.
type Debounce ¶
type Debounce int64
Debounce is the number of milliseconds before a task can run again.
type Project ¶
type Project struct {
sync.Mutex
Tasks map[string]*Task
Namespace map[string]*Project
// contains filtered or unexported fields
}
Project is a container for tasks.
func NewProject ¶
NewProject creates am empty project ready for tasks.
type RegexpInfo ¶
RegexpInfo contains additional info about the Regexp created by a glob pattern.
type Task ¶
type Task struct {
Name string
Description string
Dependencies []string
Handler func()
ContextHandler func(*Context)
// Watches are the files are watched. On change the task is rerun. For example `**/*.less`
// Usually Watches and Sources are the same.
WatchFiles []*FileAsset
WatchGlobs []string
WatchRegexps []*RegexpInfo
// computed based on dependencies
EffectiveWatchRegexps []*RegexpInfo
EffectiveWatchGlobs []string
// Complete indicates whether this task has already ran. This flag is
// ignored in watch mode.
Complete bool
Debounce int64
RunOnce bool
}
A Task is an operation performed on a user's project directory.