diff --git a/boot.lua b/boot.lua index 14d9de8..d6dd1ec 100644 --- a/boot.lua +++ b/boot.lua @@ -62,3 +62,5 @@ until not chunk ci(bootfs, 'close', fd) local fn = assert(load(code, '@' .. bootpath)) return fn(bootfs, bootpath) + +-- vi: set ts=2: diff --git a/build.lua b/build.lua new file mode 100644 index 0000000..df8c980 --- /dev/null +++ b/build.lua @@ -0,0 +1,82 @@ +local fs, cwd = (function() + local ok, ocfs = pcall(require, 'filesystem') + if ok then + return ocfs, require('shell').getWorkingDirectory() + end + + --otherwise, implement the functions we need on top of LuaFileSystem + local lfs = require('lfs') + local fs = {} + function fs.list(path) + local entries = {} + for name in lfs.dir(path) do + if name ~= '.' and name ~= '..' then + if lfs.attributes(path .. '/' .. name, 'mode') == 'directory' then + name = name .. '/' + end + table.insert(entries, name) + end + end + return entries + end + function fs.makeDirectory(path) + --drop the third return on error + local ok, err, code = lfs.mkdir(path) + if ok then + return true + else + return nil, string.format('%s (error %d)', err, code) + end + end + + return fs, '.' --lfs will handle this properly +end)() + +local stderr = io.stderr or io.error() --openos does this weirdly + +--configuration +local outdir = 'dist/' + +--argument parsing +do + local args = {...} + for i, arg in ipairs(args) do + if arg == '-h' or arg == '--help' then + print('usage: lua build.lua [-h|--help]') + return + end + end + + --for now, error on any arguments (after parsing -h/--help) + if args[1] then + stderr:write(string.format('error: unexpected argument %q\n', args[1])) + os.exit(64) + end +end + + +local function exportFile(srcpath, dstpath) + if not dstpath then + dstpath = outdir .. srcpath + end + local srcf = assert(io.open(srcpath)) + local dstf = assert(io.open(dstpath, 'w')) + + --for now, run a very minimal minifier + for line in srcf:lines() do + local comment = line:find('--', nil, true) + if comment then + assert(line:sub(comment, comment + 3) ~= '--[', 'TODO block comments') + line = line:sub(1, comment-1) + end + line = assert(line:match('^%s*(.-)%s*$')) + if #line > 0 then + dstf:write(line, '\n') + end + end +end + +fs.makeDirectory(cwd .. '/' .. outdir) +exportFile('boot.lua') + +-- vi: set ts=2: