-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
104 lines (77 loc) · 2.71 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import typer
from rich import print
from rich.table import Table
from enum import StrEnum
import subprocess
import shutil
import pathlib
import os
class Library(StrEnum):
FASTAPI = "fastapi"
NEXTJS = "nextjs"
EXPRESS = "express" # ! To be implemented
NESTJS = "nestjs" # ! To be implemented
def get_path():
return pathlib.Path(__file__).resolve()
def get_this_dir():
return get_path().parent
def get_library_init_command(library: Library, project_name: str):
if library == Library.FASTAPI:
return ["poetry", "new", "--src", f"{project_name}"]
return []
def get_install_deps_commands(library: Library):
dependencies = []
if library == Library.FASTAPI:
dependencies = [
"fastapi",
"gunicorn",
'uvicorn',
"sqlalchemy",
"pydantic-settings",
"psycopg2",
"psycopg2-binary",
"bcrypt",
"cryptography"]
return [(dep, ["poetry", "add", f"{dep}"]) for dep in dependencies]
return []
def get_dockerfile(library: Library):
dockerfile = get_this_dir() / library / "Dockerfile"
dockerignore = get_this_dir() / library / ".dockerignore"
return [dockerfile, dockerignore]
app = typer.Typer()
@app.command()
def create(
library: Library,
project_name: str,
dockerfile: bool = True, # ! To be implemented
src: bool = True,
poetry: bool = True, # ! To be implemented
latest: bool = True, # ! To be implemented
):
cmd = get_library_init_command(library=library, project_name=project_name)
if len(cmd) == 0:
print(f"[bold red]Error! Library {library} not implemented yet![/bold red] :boom:")
raise typer.Exit(code=1)
print(f"[bold green]Creating new project[bold green]")
table = Table("Project Name", "Library")
table.add_row(project_name, library)
print(table)
subprocess.run(cmd)
for dockerfile in get_dockerfile(library=library):
shutil.copy2(dockerfile, f"./{project_name}")
if library == Library.FASTAPI:
shutil.copytree(get_this_dir() / library / "src", f"./{project_name}/src", dirs_exist_ok=True)
shutil.copy2(get_this_dir() / library / "server.py", f"./{project_name}")
os.chdir(get_this_dir() / project_name)
for install_dep in get_install_deps_commands(library=library):
dep, install_cmd = install_dep
print(f"[bold green]Installing {dep}[bold green]")
subprocess.run(install_cmd)
print(f"[bold green]Success! Project created[bold green] :boom:")
print(f" cd {project_name}")
print(f" python src/main.py")
@app.command()
def delete(name: str, formal: bool = False):
pass
if __name__ == "__main__":
app()