Advertisement
_LINKI

GreyScript ProjectBuilder

Jul 18th, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | None | 0 0
  1. if params.len < 1 then exit("<b>Example:</b> gsbuild [ProjectPath] (opt: MainSourceName)")
  2.  
  3. //LoadProjectFolder
  4. shell = get_shell()
  5. pc = shell.host_computer()
  6. projectFolderPath = params[0]
  7. projectFolder = pc.File(projectFolderPath)
  8. if not projectFolder or not projectFolder.is_folder then exit("<b>Project folder not found</b>")
  9. projectName = projectFolder.name
  10.  
  11. //LoadMainFile
  12. if params.len > 1 then
  13.     mainFilePath = projectFolder.path + "/" + params[1]
  14. else
  15.     mainFilePath = projectFolder.path + "/Main.src"
  16. end if
  17. mainFile = pc.File(mainFilePath)
  18. if not mainFile and mainFile.is_folder then exit("<b>Main file not found</b>\n<i>(i)Check path - '" + mainFilePath + "'</i>")
  19. mainCode = mainFile.content
  20.  
  21. //AnalyzeCommands
  22. importLibs = []; i = 0; codeLines = mainCode.split("\n")
  23. while i < codeLines.len
  24.     if codeLines[i] and codeLines[i].len > 0 and codeLines[i][0] == "#" then
  25.         line = codeLines[i].remove("#")
  26.         splited = line.split(" ")
  27.         if splited.len != 2 then exit("<b>Unknown command in line - " + i + "</b>")
  28.        
  29.         command = splited[0]
  30.         arg = splited[1]
  31.         if command == "import" then importLibs.push({ "name" : arg, "pos" : i })
  32.     end if
  33.     i = i + 1
  34. end while
  35.  
  36. //LoadLibsFolder
  37. libsFolderPath = projectFolder.path + "/libs"
  38. libsFolder = pc.File(libsFolderPath)
  39. if not libsFolder or not libsFolder.is_folder then exit("<b>Libs folder not found</b>")
  40.  
  41. //LoadLibs
  42. i = 0
  43. while i < importLibs.len
  44.     lib = pc.File(libsFolderPath + "/" + importLibs[i].name)
  45.     if not lib or lib.is_folder then
  46.         lib = pc.File(libsFolderPath + "/" + importLibs[i].name + ".src")
  47.         if not lib then exit("<b>Not found lib - '" + importLibs[i].name + "'</b>\n<i>(i)Check libs folder</i>")
  48.     end if
  49.     importLibs[i].file = lib
  50.     i = i + 1
  51. end while
  52.  
  53. //ImportLibs
  54. content = ""; i = 0
  55. while i < codeLines.len
  56.     for lib in importLibs
  57.         if lib.pos == i then
  58.             codeLines[i] = lib.file.content.replace("\n", """+char(10)+""").replace("\t", """+char(9)+""")
  59.             break
  60.         end if
  61.     end for
  62.     content = content + codeLines[i] + "\n"
  63.     i = i + 1
  64. end while
  65. print("<i>(i)Imported " + importLibs.len + " libs</i>")
  66.  
  67. //CreateOutFile
  68. outFileName = projectFolder.name + ".src"
  69. outFilePath = projectFolder.path + "/" + outFileName
  70. outFile = pc.File(outFilePath)
  71. if not outFile or outFile.is_folder then
  72.     pc.touch(projectFolder.path, outFileName)
  73.     outFile = pc.File(outFilePath)
  74. end if
  75. if not outFile or outFile.is_folder then exit("<b>Could not create file - '" + outFilePath + "'</b>")
  76. outFile.set_content(content)
  77.  
  78. //Compile
  79. binPath = projectFolder.path + "/bin"
  80. if not pc.File(binPath) then pc.create_folder(projectFolder.path, "bin")
  81.  
  82. msg = shell.build(outFile.path, binPath)
  83. if msg then exit("<b>Compile error:\n" + msg + "</b>")
  84. //outFile.delete()
  85.  
  86. print("<i>(i)Project compiled to in '" + binPath + "'</i>")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement