82 lines
2.3 KiB
Python
82 lines
2.3 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
def merge_files():
|
|||
|
|
"""合并temp_mock_data.js到resumeInterviewMock.js"""
|
|||
|
|
|
|||
|
|
# 读取原始文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js.backup_final', 'r', encoding='utf-8') as f:
|
|||
|
|
original_content = f.read()
|
|||
|
|
|
|||
|
|
# 读取新生成的数据
|
|||
|
|
with open('temp_mock_data.js', 'r', encoding='utf-8') as f:
|
|||
|
|
new_content = f.read()
|
|||
|
|
|
|||
|
|
# 从新文件中提取industries和resumeTemplates
|
|||
|
|
# 提取industries
|
|||
|
|
industries_match = re.search(r'const industries = (\[[\s\S]*?\n\]);', new_content, re.MULTILINE)
|
|||
|
|
if not industries_match:
|
|||
|
|
print("错误:无法从temp_mock_data.js中提取industries")
|
|||
|
|
return False
|
|||
|
|
new_industries = industries_match.group(0)
|
|||
|
|
|
|||
|
|
# 提取resumeTemplates
|
|||
|
|
templates_match = re.search(r'const resumeTemplates = (\{[\s\S]*?\n\});', new_content, re.MULTILINE)
|
|||
|
|
if not templates_match:
|
|||
|
|
print("错误:无法从temp_mock_data.js中提取resumeTemplates")
|
|||
|
|
return False
|
|||
|
|
new_templates = templates_match.group(0)
|
|||
|
|
|
|||
|
|
# 在原始文件中替换industries
|
|||
|
|
original_content = re.sub(
|
|||
|
|
r'const industries = \[[\s\S]*?\n\];',
|
|||
|
|
new_industries,
|
|||
|
|
original_content,
|
|||
|
|
count=1
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 在原始文件中替换resumeTemplates
|
|||
|
|
original_content = re.sub(
|
|||
|
|
r'const resumeTemplates = \{[\s\S]*?\n\};',
|
|||
|
|
new_templates,
|
|||
|
|
original_content,
|
|||
|
|
count=1
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 保存合并后的文件
|
|||
|
|
with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(original_content)
|
|||
|
|
|
|||
|
|
print("✅ 成功合并数据到 resumeInterviewMock.js")
|
|||
|
|
return True
|
|||
|
|
|
|||
|
|
def verify_syntax():
|
|||
|
|
"""验证生成的文件语法是否正确"""
|
|||
|
|
import subprocess
|
|||
|
|
|
|||
|
|
result = subprocess.run(
|
|||
|
|
['node', '-c', 'src/mocks/resumeInterviewMock.js'],
|
|||
|
|
capture_output=True,
|
|||
|
|
text=True
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
if result.returncode == 0:
|
|||
|
|
print("✅ 语法检查通过")
|
|||
|
|
return True
|
|||
|
|
else:
|
|||
|
|
print(f"❌ 语法错误:{result.stderr}")
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
def main():
|
|||
|
|
print("开始合并文件...")
|
|||
|
|
|
|||
|
|
if merge_files():
|
|||
|
|
print("\n验证语法...")
|
|||
|
|
verify_syntax()
|
|||
|
|
|
|||
|
|
print("\n数据替换完成!")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
main()
|