123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 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'<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__':
- if '--only-html' in sys.argv:
- build_index()
- else:
- main()
|