1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import json
- import os
- import shutil
- import subprocess
- def main():
- print('=> rebuilding wasm')
- subprocess.check_call(['wasm-pack', 'build', '--target', 'web'])
- os.makedirs('out', exist_ok=True)
- build_index()
- print('=> moving wasm output')
- for root, _, files in os.walk('pkg'):
- for f in files:
- shutil.copy(
- os.path.join(root, f),
- os.path.join('out', f)
- )
- 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'<option value="{s}">{s}.matzo</option>'
- 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__':
- main()
|