Skip to content

Commit 5189d63

Browse files
authoredApr 30, 2020
Add .cookiecutter.json to project (#203)
* Add .cookiecutter.json to project This file records the JSON context used when generating the project. It allows to upgrade the project with changes from the Cookiecutter, using tools like [cupper]. [cupper]: https://github.com/senseyeio/cupper * Add post generation hook to fix JSON indentation width The jsonify extension distributed with Cookiecutter uses an indentation width of four spaces. This conflicts with the default indentation width of Prettier for JSON files. Prettier is run as a pre-commit hook in CI.
1 parent b3496e4 commit 5189d63

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎hooks/post_gen_project.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
import json
3+
from pathlib import Path
4+
5+
6+
def reindent_cookiecutter_json():
7+
"""Indent .cookiecutter.json using two spaces.
8+
9+
The jsonify extension distributed with Cookiecutter uses an indentation
10+
width of four spaces. This conflicts with the default indentation width of
11+
Prettier for JSON files. Prettier is run as a pre-commit hook in CI.
12+
"""
13+
path = Path(".cookiecutter.json")
14+
15+
with path.open() as io:
16+
data = json.load(io)
17+
18+
with path.open(mode="w") as io:
19+
json.dump(data, io, sort_keys=True, indent=2)
20+
io.write("\n")
21+
22+
23+
if __name__ == "__main__":
24+
reindent_cookiecutter_json()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ cookiecutter | jsonify }}

0 commit comments

Comments
 (0)