Create build

This commit is contained in:
Ale32bit 2016-11-01 17:14:53 +01:00 committed by GitHub
parent 43f248f67f
commit 45828ca196

83
src/sdk/build Normal file
View file

@ -0,0 +1,83 @@
local args = {...}
if not sPhone then
print("build requires sPhone")
end
if #args < 2 then
print("Usage: build <App Folder> <Output>")
return
end
local dir = args[1]
local output = args[2]
local final = {}
local builderVersion = 1
if not fs.exists(dir) or not fs.isDir(dir) then
print("Input must be a folder")
return
end
local f = fs.open(dir.."/config","r")
local config = textutils.unserialize(f.readAll())
f.close()
if not config then
print("Config file is corrupted")
return
end
-- COMPRESS
local filesystem = {}
local function readFile(path)
local file = fs.open(path,"r")
local variable = file.readAll()
file.close()
return variable
end
local function explore(dir)
local buffer = {}
local sBuffer = fs.list(dir)
for i,v in pairs(sBuffer) do
sleep(0.05)
if fs.isDir(dir.."/"..v) then
if v ~= ".git" then
buffer[v] = explore(dir.."/"..v)
end
else
buffer[v] = readFile(dir.."/"..v)
end
end
return buffer
end
-- COMPRESS
local result = {}
print("Name:",config.name)
print("Author:",config.author)
print("Version:",config.version)
print("ID:",config.id)
if string.getExtension(output) ~= "spk" then
printError("TIP: Use .spk extension")
end
print("Building...")
local filesystem = explore(args[1].."/main")
result["files"] = textutils.serialize(filesystem)
result["config"] = textutils.serialize(config)
local newResult = textutils.serialize(result)
local info = "--\n-- sPhone Application Package\n-- Built with SPK builder "..builderVersion.."\n--"
local f = fs.open(output,"w")
f.write(info.."\n"..newResult)
f.close()