Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LUA_PATH = LUA_PATH .. ':/sys/apis/minify'
- local util = require'Util'
- local Parser = require'ParseLua'
- local Format_Mini = require'FormatMini'
- local ParseLua = Parser.ParseLua
- --local PrintTable = util.PrintTable
- local function minify(inFilename, outFilename)
- write(string.format('%s -> %s ', inFilename, outFilename))
- local sourceText = Util.readFile(inFilename)
- if not sourceText then
- printError("Failed to open `"..inFilename.."` for reading")
- return
- end
- local st, ast = ParseLua(sourceText)
- if not st then
- --we failed to parse the file, show why
- printError(ast)
- return
- end
- local isize = fs.getSize(inFilename)
- local outf = io.open(outFilename, 'w')
- if not outf then
- printError("Failed to open `"..outFilename.."` for writing")
- return
- end
- outf:write(Format_Mini(ast))
- outf:close()
- local osize = fs.getSize(outFilename)
- write(string.format('(%d%%)', 100 - math.floor(osize / isize * 100)))
- print()
- end
- local arg = { ... }
- if #arg == 1 then
- local inPath = Util.resolve(DIR, arg[1])
- if not fs.exists(inPath) then
- error('File does not exist: ' .. inPath)
- end
- if fs.isDir(inPath) then
- for _,filename in pairs(fs.list(inPath)) do
- local rf = Util.resolve(inPath, filename)
- if not fs.isDir(rf) then
- minify(rf, rf)
- end
- end
- else
- minify(inPath, inPath)
- end
- elseif #arg == 2 then
- minify(Util.resolve(DIR, arg[1]), Util.resolve(DIR, arg[2]))
- else
- error("Invalid arguments, Usage:\nminify source [destination]")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement