Skip to content

Commit 368cbe7

Browse files
committed
Copy the replay file into the repo
Cookiecutter saves a replay file (oddly) in `~/.cookiecutter_replay/cookiecutter.json` that can be later used with `--replay --replay-file` to regenerate the template without having to enter all the inputs again. We save this file in the repo to make it easier to fetch future updates to the templates. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 1074a6b commit 368cbe7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cookiecutter/hooks/post_gen_project.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def finish_setup() -> None:
9292
"""
9393
was_repo_initialized = initialize_git_repo()
9494

95+
copy_replay_file()
96+
9597
remove_unneeded_files()
9698

9799
match cookiecutter.type:
@@ -110,6 +112,22 @@ def finish_setup() -> None:
110112
commit_git_changes(first_commit=was_repo_initialized)
111113

112114

115+
def copy_replay_file() -> None:
116+
"""Copy the replay file to the project root."""
117+
src = _pathlib.Path("~/.cookiecutter_replay/cookiecutter.json").expanduser()
118+
dst = _pathlib.Path(".cookiecutter-replay.json")
119+
if not src.exists():
120+
print(f"WARNING: No replay file found in {src}. Skipping...")
121+
122+
try:
123+
_shutil.copyfile(src, dst)
124+
except (OSError, IOError) as error:
125+
print(
126+
f"WARNING: Error copying the replay file {src} -> {dst} ({error}). "
127+
"Skipping..."
128+
)
129+
130+
113131
def initialize_git_submodules() -> bool:
114132
"""Initialize git submodules.
115133

0 commit comments

Comments
 (0)