47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Monta o build autocontido da apresentação.
|
|
|
|
- Embuti src/styles.css e src/main.js dentro do HTML.
|
|
- Copia src/assets/ para build/assets/ (as imagens continuam externas).
|
|
"""
|
|
import os
|
|
import shutil
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
SRC = os.path.join(ROOT, "src")
|
|
BUILD = os.path.join(ROOT, "build")
|
|
|
|
os.makedirs(BUILD, exist_ok=True)
|
|
|
|
with open(os.path.join(SRC, "index.html"), encoding="utf-8") as f:
|
|
html = f.read()
|
|
with open(os.path.join(SRC, "styles.css"), encoding="utf-8") as f:
|
|
css = f.read()
|
|
with open(os.path.join(SRC, "main.js"), encoding="utf-8") as f:
|
|
js = f.read()
|
|
|
|
html = html.replace(
|
|
'<link rel="stylesheet" href="styles.css">',
|
|
"<style>\n" + css + "</style>",
|
|
)
|
|
html = html.replace(
|
|
'<script src="main.js"></script>',
|
|
"<script>\n" + js + "</script>",
|
|
)
|
|
|
|
# Confere que não sobrou nenhuma referência externa a CSS/JS
|
|
assert 'href="styles.css"' not in html, "styles.css não foi embutido"
|
|
assert 'src="main.js"' not in html, "main.js não foi embutido"
|
|
|
|
with open(os.path.join(BUILD, "index.html"), "w", encoding="utf-8") as f:
|
|
f.write(html)
|
|
|
|
# Imagens: build/assets/
|
|
assets_out = os.path.join(BUILD, "assets")
|
|
if os.path.isdir(assets_out):
|
|
shutil.rmtree(assets_out)
|
|
shutil.copytree(os.path.join(SRC, "assets"), assets_out)
|
|
|
|
print("build/index.html gerado ({} bytes)".format(len(html.encode("utf-8"))))
|
|
print("build/assets/ com {} arquivos".format(len(os.listdir(assets_out))))
|