๐ A small taskrunner that harnesses the power of Lua's metamethods to easily express flow of tasks.
Note: Fourmi is in active development.
Requirements:
- Lua 5.3
- luarocks >= 3.0 (Note:
hererocks -rlatest
will install 2.4, you need to specify it with-r3.0
)
luarocks install --server=http://luarocks.org/dev fourmi
Write a fourmi.plan.lua file in your project directory and then:
# If `plan` is not provided, will run plan named `all`
fourmi [--file <file>] [-h] <plan> [<arguments>] ...
Task are relatively small jobs that you can combine using operators.
local mytask = task "mytask"
:description "A short description of what it does"
:file "output.o"
:requires { "file1.x", "file2.x" }
:property("propertykey", propertyvalue)
:perform(function(self, ...)
-- Do something with ...
return output1, ..., ouputn
end)
task1 .. task2
: returns a new task that doestask1
thentask2
task1 & task2
: returns a new task that doestask2
has output, pipes it totask2
task1 | task2
: returns a new task that doestask2
only iftask1
returns falsy valuetask1 >> task2
: returns a new task that pipestask1
intotask2
task1 * task2
: returns a new task that doestask2
for all output oftask1
task1 ^ (condition)
: returns a new task that doestask1
ifcondition
(expression or function to be evaluated) is true
Here's an commented excerpt of fourmi.plan.lua
:
-- Define variables
-- Those can be overwritten with cli arguments of the form `key=value`
var {
min = "luamin",
src = "./fourmi",
dest = "~/tmp-code",
}
-- ...
return {
-- Default plan
plan "all"
-- Small description of what the plan does
:description "Minify and gzip lua files"
-- Define its task
:task(
-- List files in `./fourmi` ending with `.lua`
ls("@{src}", "%.lua$")
-- For each of them: if the gzipped file does not exist or is older than the original,
-- minify then gzip then move to `~/tmp-code`
* (outdated "@{dest}/#{original}.gz"
& minify >> gzip >> mv "@{dest}")
),
-- Clean plan
plan "clean"
:description "Cleanup"
:task(
-- Remove all files from `~/tmp-code`
empty "@{dest}"
)
}
If you don't want to use operators, you can use their aliases:
..
: after&
: success|
: failure>>
: into*
: each^
: meet
__(string, [context])
interpolates special special sequences in a string:
~
: will be replaced with$HOME
${ENV}
: will be replaced by theENV
environment variable#{variable}
: fourmi will look forvariable
incontext
or_G
if none provided@{fourmi_variable}
: will be replaced by thefourmi_variable
defined withvar(name, value)