62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Check all story/art/audio references in a deployable Flutter web bundle."""
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
root = Path(sys.argv[1] if len(sys.argv) > 1 else 'build/web')
|
|
missing = []
|
|
references = set()
|
|
|
|
|
|
def visit(value):
|
|
if isinstance(value, dict):
|
|
for item in value.values():
|
|
visit(item)
|
|
elif isinstance(value, list):
|
|
for item in value:
|
|
visit(item)
|
|
elif isinstance(value, str) and value.startswith('assets/'):
|
|
references.add(value)
|
|
path = root / 'assets' / value
|
|
if path.suffix in ('.png', '.wav'):
|
|
path = path.with_suffix('.webp' if path.suffix == '.png' else '.mp3')
|
|
if not path.is_file():
|
|
missing.append(value)
|
|
|
|
|
|
for name in ['index.html', 'flutter_bootstrap.js', 'narration.js', 'main.dart.js',
|
|
'manifest.json', 'main.dart.wasm', 'main.dart.mjs', 'assets/AssetManifest.bin.json',
|
|
'assets/assets/fonts/DancingScript.ttf']:
|
|
if not (root / name).is_file():
|
|
missing.append(name)
|
|
|
|
bootstrap = root / 'flutter_bootstrap.js'
|
|
if bootstrap.is_file() and ('{{flutter_js}}' in bootstrap.read_text() or
|
|
'{{flutter_build_config}}' in bootstrap.read_text()):
|
|
raise SystemExit('Flutter bootstrap still contains source templates; serve the built output, not web/.')
|
|
|
|
postcards = Path('assets/postcards/recordings-source.json')
|
|
if postcards.is_file():
|
|
visit('assets/postcards/island-postcard-v1.png')
|
|
for card in json.loads(postcards.read_text()):
|
|
visit(f"assets/postcards/audio/{card['id']}.wav")
|
|
visit(f"assets/postcards/illustrations/{card['id']}.png")
|
|
|
|
font_manifest = root / 'assets/FontManifest.json'
|
|
if font_manifest.is_file():
|
|
visit(json.loads(font_manifest.read_text()))
|
|
|
|
for path in (root / 'assets/assets').rglob('*.json'):
|
|
data = json.loads(path.read_text())
|
|
visit(data)
|
|
# Mara's original manifest uses filenames instead of asset paths.
|
|
if path.name == 'narration_manifest.json':
|
|
for track in data.get('tracks', {}).values():
|
|
if 'file' in track and 'asset' not in track:
|
|
visit('assets/audio/' + track['file'])
|
|
|
|
if missing:
|
|
raise SystemExit('Missing bundled files:\n' + '\n'.join(sorted(set(missing))))
|
|
print(f'Web bundle verified: {len(references)} referenced assets present.')
|