Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ jobs:
run: |
brew install cookiecutter mint
cookiecutter --no-input -f .
cd Project
mint bootstrap
swift test
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ All notable changes to this project will be documented in this file.
- Implement typo checking
- Added in Pull Request [#7](https://github.com/space-code/package-template/pull/7).

## Updated
- Update `post_get_project` script
- Updated in Pull Request[#14](https://github.com/space-code/package-template/pull/14).

#### 1.x Releases
- `1.1.x` Releases - [1.1.0](#110) | [1.1.1](#111)
- `1.0.x` Releases - [1.0.0](#100)
Expand Down
66 changes: 57 additions & 9 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
import os
import shutil
import subprocess

print(os.getcwd())
def print_current_directory():
print(os.getcwd())

def remove(filepath):
if os.path.isfile(filepath):
os.remove(filepath)
elif os.path.isdir(filepath):
shutil.rmtree(filepath)
def rename_copy_remove():
source_directory = "../{{ cookiecutter.name | lower }}"
temp_directory = "../temp"

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

if not create_docc:
remove(os.path.join(os.getcwd(), '.github/workflows', 'deploy_docc.yml'))
except Exception as e:
print(f"An error occurred: {e}")
finally:
shutil.rmtree(os.path.join(os.getcwd(), "temp"))

def remove_file_or_directory(filepath):
if os.path.exists(filepath):
if os.path.isfile(filepath):
os.remove(filepath)
elif os.path.isdir(filepath):
shutil.rmtree(filepath)

def remove_deploy_docc():
filepath = os.path.join(os.getcwd(), '.github/workflows/deploy_docc.yml')
remove_file_or_directory(filepath)

def initialize_swift_library():
project_name = "{{ cookiecutter.name }}"
subprocess.run(["swift", "package", "init", "--name", project_name, "--type", "library"])

def run_make_commands():
subprocess.run(["make", "bootstrap"])
subprocess.run(["make", "fmt"])

def initialize_git_repository():
subprocess.run(["git", "init"])
subprocess.run(["git", "add", "."])
subprocess.run(["git", "commit", "-m", "Initial commit"])

def main():
print_current_directory()

create_docc = '{{ cookiecutter.deploy_docc.lower() }}' == 'yes'

if not create_docc:
remove_deploy_docc()

rename_copy_remove()

initialize_swift_library()

run_make_commands()

initialize_git_repository()

if __name__ == "__main__":
main()
10 changes: 0 additions & 10 deletions hooks/post_gen_project.sh

This file was deleted.

2 changes: 1 addition & 1 deletion {{ cookiecutter.name | lower }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ bootstrap: hook
mint bootstrap

hook:
ln -sf ../../hooks/pre-commit .git/hooks/pre-commit
ln -sf .git/hooks/pre-commit ../../hooks/pre-commit
chmod +x .git/hooks/pre-commit

mint:
Expand Down