SquidDev

WebBuild.min.lua

Sep 22nd, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.05 KB | None | 0 0
  1.  
  2. local function e(q)
  3. local j=setmetatable({},{__index=_ENV or getfenv()})if setfenv then setfenv(q,j)end;return q(j)or j end
  4. local t=e(function(q,...)
  5. local j={["\n"]="\\n",["\r"]="\\r",["\t"]="\\t",["\b"]="\\b",["\f"]="\\f",["\""]="\\\"",["\\"]="\\\\"}
  6. local x={['\n']=true,['r']=true,['\t']=true,[' ']=true,[',']=true,[':']=true}
  7. local function z(D)while x[D:sub(1,1)]do D=D:sub(2)end;return D end;local _
  8. local function E(D)if D:sub(1,4)=="true"then return true,z(D:sub(5))else
  9. return false,z(D:sub(6))end end;local function T(D)return nil,z(D:sub(5))end
  10. local A={['e']=true,['E']=true,['+']=true,['-']=true,['.']=true}
  11. local function O(D)local L=1
  12. while A[D:sub(L,L)]or tonumber(D:sub(L,L))do L=L+1 end;local U=tonumber(D:sub(1,L-1))D=z(D:sub(L))return U,D end
  13. local function I(D)local L,U=D:find('^".-[^\\]"')local C=D:sub(L+1,U-1)for M,F in pairs(j)do
  14. C=C:gsub(F,M)end;D=z(D:sub(U+1))return C,D end
  15. local function N(D)D=z(D:sub(2))local L={}local U=1;while D:sub(1,1)~="]"do local C=nil;C,D=_(D)L[U]=C
  16. U=U+1;D=z(D)end;D=z(D:sub(2))return L,D end;local function S(D)local L=nil;L,D=_(D)local U=nil;U,D=_(D)return L,U,D end
  17. local function H(D)
  18. D=z(D:sub(2))local L={}
  19. while D:sub(1,1)~="}"do local U,C=nil,nil;U,C,D=S(D)L[U]=C;D=z(D)end;D=z(D:sub(2))return L,D end
  20. function _(D)local L=D:sub(1,1)
  21. if L=="{"then return H(D)elseif L=="["then return N(D)elseif
  22. tonumber(L)~=nil or A[L]then return O(D)elseif D:sub(1,4)=="true"or D:sub(1,5)=="false"then
  23. return E(D)elseif L=="\""then return I(D)elseif D:sub(1,4)=="null"then return T(D)end;return nil end;local function R(D)D=z(D)t=_(D)return t end
  24. return function(D)local L=http.get(D)return L and
  25. R(L.readAll())end end)
  26. local a=e(function(q,...)
  27. local function j(z,_,E)
  28. local T='https://api.github.com/repos/'..z..'/git/trees/'.._..'?recursive=1'
  29. for A=1,E do local O=t(T)if O and O.tree then return O.tree end end;return nil end
  30. local function x(z,_,E,T,A)
  31. local O='https://raw.github.com/'..z..'/'.._..'/'local I={}local N=0;local S=0
  32. local function x(R)local D=R.path;local L;for U=1,T do local C=(O..D):gsub(' ','%%20')
  33. local M=http.get(C)
  34. if M then N=N+1;I[D]=M.readAll()A(true,D,R,N,S)return end end
  35. A(false,D,R,N,S)end;local H={}
  36. for R,D in ipairs(E)do if D.type=='tree'then I[D.path]=true else S=S+1
  37. H[S]=function()x(D)end end end;parallel.waitForAll(unpack(H))return I end;return{getTree=j,download=x}end)
  38. local o=e(function(q,...)local j=fs
  39. local x={["^"]="%^",["$"]="%$",["("]="%(",[")"]="%)",["%"]="%%",["."]="%.",["["]="%[",["]"]="%]",["*"]="%*",["+"]="%+",["-"]="%-",["?"]="%?",["\0"]="%z"}local function z(A)return(A:gsub(".",x))end
  40. local function _(A,O)return A==""or O==A or
  41. O:sub(1,#A+1)==A.."/"end
  42. local function E(A,O)if A==""then return O else return O:sub(#A+2)end end
  43. local function T(A)local O={}for I,N in pairs(A)do O[I]=N end;return O end
  44. return
  45. function(A,O)O=T(O)local I
  46. I={fs={list=function(N)N=j.combine(N,"")
  47. local S=j.isDir(N)and j.list(N)or{}if _(A,N)then local H="^"..z(E(A,N))if H~="^"then H=H..'/'end
  48. H=H..'([^/]+)$'
  49. for R,D in pairs(O)do local L=R:match(H)if L then S[#S+1]=L end end end
  50. return S end,exists=function(N)
  51. N=j.combine(N,"")
  52. if j.exists(N)then return true elseif _(A,N)then return O[E(A,N)]~=nil end end,isDir=function(N)
  53. N=j.combine(N,"")
  54. if j.isDir(N)then return true elseif _(A,N)then return O[E(A,N)]==true end end,isReadOnly=function(N)
  55. N=j.combine(N,"")if j.exists(N)then return j.isReadOnly(N)elseif _(A,N)and O[E(A,N)]~=nil then
  56. return true else return false end end,getName=j.getName,getDir=j.getDir,getSize=j.getSize,getFreespace=j.getFreespace,combine=j.combine,move=j.move,copy=j.copy,makeDir=function(N)
  57. end,delete=j.delete,open=function(N,S)N=j.combine(N,"")
  58. if _(A,N)then local H=E(A,N)
  59. if type(O[H])=='string'then
  60. local R={close=function()end}
  61. if S=='r'then local D=O[H]R.readAll=function()return D end;local L=1;local U
  62. R.readLine=function()if not U then
  63. U={D:match((D:gsub("[^\n]+\n?","([^\n]+)\n?")))}end;if L>#U then return nil else return U[L]end
  64. L=L+1 end;return R else error('Cannot write to read-only file.',2)end end end;return j.open(N,S)end},loadfile=function(N)
  65. local S=I.fs.open(N,"r")if S then local H,R=loadstring(S.readAll(),j.getName(N))
  66. S.close()return H,R end
  67. return nil,"File not found: "..N end,dofile=function(N)
  68. local S,H=I.loadfile(N)
  69. if S then setfenv(S,getfenv(2))return S()else error(H,2)end end}I._G=I;return I end end)local i=2;local n="master"local s=false;local h;local r,d;local l={...}local u,c=1,#l
  70. while u<=c do local q=l[u]
  71. if
  72. q=="--branch"or q=="-branch"or q=="-b"then u=u+1;n=l[u]elseif q=="--repo"or q==
  73. "-repo"or q=="-r"then u=u+1;d=l[u]elseif
  74. q=="--tries"or q=="-tries"then u=u+1;i=tonumber(l[u])
  75. if i==nil then
  76. error("Invalid number for tries: "..l[u],0)elseif i<=0 then error("Tries must be >= 1",0)end elseif q=="--once"then s=true elseif q=="--local"or q=="-l"then u=u+1;h=l[u]
  77. if h==nil then
  78. error("Invalid Howl path",0)else h=shell.resolve(h)if not fs.exists(h)then
  79. error("Cannot find Howl",0)end end elseif q=="--task"or q=="-task"or q=="-t"then u=u+1;r=l[u]elseif not d then d=q elseif not r then
  80. r=q else error("Unexpected argument "..q)end;u=u+1 end;while d==nil or d==""do write("Repo > ")d=read()end
  81. local m=a.getTree(d,n,i)if not m then
  82. error("Could not fetch tree. Does the repo/branch exist?",0)end;local f=false
  83. for q,j in ipairs(m)do if
  84.  
  85. j.path=="Howlfile.lua"or j.path=="Howlfile"and j.type=="blob"then f=true;break end end;if not f then
  86. error("Cannot find a Howlfile. It must be in the root of the project",0)end
  87. local function w(m)local q={}
  88. write("Downloading...")
  89. local function j(x,z,_,E,T)if not x then q[#q+1]=_;local I,N=term.getCursorPos()
  90. term.setCursorPos(1,N)term.clearLine()
  91. printError("Cannot download "..z)end
  92. local A,O=term.getCursorPos()term.setCursorPos(1,O)term.clearLine()
  93. write(("Downloading: %s/%s (%s%%)"):format(E,T,
  94. E/T*100))end;local a=a.download(d,n,m,i,j)print()return a,q end;local y,p=w(m)
  95. while#p>0 do write("Failed to download. Retry? [y/n]")if
  96. read():sub(1,1):lower()=="y"then local q,j=w(p)p=j;for x,z in pairs(q)do y[x]=z end else
  97. error("Exiting",0)end end;local v={}do local q=y['.howl']
  98. if q then v=textutils.unserialize(q)if v==nil then
  99. error("Invalid format for .howl file",0)end end end;if not r then
  100. r=v.defaultTask end;local b=o(shell.dir(),y)local g
  101. if h then
  102. g=setfenv(assert(loadfile("/H")),setmetatable(b,{__index=_ENV}))else local q
  103. local j=v.howl or"http://pastebin.com/raw.php?i=uHRTm9hp"local x;if
  104. j:sub(1,7)=="http://"or j:sub(1,8)=="https://"then print("Downloading Howl...")x=http.get(j)else
  105. x=b.fs.open(j)end;if not x then error("Cannot find Howl at "..
  106. j,0)end
  107. q=x.readAll()x.close()
  108. g=assert(load(q,"Howl",nil,setmetatable(b,{__index=_ENV})))end
  109. local function k(q)local j={}local x=false;for z in(q.."\""):gmatch("(.-)\"")do if x then j[#j+1]=z else for _ in
  110. z:gmatch("[^ \t]+")do j[#j+1]=_ end end
  111. x=not x end;return j end;local l
  112. if r then l={r}else term.write("Task > ")l=k(read())end
  113. while true do local q,j=pcall(g,unpack(l))if not q then
  114. print("Running task failed:")printError(j)end;if s then break end
  115. term.write("Task > ")l=k(read())if#l==0 then break end end
Advertisement
Add Comment
Please, Sign In to add comment