import json import os import shutil import subprocess import sys def main(): print('=> cleaning') shutil.rmtree('out') print('=> rebuilding wasm') # subprocess.check_call(['wasm-pack', 'build', '--target', 'web']) print('=> rebuilding js') subprocess.check_call(['yarn', 'build']) os.makedirs('out', exist_ok=True) build_index() print('=> moving wasm output') shutil.copytree('dist', os.path.join('out', 'dist')) def build_index(): print('=> building index.html') sources = {} for root, _, files in os.walk("examples"): for f in files: if not f.endswith(".matzo"): continue with open(os.path.join(root, f)) as s: sources[f.removesuffix(".matzo")] = s.read() with open('index.html') as f: template = f.read() examples = '\n'.join(( f'' for s in sorted(sources.keys()) if s != 'hello' )) template = (template .replace('%SOURCES%', json.dumps(sources)) .replace('%EXAMPLES%', examples)) with open(os.path.join('out', 'index.html'), 'w') as f: f.write(template) if __name__ == '__main__': if '--only-html' in sys.argv: build_index() else: main()