-
Notifications
You must be signed in to change notification settings - Fork 4
Tasks
The simplest way to define a task is through the Tasks:Task
functions
Tasks:Task "compile"(function()
print("Compiling now...")
end)
You can define dependencies:
Tasks:Task "test"({"compile"}, function()
print("Running tests")
end)
You can also chains functions together:
Tasks:Task "test"(function()
print("Running tests")
end)
:Depends("compile")
:Description("Compile and run tests")
You can also use the Tasks:AddTask
function. This also supports chaining:
Tasks:AddTask("test", {"compile"}, function()
print("running tests")
end):Description("Compile and run tests")
Files can depend on a file like so:
Tasks:Task "test"(function()
print("Running tests")
end
:Depends("aTask")
:Depends({"Many", "Tasks"})
However you can also depend on a file. This will attempt to find a task that creates something.lua
or use it if it exists already.
Tasks:Task "test"(function()
print("Running tests with something.lua")
end
:Requires("something.lua")
You can define tasks that create files with :Produces
Tasks:Task "combine"(function()
print("Combining files into something.lua")
end
:Produces("something.lua")
You can also define tasks that read in files, and produce other files:
Tasks:Task "minify"(function(input, output)
print("Transforming " .. input .. " into " .. output)
end
:Maps("something.lua", "something.min.lua")
-- or use wildcards
:Maps("wild:*.lua", "wild:*.min.lua")
-- or use patterns. Note, the capturing group
-- should be in the output field.
:Maps("ptrn:%1%.lua", "ptrn:(.*)%.min%.lua")
You can use multiple maps functions
Some tasks have predefined functions. These normally follow the pattern Tasks:TypeName(name, options, taskDependencies)
Clean removes a directory/file from the filesystem. It is worth noting that the directory is global, so you must use fs.combine
Tasks:Clean("clean", fs.combine(CurrentDirectory, "build"))
Combines a dependency tree into one file
local sources = Dependencies(CurrentDirectory)
sources:Main "Thing.lua"
:Depends "Another"
sources:Main "Another.lua"
:Name "Another"
Tasks:Combine("combine", sources, "build.lua", {"clean"})
This also takes the additional option of :Verify(verify)
. If set to true this will verify sources with loadstring
to ensure that they are valid Lua sources.
You can read more on dependencies here.
There are multiple ways to minify files:
This allows you to define a task that can minify any file based on a wildcard.
-- All these arguments are optional
-- We define a task called _minify that reads in anything called
-- *.lua and produces a *.min.lua file
Tasks:MinifyAll("_minify", "wild:*.lua", "wild:*.min.lua")
-- So now we can do
Tasks:AddTask "minify"
:Requires(File "Result.min.lua")
:Description("Produces a minified version of the code")
-- And it runs any task needed to create Result.min.lua and minifies it
This is much more simple, but much less flexible:
Tasks:Minify("minify", "Result.lua", "Result.min.lua")