#!/usr/bin/env python3 """ Build a single self-contained HTML file from the source files. Usage: python3 build.py [output.html] If output is not given, defaults to 'background-standalone.html'. What gets inlined: - config.js, i18n.js (plain inside an inline block would end it early return s.replace('' % tag new = '' % body if old not in html: raise SystemExit('build.py: expected tag not found: ' + tag) return html.replace(old, new, 1) def parse_themes(config_src): m = re.search(r'window\.THEMES\s*=\s*\{(.*?)\}', config_src, re.S) if not m: raise SystemExit('build.py: window.THEMES not found in config.js') return dict(re.findall(r"'([^']+)'\s*:\s*'([^']+\.css)'", m.group(1))) def main(): out = sys.argv[1] if len(sys.argv) > 1 else 'background-standalone.html' html = read('background.html') config_src = read('config.js') themes = parse_themes(config_src) # embedded data preamble (before clouds3d's own scripts run) stars = json.loads(read('vendor/stars.json')) theme_css = {name: read(fname) for name, fname in themes.items()} embed = ( '\n' % (json.dumps(stars, separators=(',', ':')), json.dumps(theme_css)) ) anchor = '' html = html.replace(anchor, embed + anchor, 1) html = inline_script(html, 'config.js', read('config.js')) html = inline_script(html, 'i18n.js', read('i18n.js')) html = inline_script(html, 'vendor/suncalc.js', read('vendor/suncalc.js')) html = inline_script(html, 'vendor/plane3d.js', read('vendor/plane3d.js')) html = inline_script(html, 'vendor/clouds3d.js', read('vendor/clouds3d.js')) # the default stays but is # disabled by the inline-theme loader; keep a guarded fallback anyway html = html.replace('\n