Skip to content

Commit 54c0d09

Browse files
authored
Update the post_gen_project script (#14)
* Update the `post_get_project` script * Update `CHANGELOG.md` * Update `generate.yml`
1 parent d68e99f commit 54c0d09

5 files changed

Lines changed: 62 additions & 21 deletions

File tree

.github/workflows/generate.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ jobs:
2222
run: |
2323
brew install cookiecutter mint
2424
cookiecutter --no-input -f .
25-
cd Project
2625
mint bootstrap
2726
swift test

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ All notable changes to this project will be documented in this file.
1919
- Implement typo checking
2020
- Added in Pull Request [#7](https://github.com/space-code/package-template/pull/7).
2121

22+
## Updated
23+
- Update `post_get_project` script
24+
- Updated in Pull Request[#14](https://github.com/space-code/package-template/pull/14).
25+
2226
#### 1.x Releases
2327
- `1.1.x` Releases - [1.1.0](#110) | [1.1.1](#111)
2428
- `1.0.x` Releases - [1.0.0](#100)

hooks/post_gen_project.py

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,63 @@
11
import os
22
import shutil
3+
import subprocess
34

4-
print(os.getcwd())
5+
def print_current_directory():
6+
print(os.getcwd())
57

6-
def remove(filepath):
7-
if os.path.isfile(filepath):
8-
os.remove(filepath)
9-
elif os.path.isdir(filepath):
10-
shutil.rmtree(filepath)
8+
def rename_copy_remove():
9+
source_directory = "../{{ cookiecutter.name | lower }}"
10+
temp_directory = "../temp"
1111

12-
create_docc = '{{ cookiecutter.deploy_docc }}' == 'yes'
12+
try:
13+
os.rename(source_directory, temp_directory)
14+
os.chdir('..')
15+
shutil.copytree(os.path.join(os.getcwd(), "temp"), os.getcwd(), dirs_exist_ok=True)
1316

14-
if not create_docc:
15-
remove(os.path.join(os.getcwd(), '.github/workflows', 'deploy_docc.yml'))
17+
except Exception as e:
18+
print(f"An error occurred: {e}")
19+
finally:
20+
shutil.rmtree(os.path.join(os.getcwd(), "temp"))
21+
22+
def remove_file_or_directory(filepath):
23+
if os.path.exists(filepath):
24+
if os.path.isfile(filepath):
25+
os.remove(filepath)
26+
elif os.path.isdir(filepath):
27+
shutil.rmtree(filepath)
28+
29+
def remove_deploy_docc():
30+
filepath = os.path.join(os.getcwd(), '.github/workflows/deploy_docc.yml')
31+
remove_file_or_directory(filepath)
32+
33+
def initialize_swift_library():
34+
project_name = "{{ cookiecutter.name }}"
35+
subprocess.run(["swift", "package", "init", "--name", project_name, "--type", "library"])
36+
37+
def run_make_commands():
38+
subprocess.run(["make", "bootstrap"])
39+
subprocess.run(["make", "fmt"])
40+
41+
def initialize_git_repository():
42+
subprocess.run(["git", "init"])
43+
subprocess.run(["git", "add", "."])
44+
subprocess.run(["git", "commit", "-m", "Initial commit"])
45+
46+
def main():
47+
print_current_directory()
48+
49+
create_docc = '{{ cookiecutter.deploy_docc.lower() }}' == 'yes'
50+
51+
if not create_docc:
52+
remove_deploy_docc()
53+
54+
rename_copy_remove()
55+
56+
initialize_swift_library()
57+
58+
run_make_commands()
59+
60+
initialize_git_repository()
61+
62+
if __name__ == "__main__":
63+
main()

hooks/post_gen_project.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

{{ cookiecutter.name | lower }}/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ bootstrap: hook
44
mint bootstrap
55

66
hook:
7-
ln -sf ../../hooks/pre-commit .git/hooks/pre-commit
7+
ln -sf .git/hooks/pre-commit ../../hooks/pre-commit
88
chmod +x .git/hooks/pre-commit
99

1010
mint:

0 commit comments

Comments
 (0)