size: 800 B
| 1 | -- combine modules (specified as cli arguments) into one file |
| 2 | package.path = "./?.lua;" .. package.path |
| 3 | local parser = require("dumbParser") |
| 4 | |
| 5 | local modules = {} |
| 6 | for i=1,#arg do |
| 7 | modules[#modules + 1] = |
| 8 | arg[i]:gsub("^../",""):gsub("%.lua$",""):gsub("%/",".") |
| 9 | end |
| 10 | |
| 11 | local buffer = {} |
| 12 | local function out(s) |
| 13 | buffer[#buffer + 1] = s |
| 14 | end |
| 15 | |
| 16 | for _,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') |
| 23 | end |
| 24 | |
| 25 | out('local djot = require("djot")') |
| 26 | out('return djot') |
| 27 | |
| 28 | local combined = table.concat(buffer, "\n") |
| 29 | local ast = parser.parse(combined) |
| 30 | parser.minify(ast) |
| 31 | io.stdout:write(parser.toLua(ast, false)) |