-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstartproject.py
107 lines (105 loc) · 3.41 KB
/
startproject.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
105
106
107
import click
import os
import shutil
import subprocess
@click.command()
@click.option("-d", "--delete", is_flag=True, help="Delete existing project files")
@click.option("-dj", "--django", is_flag=True, help="Use django mongodb template")
@click.option("-w", "--wagtail", is_flag=True, help="Use wagtail mongodb template")
@click.argument("project_name", required=False, default="backend")
def startproject(
delete,
django,
wagtail,
project_name,
):
"""Run `startproject` with custom templates."""
if os.path.exists("manage.py"):
click.echo("manage.py already exists")
if not delete:
click.echo("Use -d to delete existing project files")
return
if delete:
items = {
".babelrc": os.path.isfile,
".dockerignore": os.path.isfile,
".browserslistrc": os.path.isfile,
".eslintrc": os.path.isfile,
".nvmrc": os.path.isfile,
".stylelintrc.json": os.path.isfile,
"Dockerfile": os.path.isfile,
"apps": os.path.isdir,
"home": os.path.isdir,
"backend": os.path.isdir,
"db.sqlite3": os.path.isfile,
"frontend": os.path.isdir,
"mongo_migrations": os.path.isdir,
"manage.py": os.path.isfile,
"package-lock.json": os.path.isfile,
"package.json": os.path.isfile,
"postcss.config.js": os.path.isfile,
"requirements.txt": os.path.isfile,
"search": os.path.isdir,
}
for item, check_function in items.items():
if check_function(item):
if os.path.isdir(item):
shutil.rmtree(item)
click.echo(f"Removed directory: {item}")
elif os.path.isfile(item):
os.remove(item)
click.echo(f"Removed file: {item}")
else:
click.echo(f"Skipping: {item} does not exist")
return
template = None
django_admin = "django-admin"
startproject = "startproject"
startapp = "startapp"
if wagtail:
template = os.path.join(os.path.join("src", "wagtail-mongodb-project"))
django_admin = "wagtail"
startproject = "start"
elif django:
template = os.path.join(os.path.join("src", "django-mongodb-project"))
if not template:
template = os.path.join(
os.path.join("src", "django-mongodb-templates", "project_template")
)
click.echo(f"Using template: {template}")
subprocess.run(
[
django_admin,
startproject,
project_name,
".",
"--template",
template,
]
)
frontend_template = os.path.join(
"src", "django-mongodb-templates", "frontend_template"
)
click.echo(f"Using template: {frontend_template}")
subprocess.run(
[
django_admin,
startproject,
"frontend",
".",
"--template",
frontend_template,
]
)
if not wagtail:
home_template = os.path.join("src", "django-mongodb-templates", "home_template")
click.echo(f"Using template: {home_template}")
subprocess.run(
[
django_admin,
startapp,
"home",
"--template",
home_template,
]
)