UGCProjects/Tool/lua_to_one_line.py
2025-01-04 23:00:19 +08:00

41 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import re
import sys
import utils
def all_files_to_one_line(dirname, targetDir: str):
curr_path = os.getcwd()
path = curr_path + "\\" + dirname + r"\Script"
files = utils.listFiles(path, ["lua"])
targetPath = targetDir + "\\" + dirname + r"\Script"
# 直接创建即可
utils.createFolder(targetPath)
for i in files:
file_content = utils.load_file(i, encode='utf-8')
targetFile = i.replace(path, targetPath)
utils.file_exist(targetFile)
with open(targetFile, mode='w', encoding='utf-8') as f:
file_content = utils.remove_lua_comments(file_content)
f.write(utils.one_line(file_content))
f.close()
if __name__ == '__main__':
# 0 是自己1 是目标文件夹2及以后 是要处理的文件
target_dir = ""
dirs = []
for i in range(0, len(sys.argv)):
if i == 1:
# 此时是目标文件夹
target_dir = sys.argv[i]
elif i > 1:
dirs.append(sys.argv[i])
if target_dir.find(':') == -1:
target_dir = os.getcwd() + "\\" + target_dir
# 处理控制台参数
for i in dirs:
project_name_dir = re.findall(r"\w+", i)
all_files_to_one_line(project_name_dir[0], target_dir)