-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
543 lines (463 loc) · 21.7 KB
/
Copy pathbuild.py
File metadata and controls
543 lines (463 loc) · 21.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
import os
import re
import sys
from datetime import datetime
# Configuration
APPEND_BUILD_ID = False # Set to True to append YYYYMMDD_HHMMSS to version
COMPONENT_DIR = os.path.dirname(os.path.abspath(__file__))
HTML_FILE = os.path.join(COMPONENT_DIR, 'index.html')
CSS_FILE = os.path.join(COMPONENT_DIR, 'styles.css')
JS_DIR = os.path.join(COMPONENT_DIR, 'js')
OUTPUT_FILE = os.path.join(COMPONENT_DIR, 'Build', 'advanced_tmp_editor.html')
# Scripts directory
SCRIPTS_DIR = os.path.join(COMPONENT_DIR, 'Scripts')
# Optional Comment Cleanup Script
COMMENT_CLEANUP_SCRIPT = 'clean_comments.py'
# HTML Structure Validator Script
HTML_VALIDATOR_SCRIPT = 'validate_html.py'
# Translation Validator Script
TRANSLATION_VALIDATOR_SCRIPT = 'validate_translations.py'
# Game Palettes Configuration
PALETTES_SOURCE_DIR = os.path.join(COMPONENT_DIR, 'Palettes')
GAME_PALETTES_JS = os.path.join(JS_DIR, 'game_palettes.js')
import base64
import json
# Order is critical for dependencies
JS_ORDER = [
'constants.js',
'ramp_types.js',
'state.js',
'translations.js',
'tmp_format.js',
'history.js',
'utils.js',
'predefined_zdata.js',
'ui.js',
'tools.js',
'import_tmp.js',
'pcx_loader.js',
'file_io.js',
'game_palettes.js',
'palette_menu.js',
'menu_handlers.js',
'tabs.js',
'main.js'
]
PREDEFINED_ZDATA_DIR = os.path.join(COMPONENT_DIR, 'game_zdata')
PREDEFINED_ZDATA_JS = os.path.join(JS_DIR, 'predefined_zdata.js')
def generate_predefined_zdata():
if not os.path.exists(PREDEFINED_ZDATA_DIR):
print(f"[INFO] Predefined zdata directory not found at {PREDEFINED_ZDATA_DIR}. Skipping generation.")
if not os.path.exists(PREDEFINED_ZDATA_JS):
with open(PREDEFINED_ZDATA_JS, "w", encoding="utf-8") as f:
f.write("export const PREDEFINED_ZDATA = {};\n")
return
print("Generating predefined z-data...")
zdata_images = {"ts": {}, "ra2": {}}
categories = ["TS", "RA2"]
for cat in categories:
cat_path = os.path.join(PREDEFINED_ZDATA_DIR, cat)
if not os.path.exists(cat_path):
continue
files = [f for f in os.listdir(cat_path) if f.lower().endswith('.png')]
files.sort()
for filename in files:
file_path = os.path.join(cat_path, filename)
idx_str = "".join(filter(str.isdigit, filename))
if not idx_str: continue
idx = int(idx_str)
with open(file_path, "rb") as f:
data = f.read()
b64_data = base64.b64encode(data).decode('utf-8')
zdata_images[cat.lower()][idx] = f"data:image/png;base64,{b64_data}"
content = f"// AUTO-GENERATED PREDEFINED ZDATA\nexport const PREDEFINED_ZDATA = {json.dumps(zdata_images, indent=2)};\n"
with open(PREDEFINED_ZDATA_JS, "w", encoding="utf-8") as f:
f.write(content)
print(f"[OK] Generated {PREDEFINED_ZDATA_JS}")
RAMP_TYPES_SOURCE_DIR = os.path.join(COMPONENT_DIR, 'ramp_types')
RAMP_TYPES_JS = os.path.join(JS_DIR, 'ramp_types.js')
def generate_ramp_types_data():
if not os.path.exists(RAMP_TYPES_SOURCE_DIR):
print(f"[INFO] Ramp types source directory not found at {RAMP_TYPES_SOURCE_DIR}. Skipping generation.")
# Create empty if not exists to not break build
if not os.path.exists(RAMP_TYPES_JS):
with open(RAMP_TYPES_JS, "w", encoding="utf-8") as f:
f.write("export const RAMP_IMAGES = {};\n")
return
print("Generating ramp types data...")
ramp_images = {}
files = [f for f in os.listdir(RAMP_TYPES_SOURCE_DIR) if f.lower().endswith('.png')]
files.sort()
for filename in files:
file_path = os.path.join(RAMP_TYPES_SOURCE_DIR, filename)
idx = int(filename[5:7]) # mslop00.png -> 0
with open(file_path, "rb") as f:
data = f.read()
b64_data = base64.b64encode(data).decode('utf-8')
ramp_images[idx] = f"data:image/png;base64,{b64_data}"
content = f"// AUTO-GENERATED RAMP TYPES DATA\nexport const RAMP_IMAGES = {json.dumps(ramp_images, indent=2)};\n"
with open(RAMP_TYPES_JS, "w", encoding="utf-8") as f:
f.write(content)
print(f"[OK] Generated {RAMP_TYPES_JS}")
def generate_game_palettes_data():
if not os.path.exists(PALETTES_SOURCE_DIR):
print(f"[INFO] Palettes source directory not found at {PALETTES_SOURCE_DIR}. Skipping generation.")
return
print("Generating game palettes data...")
categories = [
{"folder": "Tiberian Sun", "key": "ts"},
{"folder": "Red Alert 2", "key": "ra2"},
{"folder": "Yuri's Revenge", "key": "yr"},
{"folder": "cnc reloaded", "key": "cncreloaded"}
]
game_palettes = {}
# Get actual directory names on disk for case-insensitive matching
available_dirs = {d.lower(): d for d in os.listdir(PALETTES_SOURCE_DIR)
if os.path.isdir(os.path.join(PALETTES_SOURCE_DIR, d))}
for cat in categories:
folder_key = cat["folder"].lower()
if folder_key not in available_dirs:
continue
folder_path = os.path.join(PALETTES_SOURCE_DIR, available_dirs[folder_key])
files = [f for f in os.listdir(folder_path) if f.lower().endswith('.pal')]
files.sort()
for filename in files:
file_path = os.path.join(folder_path, filename)
with open(file_path, "rb") as f:
data = f.read()
if len(data) == 768:
b64_data = base64.b64encode(data).decode('utf-8')
name = os.path.splitext(filename)[0]
pal_id = f"game_{cat['key']}_{name.lower().replace(' ', '_')}"
if cat["key"] not in game_palettes:
game_palettes[cat["key"]] = []
game_palettes[cat["key"]].append({ # type: ignore
"id": pal_id,
"name": name,
"b64": b64_data,
"category": cat["key"]
})
content = f"// AUTO-GENERATED GAME PALETTES DATA\nexport const GAME_PALETTES = {json.dumps(game_palettes, indent=2)};\n"
with open(GAME_PALETTES_JS, "w", encoding="utf-8") as f:
f.write(content)
print(f"[OK] Generated {GAME_PALETTES_JS}")
def read_file(path):
with open(path, 'r', encoding='utf-8') as f:
return f.read()
def bundle():
print("Bundling Advanced TMP Editor...")
# 0. Generate game palettes and ramp types
generate_game_palettes_data()
generate_ramp_types_data()
generate_predefined_zdata()
if COMPONENT_DIR not in sys.path:
sys.path.insert(0, COMPONENT_DIR)
if SCRIPTS_DIR not in sys.path:
sys.path.insert(0, SCRIPTS_DIR)
# 0.5 Validate source HTML Structure (pre-build)
validator_path = os.path.join(SCRIPTS_DIR, HTML_VALIDATOR_SCRIPT)
if os.path.exists(validator_path):
print("\nRunning pre-build HTML validation on source (index.html)...")
from validate_html import validate_html_file # type: ignore
errors, _ = validate_html_file(HTML_FILE)
if errors:
print("\n[ERROR] Source HTML has structural issues. Build aborted.")
print(" Fix the errors above before building.\n")
sys.exit(1)
print("Source HTML validation passed.\n")
# 0.7 Check for TODO/FIXME in all source files
print("Scanning for unfinished tasks (TODO/FIXME)...")
todo_found = False
for root, _, files in os.walk(COMPONENT_DIR):
if any(d in root for d in ('.git', '.gemini', '__pycache__')): continue
for f in files:
if not f.endswith(('.html', '.js', '.css', '.py')): continue
# Don't scan this script itself for its own keywords
if f == os.path.basename(__file__): continue
p = os.path.join(root, f)
with open(p, 'r', encoding='utf-8', errors='ignore') as src:
for line_no, content in enumerate(src, 1):
if 'TODO' in content or 'FIXME' in content:
print(f" [INFO] Task found in {os.path.relpath(p, COMPONENT_DIR)} (L{line_no}): {content.strip()}")
todo_found = True
if not todo_found:
print(" [OK] No TODOs or FIXMEs found. Code looks ready.")
else:
print(" [TIP] Remember to check the tasks listed above before final deployment.\n")
html_content = read_file(HTML_FILE)
# 1.5 Handle Build ID / Versioning
if APPEND_BUILD_ID:
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
# Strip any existing build ID first, then append the new one
html_content = re.sub(
r"(const APP_VERSION = ')(.*?)(\s*-\s*Build\s*\d{8}_\d{6})?(')",
fr"\1\2 - Build {ts}\4",
html_content
)
# 2. Embed CSS
print(f"Embedding {CSS_FILE} and refinements.css...")
css_content = read_file(CSS_FILE)
if os.path.exists(os.path.join(COMPONENT_DIR, 'refinements.css')):
css_content += "\n" + read_file(os.path.join(COMPONENT_DIR, 'refinements.css'))
html_content = html_content.replace(
'<link rel="stylesheet" href="styles.css">',
f'<style>\n{css_content}\n</style>'
)
# Also remove refinements.css link if present since it's merged above
html_content = html_content.replace(
'<link rel="stylesheet" href="refinements.css">',
''
)
# 3. Bundle JS
print("Bundling JavaScript modules...")
js_bundle = ""
for js_name in JS_ORDER:
path = os.path.join(JS_DIR, js_name)
if not os.path.exists(path):
print(f"Error: Could not find {path}")
return
print(f"Processing {js_name}...")
script_content = read_file(path)
# Remove import statements (handles multi-line)
script_content = re.sub(r'import\s+.*?from\s+[\'"].*?[\'"];?\n?', '', script_content, flags=re.DOTALL)
# Remove export keywords (handles export async function, export const, etc.)
script_content = re.sub(r'export\s+(async\s+)?(function|const|let|var|class)\s+', r'\1\2 ', script_content)
# Remove export { ... } statements
script_content = re.sub(r'export\s+\{.*?\};?\n?', '', script_content, flags=re.DOTALL)
js_bundle += f"\n// --- {js_name} ---\n{script_content}\n"
# 3.5 Check Syntax Using Node.js
import subprocess
print("Checking JavaScript syntax using Node.js...")
tmp_js = os.path.join(COMPONENT_DIR, '.syntax_check.js')
with open(tmp_js, 'w', encoding='utf-8') as f:
f.write(js_bundle)
try:
res = subprocess.run(['node', '-c', '.syntax_check.js'], capture_output=True, text=True, cwd=COMPONENT_DIR)
if res.returncode != 0:
print("\n[ERROR] JavaScript Syntax Error found during build!")
print("="*40)
print(res.stderr)
print("="*40)
print("Build aborted. Fix the syntax error above.")
sys.exit(1)
else:
print("[OK] JavaScript syntax is valid.")
except FileNotFoundError:
print("\n" + "="*60)
print("[WARNING] Node.js is not installed or not in your PATH.")
print(" Syntax checking for the final bundle will be skipped.")
print("="*60)
print("\nWhat is Node.js?")
print(" Node.js is simply the JavaScript engine from Google Chrome")
print(" packaged as a standalone, lightweight program. It is the")
print(" industry standard for validating JavaScript code offline.")
print("\nDoes it install Docker or bloatware?")
print(" NO. It does not install Docker, virtual machines, or heavy")
print(" background services. It's just a clean executable engine.")
print("\nHow to install it (Recommended):")
print(" 1. Go to https://nodejs.org/")
print(" 2. Download the 'LTS' (Long Term Support) installer for Windows.")
print(" 3. Run the installer (you can leave all default options).")
print(" 4. IMPORTANT: Close this terminal/command prompt and open a new one")
print(" so Windows registers the new 'node' command.")
print(" 5. Run 'python build.py' again. You will now have automatic,")
print(" bulletproof syntax checking!")
print("\n" + "="*60 + "\n")
finally:
if os.path.exists(tmp_js):
os.remove(tmp_js)
# 4. Embed JS into HTML
# Replace the module script tag with the bundled script
html_content = html_content.replace(
'<script type="module" src="js/main.js"></script>',
f'<script>\n{js_bundle}\n</script>'
)
# 5.5 Update PWA Manifest dynamically to match OUTPUT_FILE basename
print(f"Updating PWA manifest for {os.path.basename(OUTPUT_FILE)}...")
manifest_match = re.search(r"<link rel=\"manifest\"[\s\S]+?href='data:application/json,([\s\S]+?)'\s*>", html_content, re.DOTALL)
if manifest_match:
try:
manifest_json = json.loads(manifest_match.group(1))
basename = os.path.basename(OUTPUT_FILE)
manifest_json['start_url'] = f"./{basename}"
if 'file_handlers' in manifest_json:
for handler in manifest_json['file_handlers']:
handler['action'] = f"./{basename}"
import urllib.parse
manifest_str = json.dumps(manifest_json)
encoded_manifest = urllib.parse.quote(manifest_str)
updated_manifest = f"<link rel=\"manifest\" href='data:application/json,{encoded_manifest}'>"
html_content = html_content.replace(manifest_match.group(0), updated_manifest)
except Exception as e:
print(f"[WARNING] Failed to update PWA manifest: {e}")
# 6. Prepare Final Content with License
license_header = f"""<!--
Advanced TMP Editor
Copyright (C) 2026 FS-21
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
"""
full_content = license_header + html_content
# 6.1 Write Standard Bundle Output
os.makedirs(os.path.dirname(OUTPUT_FILE), exist_ok=True)
with open(OUTPUT_FILE, 'w', encoding='utf-8') as f:
f.write(full_content)
print(f"Done! Created {OUTPUT_FILE}")
# 7. Generate PWA deployment folder
pwa_dir = os.path.join(COMPONENT_DIR, 'Build', 'PWA')
print(f"\nGenerating PWA deployment folder at {pwa_dir}...")
if not os.path.exists(pwa_dir):
os.makedirs(pwa_dir)
# 7.1 Copy bundle as index.html
pwa_index = os.path.join(pwa_dir, 'index.html')
pwa_html = full_content
manifest_data = {
"name": "Advanced TMP Editor",
"short_name": "A TMP Editor",
"description": "Advanced TMP Tile Set Editor for Tiberian Sun & Red Alert 2",
"start_url": "./index.html",
"display": "standalone",
"background_color": "#0d0e12",
"theme_color": "#00ff9d",
"icons": [
{
"src": "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHJ4PSIxNCIgZmlsbD0iIzBkMGUxMiIvPjx0ZXh0IHg9IjMyIiB5PSIyNiIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZmlsbD0iI2ZmZmZmZiIgZm9udC1mYW1pbHk9IlZlcmRhbmEsIHNhbnMtc2VyaWYiIGZvbnQtd2VpZ2h0PSI5NTAiIGZvbnQtc2l6ZT0iMjIiIGxldHRlci1zcGFjaW5nPSItMSI+VE1QPC90ZXh0PjxnIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxnIHN0cm9rZT0iIzAwZmY5ZCIgc3Ryb2tlLXdpZHRoPSIwLjgiIG9wYWNpdHk9IjAuNSI+PHBhdGggZD0iTTE4IDM3TDQ2IDUxIE0xMSA0MC41TDM5IDU0LjVBNTI1IDMzLjVUNTMgNDcuNSIgLz48cGF0aCBkPSJNNDYgMzdMMTggNTEgTTUzIDQwLjVMMjUgNTQuNSBNMzkgMzMuNUwxMSA0Ny41IiAvPjwvZz48cGF0aCBkPSJNMzIgMzBWNTggTTQgNDRINTAiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLXdpZHRoPSIxLjIiIG9wYWNpdHk9IjAuOCIvPjxnIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLXdpZHRoPSIxLjgiIGZpbGw9IiNmZmZmZmYxNSI+PHBhdGggZD0iTTM5IDMzLjVMNDYgMzdMMzkgNDAuNUwzMiAzN1oiIC8+PHBhdGggZD0iTTQ2IDM3TDUzIDQwLjVMNDYgNDRMMzkgNDAuNVoiIC8+PHBhdGggZD0iTTM5IDQ3LjVMNDYgNTFMMzkgNTQuNUwzMiA1MVoiIC8+PC9nPjxwYXRoIGQ9Ik0zMiAzMEw2MCA0NEwzMiA1OEw0IDQ0TDMyIDMwWiIgc3Ryb2tlPSIjMDBmZjlkIiBzdHJva2Utd2lkdGg9IjIuNSIvPjwvZz48L3N2Zz4=",
"sizes": "64x64 192x192 512x512 any",
"type": "image/svg+xml",
"purpose": "any maskable"
}
],
"file_handlers": [
{
"action": "./index.html",
"accept": {
"application/x-wwn-tmp": [".tem", ".sno", ".urb", ".des", ".ubn", ".lun"]
},
"launch_type": "single-client"
}
]
}
manifest_file = os.path.join(pwa_dir, 'manifest.json')
with open(manifest_file, 'w', encoding='utf-8') as f:
json.dump(manifest_data, f, indent=4)
print(f"[OK] PWA manifest.json created.")
# 7.3 Update index.html in PWA folder to point to manifest.json instead of data URI
manifest_pattern = r'<link rel="manifest"[\s\S]+?href=\'data:application/json,[\s\S]+?\'\s*>'
pwa_html = re.sub(manifest_pattern, '<link rel="manifest" href="manifest.json">', pwa_html)
with open(pwa_index, 'w', encoding='utf-8') as f:
f.write(pwa_html)
print(f"[OK] PWA index.html created.")
# 7.4 Generate Dedicated Service Worker for PWA folder
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
pwa_sw_file = os.path.join(pwa_dir, 'sw.js')
pwa_sw_content = f"""const CACHE_NAME = 'tmp-editor-pwa-{ts}';
const ASSETS = [
'./',
'./index.html'
];
self.addEventListener('install', (event) => {{
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => {{
return cache.addAll(ASSETS);
}})
);
}});
self.addEventListener('activate', (event) => {{
event.waitUntil(
caches.keys().then((keys) => {{
return Promise.all(
keys.filter((key) => key !== CACHE_NAME)
.map((key) => caches.delete(key))
);
}})
);
}});
self.addEventListener('fetch', (event) => {{
event.respondWith(
caches.match(event.request).then((cachedResponse) => {{
return cachedResponse || fetch(event.request);
}})
);
}});
"""
with open(pwa_sw_file, 'w', encoding='utf-8') as f:
f.write(pwa_sw_content)
print(f"[OK] PWA sw.js updated.")
# 7.4 Ensure global Service Worker still exists for primary build
sw_file = os.path.join(COMPONENT_DIR, 'sw.js')
sw_content = f"""const CACHE_NAME = 'tmp-editor-{ts}';
const ASSETS = [
'./',
'./{os.path.basename(OUTPUT_FILE)}',
'./index.html',
'./sw.js'
];
self.addEventListener('install', (event) => {{
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => {{
return cache.addAll(ASSETS);
}})
);
}});
self.addEventListener('activate', (event) => {{
event.waitUntil(
caches.keys().then((keys) => {{
return Promise.all(
keys.filter((key) => key !== CACHE_NAME)
.map((key) => caches.delete(key))
);
}})
);
}});
self.addEventListener('fetch', (event) => {{
event.respondWith(
caches.match(event.request).then((cachedResponse) => {{
return cachedResponse || fetch(event.request);
}})
);
}});
"""
with open(sw_file, 'w', encoding='utf-8') as f:
f.write(sw_content)
print(f"Global Service Worker updated at {sw_file}")
import subprocess
if __name__ == '__main__':
bundle()
# Post-build: Validate HTML structure of the final bundle
validator_path = os.path.join(SCRIPTS_DIR, HTML_VALIDATOR_SCRIPT)
if os.path.exists(validator_path):
print("\nRunning post-build HTML structure validation on bundle...")
from validate_html import validate_html_file # type: ignore
errors, warnings = validate_html_file(OUTPUT_FILE)
if errors:
print("[WARNING] Bundle has HTML structure issues! Check the report above.")
else:
print(f"\n[INFO] HTML validator '{HTML_VALIDATOR_SCRIPT}' not found. Skipping.")
# Run comment validation script after build, if it exists
cleanup_path = os.path.join(SCRIPTS_DIR, COMMENT_CLEANUP_SCRIPT)
if os.path.exists(cleanup_path):
print("\nRunning post-build comment validation...")
result = subprocess.run(['python', cleanup_path], cwd=COMPONENT_DIR)
if result.returncode != 0:
print("\n[WARNING] Build succeeded but comment validation failed.")
else:
print(f"\n[INFO] Comment cleanup script '{COMMENT_CLEANUP_SCRIPT}' not found. Skipping validation.")
# Post-build Translation Parity Check
trans_validator_path = os.path.join(SCRIPTS_DIR, TRANSLATION_VALIDATOR_SCRIPT)
if os.path.exists(trans_validator_path):
print("\nChecking translations for missing entries (parity scan)...")
result = subprocess.run(['python', trans_validator_path], cwd=COMPONENT_DIR)
if result.returncode != 0:
print("\n[CRITICAL] Translation parity check FAILED. Please fix missing keys above.")
sys.exit(1)
else:
print("[SUCCESS] Translations are consistent across all languages.")