Goat is a file watcher written in Golang. Goat watches files which have specific extensions and executes specific commands when one of these files is created, updated or removed.
You can use Goat to:
- Restart a Golang web server process when one of the Golang source files is updated.
- Compile Stylus, Sass/SCSS and LESS source files when one of these files is updated.
- Concatenate and compress JS and CSS source files when one of these files is updated.
$ go get github.com/yosssi/goat/...
To run goat, you have to create a configuration file named goat.json
in your project root directory. This file looks like the following:
{
"init_tasks": [
{
"command": "make stop"
},
{
"command": "make run",
"nowait": true
}
],
"watchers": [
{
"extension": "go",
"tasks": [
{
"command": "make stop"
},
{
"command": "make run",
"nowait": true
}
]
},
{
"extension": "styl",
"tasks": [
{
"command": "make stylus"
}
]
},
{
"extension": "css",
"excludes": ["all.css", "all.min.css"],
"tasks": [
{
"command": "make catcss"
},
{
"command": "make uglifycss"
}
]
},
{
"extension": "js",
"excludes": ["all.js", "all.min.js"],
"tasks": [
{
"command": "make catjs"
},
{
"command": "make uglifyjs"
}
]
}
]
}
init_tasks
defines an array of initial tasks. This definition is optional. Each task definition has the following properties:command
(required)nowait
(optional)
command
defines a command which is executed when one of the target files is created, updated or removed.nowait
defines whether Goat waits the completion of the command or not.watchers
defines an array of file watchers. Each watcher definition has the following properties:extension
(required)tasks
(required)excludes
(optional)
extension
defines target file's extension. Goat watches all files which have this extension in and under your project root directory.tasks
defines an array of tasks.excludes
defines an array of file names which is out of watching range.
On the your project root directory which has goat.json
file, execute the following command:
$ goat
2014/03/06 01:22:04 [go wathcer] Watching...
2014/03/06 01:22:04 [js wathcer] Watching...
2014/03/06 01:22:04 [css wathcer] Watching...
2014/03/06 01:22:04 [styl wathcer] Watching...
Goat launches watcher processes defined on goat.json
file.
Default interval time of each watcher's file check loop is 500 ms. You can change this interval time by specifying -i flag. The following example shows a command which sets the interval time to 1000 ms:
$ goat -i 1000