上传编译工具

This commit is contained in:
liwei 2023-07-19 14:53:37 +08:00
parent 14ec1db85d
commit 4a0729edb1
2 changed files with 39 additions and 42 deletions

31
.gitignore vendored
View File

@ -1,23 +1,14 @@
.DS_Store # ---> Go
node_modules # Binaries for programs and plugins
/dist *.exe
*.exe~
# Test binary, built with `go test -c`
*.test
# local env files # Output of the go coverage tool, specifically when used with LiteIDE
.env.local *.out
.env.*.local
# Log files *.log
npm-debug.log* pb
yarn-debug.log* node_modules
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@ -14,28 +14,34 @@ if os.path.exists(source_path):
# dirs 是一个 list内容是该文件夹中所有的目录的名字(不包括子目录) # dirs 是一个 list内容是该文件夹中所有的目录的名字(不包括子目录)
# files 同样是 list, 内容是该文件夹中所有的文件(不包括子目录) # files 同样是 list, 内容是该文件夹中所有的文件(不包括子目录)
for root, dirs, files in os.walk(source_path): for root, dirs, files in os.walk(source_path):
for file in files: if not "google" in root:
folder = os.path.basename(root) relative_path = root.split(source_path)[-1].strip("/")
if folder == "proto": if len(relative_path) == 0:
src_file = os.path.join(root, file) for file in files:
shutil.copy(src_file, target_path) folder = os.path.splitext(file)[1]
elif folder != "protobuf": if folder == ".proto":
src_file = os.path.join(root, file) src_file = os.path.join(root, file)
out_file = os.path.join(target_path, file) shutil.copy(src_file, target_path)
file_data = "" else:
print(src_file) for file in files:
with io.open(src_file, "r", encoding='utf-8') as f: folder = os.path.splitext(file)[1]
for line in f: if folder == ".proto":
if 'import' in line: src_file = os.path.join(root, file)
cite = re.findall(r"\"(.+?)\"",line)[0] out_file = os.path.join(target_path, file)
cpaths = cite.split("/") file_data = ""
if len(cpaths) == 2: print(src_file)
line = re.sub( with io.open(src_file, "r", encoding='utf-8') as f:
cite, cpaths[1], line) for line in f:
print(line) if 'import' in line:
file_data += line cite = re.findall(r"\"(.+?)\"",line)[0]
with io.open(out_file, "w", encoding='utf-8') as f: cpaths = cite.split("/")
f.write(file_data) if len(cpaths) == 2:
line = re.sub(
cite, cpaths[1], line)
print(line)
file_data += line
with io.open(out_file, "w", encoding='utf-8') as f:
f.write(file_data)
cmdstr = 'npx pbjs -t json-module -w commonjs -o ./src/pb/proto.js ./src/pb/temop/*.proto' cmdstr = 'npx pbjs -t json-module -w commonjs -o ./src/pb/proto.js ./src/pb/temop/*.proto'
print(cmdstr) print(cmdstr)
os.system(cmdstr) os.system(cmdstr)