Add Copier, migrate from Cookiecutter, in a way that supports using the project as is, forking or cloning it (#612)

* 🔧 Add first Copier config

* 🔧 Add custom copier answers file

* 🔨 Add Copier script to update .env after generating/copying

* 🙈 Update .gitignores from Copier updates

* 🔧 Update .env, restructure in order of relevance

* 🔧 Remove Copier config for SMTP port, if necessary, it can be overwritten in .env

* ♻️ Refactor Copier files, make them less visible

* 🔧 Update Copier config

* 🔥 Remove Cookiecutter files
This commit is contained in:
Sebastián Ramírez
2024-02-25 21:20:20 +01:00
committed by GitHub
parent 0cc802eec8
commit 42726193d0
9 changed files with 179 additions and 109 deletions

View File

@@ -0,0 +1 @@
{{ _copier_answers|to_json -}}

View File

@@ -0,0 +1,22 @@
from pathlib import Path
import json
# Update the .env file with the answers from the .copier-answers.yml file
# without using Jinja2 templates in the .env file, this way the code works as is
# without needing Copier, but if Copier is used, the .env file will be updated
root_path = Path(__file__).parent.parent
answers_path = Path(__file__).parent / ".copier-answers.yml"
answers = json.loads(answers_path.read_text())
env_path = root_path / ".env"
env_content = env_path.read_text()
lines = []
for line in env_content.splitlines():
for key, value in answers.items():
upper_key = key.upper()
if line.startswith(f"{upper_key}="):
new_line = line.replace(line, f"{upper_key}={value}")
lines.append(new_line)
break
else:
lines.append(line)
env_path.write_text("\n".join(lines))