Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if params.len < 1 then exit("<b>Example:</b> gsbuild [ProjectPath] (opt: MainSourceName)")
- //LoadProjectFolder
- shell = get_shell()
- pc = shell.host_computer()
- projectFolderPath = params[0]
- projectFolder = pc.File(projectFolderPath)
- if not projectFolder or not projectFolder.is_folder then exit("<b>Project folder not found</b>")
- projectName = projectFolder.name
- //LoadMainFile
- if params.len > 1 then
- mainFilePath = projectFolder.path + "/" + params[1]
- else
- mainFilePath = projectFolder.path + "/Main.src"
- end if
- mainFile = pc.File(mainFilePath)
- if not mainFile and mainFile.is_folder then exit("<b>Main file not found</b>\n<i>(i)Check path - '" + mainFilePath + "'</i>")
- mainCode = mainFile.content
- //AnalyzeCommands
- importLibs = []; i = 0; codeLines = mainCode.split("\n")
- while i < codeLines.len
- if codeLines[i] and codeLines[i].len > 0 and codeLines[i][0] == "#" then
- line = codeLines[i].remove("#")
- splited = line.split(" ")
- if splited.len != 2 then exit("<b>Unknown command in line - " + i + "</b>")
- command = splited[0]
- arg = splited[1]
- if command == "import" then importLibs.push({ "name" : arg, "pos" : i })
- end if
- i = i + 1
- end while
- //LoadLibsFolder
- libsFolderPath = projectFolder.path + "/libs"
- libsFolder = pc.File(libsFolderPath)
- if not libsFolder or not libsFolder.is_folder then exit("<b>Libs folder not found</b>")
- //LoadLibs
- i = 0
- while i < importLibs.len
- lib = pc.File(libsFolderPath + "/" + importLibs[i].name)
- if not lib or lib.is_folder then
- lib = pc.File(libsFolderPath + "/" + importLibs[i].name + ".src")
- if not lib then exit("<b>Not found lib - '" + importLibs[i].name + "'</b>\n<i>(i)Check libs folder</i>")
- end if
- importLibs[i].file = lib
- i = i + 1
- end while
- //ImportLibs
- content = ""; i = 0
- while i < codeLines.len
- for lib in importLibs
- if lib.pos == i then
- codeLines[i] = lib.file.content.replace("\n", """+char(10)+""").replace("\t", """+char(9)+""")
- break
- end if
- end for
- content = content + codeLines[i] + "\n"
- i = i + 1
- end while
- print("<i>(i)Imported " + importLibs.len + " libs</i>")
- //CreateOutFile
- outFileName = projectFolder.name + ".src"
- outFilePath = projectFolder.path + "/" + outFileName
- outFile = pc.File(outFilePath)
- if not outFile or outFile.is_folder then
- pc.touch(projectFolder.path, outFileName)
- outFile = pc.File(outFilePath)
- end if
- if not outFile or outFile.is_folder then exit("<b>Could not create file - '" + outFilePath + "'</b>")
- outFile.set_content(content)
- //Compile
- binPath = projectFolder.path + "/bin"
- if not pc.File(binPath) then pc.create_folder(projectFolder.path, "bin")
- msg = shell.build(outFile.path, binPath)
- if msg then exit("<b>Compile error:\n" + msg + "</b>")
- //outFile.delete()
- print("<i>(i)Project compiled to in '" + binPath + "'</i>")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement