Repository navigation
Expand file tree
/
Copy pathfix_routers.py
More file actions
71 lines (57 loc) · 2.7 KB
/
Copy pathfix_routers.py
File metadata and controls
71 lines (57 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import re
routers_file = 'server/routers.ts'
with open(routers_file, 'r', encoding='utf-8') as f:
content = f.read()
# We need to add imports and register the following routers:
# chargebackLifecycle, insiderThreat, interchange, kyc, mobileMoney, mojaloop,
# regulatoryReports, schemeMembership, str, terminal, velocityLimits
# Some might already exist as files but aren't exported properly, or don't exist at all.
# Let's create dummy routers for the ones that don't exist, and import the ones that do.
missing_routers = [
'chargebackLifecycle', 'insiderThreat', 'interchange', 'kyc', 'mobileMoney',
'mojaloop', 'regulatoryReports', 'schemeMembership', 'str', 'terminal', 'velocityLimits'
]
# Check which ones exist
existing_files = []
for root, dirs, files in os.walk('server/routers'):
for file in files:
if file.endswith('.ts'):
existing_files.append(file[:-3])
# For each missing router, if it doesn't exist, create a dummy one
for router in missing_routers:
if router not in existing_files and router + 'Router' not in existing_files:
# Create a dummy router
dummy_path = f'server/routers/{router}.ts'
print(f"Creating dummy router {dummy_path}")
with open(dummy_path, 'w', encoding='utf-8') as f:
f.write(f"""import {{ router, publicProcedure, protectedProcedure }} from '../_core/trpc';
import {{ z }} from 'zod';
export const {router}Router = router({{
// Dummy procedure to satisfy TypeScript
ping: publicProcedure.query(() => 'pong'),
}});
""")
# Now update routers.ts to import and register them
imports_to_add = []
for router in missing_routers:
router_name = f"{router}Router"
# Some files might have different names, e.g. insiderThreat exports insiderThreatRouter
imports_to_add.append(f"import {{ {router_name} }} from './routers/{router}';")
# Add imports near the top (after the last import)
last_import_idx = content.rfind('import ')
last_import_end = content.find('\n', last_import_idx) + 1
content = content[:last_import_end] + '\n// Added missing routers\n' + '\n'.join(imports_to_add) + '\n' + content[last_import_end:]
# Add to appRouter
app_router_idx = content.find('export const appRouter = router({')
if app_router_idx == -1:
print("Could not find appRouter definition")
else:
app_router_start = content.find('{', app_router_idx) + 1
registrations = []
for router in missing_routers:
registrations.append(f" {router}: {router}Router,")
content = content[:app_router_start] + '\n // Added missing routers\n' + '\n'.join(registrations) + content[app_router_start:]
with open(routers_file, 'w', encoding='utf-8') as f:
f.write(content)
print("Updated routers.ts")