From 669553ecb5c7f7e1a030a819759e43a532a80378 Mon Sep 17 00:00:00 2001 From: Victor Mattos <5757883+vicmattos@users.noreply.github.com> Date: Tue, 21 Nov 2023 16:08:47 -0300 Subject: [PATCH] refactor(templates): Simplify target template file names with `post_gen_project.py` hook (#2061) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor(templates): Simplify target template file names with post_gen_project.py hook * Update cookiecutter/target-template/hooks/post_gen_project.py --------- Co-authored-by: Edgar Ramírez Mondragón <16805946+edgarrmondragon@users.noreply.github.com> --- .../target-template/hooks/post_gen_project.py | 14 ++++++++++++++ ...b' %}dependabot.yml{%endif%} => dependabot.yml} | 0 ...es == 'GitHub' %}test.yml{%endif%} => test.yml} | 0 ...iecutter.license %}LICENSE{%endif%} => LICENSE} | 0 4 files changed, 14 insertions(+) create mode 100644 cookiecutter/target-template/hooks/post_gen_project.py rename cookiecutter/target-template/{{cookiecutter.target_id}}/.github/{{% if cookiecutter.include_ci_files == 'GitHub' %}dependabot.yml{%endif%} => dependabot.yml} (100%) rename cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/{{% if cookiecutter.include_ci_files == 'GitHub' %}test.yml{%endif%} => test.yml} (100%) rename cookiecutter/target-template/{{cookiecutter.target_id}}/{{%if 'Apache-2.0' == cookiecutter.license %}LICENSE{%endif%} => LICENSE} (100%) diff --git a/cookiecutter/target-template/hooks/post_gen_project.py b/cookiecutter/target-template/hooks/post_gen_project.py new file mode 100644 index 000000000..44edd337b --- /dev/null +++ b/cookiecutter/target-template/hooks/post_gen_project.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +from pathlib import Path +import shutil + + +BASE_PATH = Path("{{cookiecutter.library_name}}") + + +if __name__ == "__main__": + if "{{ cookiecutter.license }}" != "Apache-2.0": + Path("LICENSE").unlink() + + if "{{ cookiecutter.include_ci_files }}" != "GitHub": + shutil.rmtree(Path(".github")) diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/{% if cookiecutter.include_ci_files == 'GitHub' %}dependabot.yml{%endif%} b/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/dependabot.yml similarity index 100% rename from cookiecutter/target-template/{{cookiecutter.target_id}}/.github/{% if cookiecutter.include_ci_files == 'GitHub' %}dependabot.yml{%endif%} rename to cookiecutter/target-template/{{cookiecutter.target_id}}/.github/dependabot.yml diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/{% if cookiecutter.include_ci_files == 'GitHub' %}test.yml{%endif%} b/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/test.yml similarity index 100% rename from cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/{% if cookiecutter.include_ci_files == 'GitHub' %}test.yml{%endif%} rename to cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/test.yml diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/{%if 'Apache-2.0' == cookiecutter.license %}LICENSE{%endif%} b/cookiecutter/target-template/{{cookiecutter.target_id}}/LICENSE similarity index 100% rename from cookiecutter/target-template/{{cookiecutter.target_id}}/{%if 'Apache-2.0' == cookiecutter.license %}LICENSE{%endif%} rename to cookiecutter/target-template/{{cookiecutter.target_id}}/LICENSE