automatically handle static files

This commit is contained in:
Ruidy 2023-06-04 09:45:05 +02:00
parent 43f5982d5d
commit 04006bb736
4 changed files with 22 additions and 1 deletions

View file

@ -22,6 +22,7 @@ The configuration file ([config.json](./config.json)) is mandatory and should re
"contact.html",
"reservation.html"
],
"staticFiles": [],
"outDir": "dist"
}
```

View file

@ -7,5 +7,11 @@
"contact.html",
"reservation.html"
],
"staticFiles": [
"images",
"js",
"css",
"webfonts"
],
"outDir": "dist"
}

View file

@ -5,6 +5,7 @@ from typing import TypedDict
class Config(TypedDict):
name: str
templates: list[str]
staticFiles: list[str]
outDir: str

View file

@ -1,3 +1,5 @@
import os
import shutil
import sys
from os import path
@ -15,11 +17,22 @@ def main():
sys.exit()
data = {}
destination_path = config["outDir"]
logger.info(f"🏁 Start building {config['name']}")
if os.path.exists(destination_path) and os.path.isdir(destination_path):
shutil.rmtree(destination_path)
os.mkdir(destination_path)
for template in config["templates"]:
logger.info(f"📃Render '{template}'")
with open(path.join(config["outDir"], template), "w") as f:
with open(path.join(destination_path, template), "w") as f:
f.write(render(template, data.get(template)))
logger.info("⏩ Start copying staticfiles to build")
for folder in config["staticFiles"]:
shutil.copytree(folder, f"{config['outDir']}/{folder}")
logger.info("🎉 Done…")