size: 800 B

1-- combine modules (specified as cli arguments) into one file
2package.path = "./?.lua;" .. package.path
3local parser = require("dumbParser")
4
5local modules = {}
6for i=1,#arg do
7 modules[#modules + 1] =
8 arg[i]:gsub("^../",""):gsub("%.lua$",""):gsub("%/",".")
9end
10
11local buffer = {}
12local function out(s)
13 buffer[#buffer + 1] = s
14end
15
16for _,module in ipairs(modules) do
17 out(string.format('package.preload["%s"] = function()', module))
18 local path = "../" .. module:gsub("%.","/") .. ".lua"
19 local f = assert(io.open(path, "r"))
20 local content = f:read("*all")
21 out(content)
22 out('end\n')
23end
24
25out('local djot = require("djot")')
26out('return djot')
27
28local combined = table.concat(buffer, "\n")
29local ast = parser.parse(combined)
30parser.minify(ast)
31io.stdout:write(parser.toLua(ast, false))