-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHowlfile.lua
107 lines (82 loc) · 3.05 KB
/
Howlfile.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---@diagnostic disable: undefined-global
package.path = "/" .. shell.dir() .. "/?.lua;" .. package.path
local base64 = require "util.base64"
local mixin = require "howl.class.mixin"
local CopySource = require "howl.files.CopySource"
local Runner = require "howl.tasks.Runner"
local Task = require "howl.tasks.Task"
local Context = require "howl.tasks.Context"
Options:Default "trace"
Tasks:clean "clean" (function(spec)
spec:include { "build/*.lua" }
end)
Tasks:clean "cleanIntermediate" (function(spec)
spec:include { "res/*.lua", "audio/*.lua" }
end)
local SourceTask = Task:subclass("radon.SourceTask")
:include(mixin.filterable)
:include(mixin.delegate("sources", {"from", "include", "exclude"}))
:addOptions { "action" }
function SourceTask:initialize(context, name, dependencies, action)
Task.initialize(self, name, dependencies)
self.root = context.root
self.sources = CopySource()
self:exclude { ".git", ".svn", ".gitignore" }
self:description "Runs an action on all files matching a pattern"
end
function SourceTask:runAction(context)
local files = self.sources:gatherFiles(self.root)
local action = self.options.action
if type(action) == "function" then
for _, input in ipairs(files) do
action(self, context, input)
end
else
error("No action specified")
end
end
Runner:include({ sourceTask = function(self, name, taskDepends, taskAction)
return self:injectTask(SourceTask(self.env, name, taskDepends, taskAction))
end })
local class = require "howl.class"
local MapTask = class("radon.MapTask")
MapTask.__tostring = function(self) return self.output end
function MapTask:initialize(input, output)
self.input = input
self.output = output
end
Tasks:injectTask(Tasks:Task "encodeu8" (function(self, context, task)
local iF = fs.open(task.input.path, "rb")
task.input.contents = iF.readAll()
iF.close()
local oF = fs.open(task.output, "wb")
oF.write("return \"" .. base64.encode(task.input.contents) .. "\"")
oF.close()
end))
Tasks:sourceTask "mapBinaries" (function(spec)
spec:from "audio" {
include = { "*.u8" },
exclude = { "*.lua" },
}
spec:from "res" {
include = { "*.rif" },
exclude = { "*.lua" },
}
spec:action(function(self, context, file)
local output = file.path:gsub("(.*)%.(.*)", "%1.lua")
if not fs.exists(output) then
Tasks.tasks["encodeu8"]:Run(Context(Tasks), MapTask(file, output))
end
end)
end)
Tasks:minify "minify" {
input = "build/radon.lua",
output = "build/radon.min.lua",
}
Tasks:require "main" {
include = {"components/*.lua", "core/*.lua", "fonts/*.lua", "Krypton/*.lua", "modules/*.lua", "res/*.lua", "util/*.lua", "DefaultLayout.lua", "radon.lua", "profile.lua", "configDefaults.lua"},
startup = "radon.lua",
output = "build/radon.lua",
}
Tasks:Task "build" { "mapBinaries", "main", "cleanIntermediate" }
Tasks:Default "build"