Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if params.len < 1 then exit("Example: minifier [SourceCodePath]")
- pc = get_shell.host_computer
- codeFilePath = params[0]
- codeFile = pc.File(codeFilePath)
- if not codeFile then exit("File not found")
- analyzeLine = function(string)
- string = string.trim()
- if not string or string == "" then return null
- if string.indexOf("//") == 0 then return null
- string = string.replace("\n", """+char(10)+""")
- string = string.replace("\t", """+char(9)+""")
- result = ""
- comment = false
- i = 0
- while i < string.len
- ch1 = string[i]
- if i + 1 < string.len then ch2 = string[i + 1] else ch2 = null
- if ch1 == """" then
- if comment then comment = false else comment = true
- else if not comment and ch1 == "/" and ch2 == "/" then
- break
- end if
- result = result + ch1
- i = i + 1
- end while
- return result.trim()
- end function
- result = ""
- statements = codeFile.content.split("\n")
- startTime = time
- for statement in statements
- statement = analyzeLine(statement)
- if not statement then continue
- result = result + statement + ";"
- end for
- endTime = time
- print("ElapsedTime - " + (endTime - startTime))
- dir = parent_path(codeFile.path)
- name = "Minified_" + codeFile.name
- outFilePath = dir + "/" + name
- outFile = pc.File(outFilePath)
- if not outFile then
- pc.touch(dir, name)
- outFile = pc.File(outFilePath)
- end if
- if not outFile then exit("Could not create file - '" + outFilePath + "'")
- outFile.set_content(result)
- print("Minified code saved to - '" + outFilePath + "'")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement