From ceba9fbb31bd1b561d40aefe2b02ec6f3f109b7d Mon Sep 17 00:00:00 2001 From: Victor Mattos <5757883+vicmattos@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:52:14 -0300 Subject: [PATCH] refactor(templates): Simplify target template file names with post_gen_project.py hook --- .../target-template/hooks/post_gen_project.py | 16 ++++++++++++++++ ... %}dependabot.yml{%endif%} => dependabot.yml} | 0 ... == 'GitHub' %}test.yml{%endif%} => test.yml} | 0 ...cutter.license %}LICENSE{%endif%} => LICENSE} | 0 4 files changed, 16 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..c80aa2806 --- /dev/null +++ b/cookiecutter/target-template/hooks/post_gen_project.py @@ -0,0 +1,16 @@ +#!/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