Files

30 lines
1.0 KiB
Python

#!/usr/bin/env python3
"""Embed the single CSS theme for native, browser and portable builds."""
import argparse
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SOURCE = ROOT / 'src/choano.css'
OUTPUT = ROOT / 'src/theme_source.zi'
def generated():
return ('// Generated by scripts/theme.py from src/choano.css. Edit the CSS file.\n'
'PATH :: "src/choano.css";\nSOURCE :: ' + json.dumps(SOURCE.read_text(), ensure_ascii=False) + ';\n')
def prepare():
expected = generated()
if not OUTPUT.exists() or OUTPUT.read_text() != expected:
OUTPUT.write_text(expected)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--check', action='store_true')
args = parser.parse_args()
if args.check:
if not OUTPUT.exists() or OUTPUT.read_text() != generated():
raise SystemExit('Theme embedding is stale; run python3 scripts/theme.py')
print('Choano local CSS source/embedding test passed.')
else:
prepare()