Skip to content

Commit

Permalink
refactor(templates): Simplify tap template file names with `post_gen_…
Browse files Browse the repository at this point in the history
…project.py` hook (#2060)

* refactor(templates): simplify file names with `post_gen_project.py` hook

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* revert(templates): undo changes within client files and only keep rename

* chore: remove template ci files from `check-yaml` pre-commit hook

* refactor(template): simplify folder remove in `post_gen_project.py` by using `shutil.rmtree`

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Edgar Ramírez Mondragón <[email protected]>
  • Loading branch information
3 people authored Nov 21, 2023
1 parent 206c38e commit 424e777
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ repos:
exclude: |
(?x)^(
cookiecutter/.*/meltano.yml|
cookiecutter/.*/.pre-commit-config.yaml
cookiecutter/.*/.pre-commit-config.yaml|
cookiecutter/.*/dependabot.yml|
cookiecutter/.*/test.yml
)$
- id: end-of-file-fixer
exclude: |
Expand Down
4 changes: 2 additions & 2 deletions cookiecutter/tap-template/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"JWT",
"Custom or N/A"
],
"include_ci_files": ["GitHub", "None (Skip)"],
"license": ["Apache-2.0"],
"include_ci_files": ["GitHub", "None"],
"license": ["Apache-2.0", "None"],
"__prompts__": {
"source_name": "The name of the source, in CamelCase",
"admin_name": "Provide your [bold yellow]full name[/]",
Expand Down
27 changes: 27 additions & 0 deletions cookiecutter/tap-template/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
from pathlib import Path
import shutil


BASE_PATH = Path('{{cookiecutter.library_name}}')


if __name__ == '__main__':

# Rename stream type client and delete others
target = Path(BASE_PATH, 'client.py')
Path(BASE_PATH, '{{cookiecutter.stream_type|lower}}-client.py').rename(target)
[c.unlink() for c in Path(BASE_PATH).rglob("*-client.py")]

if '{{ cookiecutter.auth_method }}' not in ('OAuth2', 'JWT'):
Path(BASE_PATH, 'auth.py').unlink()

if '{{ cookiecutter.stream_type }}' == 'SQL':
Path(BASE_PATH, 'streams.py').unlink()

if '{{ cookiecutter.license }}' != 'Apache-2.0':
Path('LICENSE').unlink()

if '{{ cookiecutter.include_ci_files }}' != 'GitHub':
shutil.rmtree(Path('.github'))

0 comments on commit 424e777

Please sign in to comment.