You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.8 KiB
Lua
83 lines
1.8 KiB
Lua
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:
|