11import os
22import 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 ()
0 commit comments