project-initializer 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- project_initializer-1.0.0/PKG-INFO +18 -0
- project_initializer-1.0.0/project_initializer/__init__.py +0 -0
- project_initializer-1.0.0/project_initializer/initilizer.py +191 -0
- project_initializer-1.0.0/project_initializer/utils.py +44 -0
- project_initializer-1.0.0/project_initializer.egg-info/PKG-INFO +18 -0
- project_initializer-1.0.0/project_initializer.egg-info/SOURCES.txt +10 -0
- project_initializer-1.0.0/project_initializer.egg-info/dependency_links.txt +1 -0
- project_initializer-1.0.0/project_initializer.egg-info/entry_points.txt +2 -0
- project_initializer-1.0.0/project_initializer.egg-info/requires.txt +2 -0
- project_initializer-1.0.0/project_initializer.egg-info/top_level.txt +1 -0
- project_initializer-1.0.0/setup.cfg +4 -0
- project_initializer-1.0.0/setup.py +25 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: project-initializer
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Home-page: https://github.com/Soulflys02/web-dev-framework
|
|
5
|
+
Author: Vervloessem Lucas
|
|
6
|
+
Author-email: lucas.vervloessem.atc@gmail.com
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Requires-Dist: questionary
|
|
12
|
+
Requires-Dist: gitpython
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: author-email
|
|
15
|
+
Dynamic: classifier
|
|
16
|
+
Dynamic: home-page
|
|
17
|
+
Dynamic: requires-dist
|
|
18
|
+
Dynamic: requires-python
|
|
File without changes
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import questionary
|
|
2
|
+
from git import Repo
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import subprocess
|
|
6
|
+
from project_initializer.utils import log, RequiredValidator, edit_line_containing, success, error
|
|
7
|
+
|
|
8
|
+
def get_packages(selected_features: list[str]) -> str:
|
|
9
|
+
"""
|
|
10
|
+
Get the list of packages to be installed based on the selected features.
|
|
11
|
+
"""
|
|
12
|
+
# Default packages
|
|
13
|
+
python_packages = [
|
|
14
|
+
"djangorestframework",
|
|
15
|
+
"django",
|
|
16
|
+
"django-cors-headers",
|
|
17
|
+
"python-dotenv",
|
|
18
|
+
]
|
|
19
|
+
react_packages = [
|
|
20
|
+
"react-router",
|
|
21
|
+
"axios",
|
|
22
|
+
"tailwindcss",
|
|
23
|
+
"@tailwindcss/vite",
|
|
24
|
+
]
|
|
25
|
+
# Adding packages based on selected features
|
|
26
|
+
for feature in selected_features:
|
|
27
|
+
match feature:
|
|
28
|
+
case "Authentication":
|
|
29
|
+
python_packages.append("djangorestframework_simplejwt")
|
|
30
|
+
react_packages.append("zustand")
|
|
31
|
+
|
|
32
|
+
return " ".join(python_packages), " ".join(react_packages)
|
|
33
|
+
|
|
34
|
+
def init_project(project_name: str, selected_features: list[str]):
|
|
35
|
+
"""
|
|
36
|
+
Initialize the project with packages for selected features.
|
|
37
|
+
"""
|
|
38
|
+
log("Initializing the project...")
|
|
39
|
+
python_str_packages, react_str_packages = get_packages(selected_features)
|
|
40
|
+
# Django project initialization
|
|
41
|
+
os.makedirs(f"{project_name}/backend")
|
|
42
|
+
subprocess.run(
|
|
43
|
+
f"\
|
|
44
|
+
python -m venv .venv\
|
|
45
|
+
&& source .venv/bin/activate\
|
|
46
|
+
&& pip install --upgrade pip\
|
|
47
|
+
&& pip install {python_str_packages}\
|
|
48
|
+
&& pip freeze > requirements.txt\
|
|
49
|
+
&& django-admin startproject {project_name} .\
|
|
50
|
+
",
|
|
51
|
+
shell=True,
|
|
52
|
+
cwd=f"{project_name}/backend"
|
|
53
|
+
)
|
|
54
|
+
shutil.move("template_repo/backend/utils", f"{project_name}/backend/utils")
|
|
55
|
+
shutil.move("template_repo/backend/.gitignore", f"{project_name}/backend/.gitignore")
|
|
56
|
+
os.remove(f"{project_name}/backend/{project_name}/settings.py")
|
|
57
|
+
os.mkdir(f"{project_name}/backend/{project_name}/settings")
|
|
58
|
+
shutil.move("template_repo/backend/backend/settings/__init__.py", f"{project_name}/backend/{project_name}/settings/__init__.py")
|
|
59
|
+
shutil.move("template_repo/backend/backend/settings/base.py", f"{project_name}/backend/{project_name}/settings/base.py")
|
|
60
|
+
with open(f"{project_name}/backend/.env", "w") as file:
|
|
61
|
+
pass
|
|
62
|
+
with open(f"{project_name}/backend/{project_name}/settings/settings.py", "w") as file:
|
|
63
|
+
file.write("from .base import *\n")
|
|
64
|
+
edit_line_containing(
|
|
65
|
+
f"{project_name}/backend/{project_name}/asgi.py",
|
|
66
|
+
[f"os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"{project_name}.settings\")"],
|
|
67
|
+
[f"os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"{project_name}.settings.settings\")\n"]
|
|
68
|
+
)
|
|
69
|
+
edit_line_containing(
|
|
70
|
+
f"{project_name}/backend/{project_name}/wsgi.py",
|
|
71
|
+
[f"os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"{project_name}.settings\")"],
|
|
72
|
+
[f"os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"{project_name}.settings.settings\")\n"]
|
|
73
|
+
)
|
|
74
|
+
edit_line_containing(
|
|
75
|
+
f"{project_name}/backend/manage.py",
|
|
76
|
+
[f"os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"{project_name}.settings\")"],
|
|
77
|
+
[f" os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"{project_name}.settings.settings\")\n"]
|
|
78
|
+
)
|
|
79
|
+
edit_line_containing(
|
|
80
|
+
f"{project_name}/backend/{project_name}/urls.py",
|
|
81
|
+
["from django.urls import path"],
|
|
82
|
+
["from django.urls import path, include\n"]
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# React project initialization
|
|
86
|
+
os.makedirs(f"{project_name}/frontend")
|
|
87
|
+
subprocess.run(f"\
|
|
88
|
+
yarn create vite . --template react-swc-ts\
|
|
89
|
+
&& yarn add {react_str_packages}\
|
|
90
|
+
",
|
|
91
|
+
shell=True,
|
|
92
|
+
cwd=f"{project_name}/frontend"
|
|
93
|
+
)
|
|
94
|
+
shutil.move("template_repo/frontend/vite.config.ts", f"{project_name}/frontend/vite.config.ts")
|
|
95
|
+
shutil.move("template_repo/frontend/.gitignore", f"{project_name}/frontend/.gitignore")
|
|
96
|
+
shutil.move("template_repo/frontend/.env", f"{project_name}/frontend/.env")
|
|
97
|
+
shutil.move("template_repo/frontend/src/index.css", f"{project_name}/frontend/src/index.css")
|
|
98
|
+
shutil.move("template_repo/frontend/src/main.tsx", f"{project_name}/frontend/src/main.tsx")
|
|
99
|
+
shutil.move("template_repo/frontend/src/PATHS.tsx", f"{project_name}/frontend/src/PATHS.tsx")
|
|
100
|
+
os.mkdir(f"{project_name}/frontend/src/components")
|
|
101
|
+
os.mkdir(f"{project_name}/frontend/src/features")
|
|
102
|
+
os.mkdir(f"{project_name}/frontend/src/hooks")
|
|
103
|
+
shutil.move("template_repo/frontend/src/hooks/useAxios.tsx", f"{project_name}/frontend/src/hooks/useAxios.tsx")
|
|
104
|
+
os.mkdir(f"{project_name}/frontend/src/pages")
|
|
105
|
+
os.mkdir(f"{project_name}/frontend/src/services")
|
|
106
|
+
shutil.move("template_repo/frontend/src/services/backend.tsx", f"{project_name}/frontend/src/services/backend.tsx")
|
|
107
|
+
os.mkdir(f"{project_name}/frontend/src/stores")
|
|
108
|
+
os.mkdir(f"{project_name}/frontend/src/types")
|
|
109
|
+
os.mkdir(f"{project_name}/frontend/src/layouts")
|
|
110
|
+
os.remove(f"{project_name}/frontend/src/assets/react.svg")
|
|
111
|
+
os.remove(f"{project_name}/frontend/src/App.css")
|
|
112
|
+
|
|
113
|
+
success("Project initialized successfully.")
|
|
114
|
+
|
|
115
|
+
def add_features(project_name: str, selected_features: list[str]):
|
|
116
|
+
"""
|
|
117
|
+
Add files based on selected features.
|
|
118
|
+
"""
|
|
119
|
+
SRC_BACKEND_DIR = "template_repo/backend"
|
|
120
|
+
DST_BACKEND_DIR = f"{project_name}/backend"
|
|
121
|
+
SRC_FRONTEND_DIR = "template_repo/frontend/src"
|
|
122
|
+
DST_FRONTEND_DIR = f"{project_name}/frontend/src"
|
|
123
|
+
|
|
124
|
+
for feature in FEATURES:
|
|
125
|
+
# Adding files based on selected features
|
|
126
|
+
if feature in selected_features:
|
|
127
|
+
log(f"Adding {feature} feature...")
|
|
128
|
+
match feature:
|
|
129
|
+
case "Authentication":
|
|
130
|
+
# Backend
|
|
131
|
+
shutil.move(f"{SRC_BACKEND_DIR}/auth", f"{DST_BACKEND_DIR}/auth")
|
|
132
|
+
shutil.move(f"{SRC_BACKEND_DIR}/backend/settings/auth.py", f"{DST_BACKEND_DIR}/{project_name}/settings/auth.py")
|
|
133
|
+
with open(f"{DST_BACKEND_DIR}/{project_name}/settings/settings.py", "a") as file:
|
|
134
|
+
file.write("from .auth import *\n")
|
|
135
|
+
edit_line_containing(
|
|
136
|
+
f"{project_name}/backend/{project_name}/urls.py",
|
|
137
|
+
["]"],
|
|
138
|
+
[" path(\"auth/\", include(\"auth.urls\")),\n]"]
|
|
139
|
+
)
|
|
140
|
+
# Frontend
|
|
141
|
+
shutil.move(f"{SRC_FRONTEND_DIR}/components/Logout.tsx", f"{DST_FRONTEND_DIR}/components/Logout.tsx")
|
|
142
|
+
shutil.move(f"{SRC_FRONTEND_DIR}/components/ProtectedRoute.tsx", f"{DST_FRONTEND_DIR}/components/ProtectedRoute.tsx")
|
|
143
|
+
shutil.move(f"{SRC_FRONTEND_DIR}/features/auth", f"{DST_FRONTEND_DIR}/features/auth")
|
|
144
|
+
shutil.move(f"{SRC_FRONTEND_DIR}/pages/Home.tsx", f"{DST_FRONTEND_DIR}/pages/Home.tsx")
|
|
145
|
+
shutil.move(f"{SRC_FRONTEND_DIR}/pages/Login.tsx", f"{DST_FRONTEND_DIR}/pages/Login.tsx")
|
|
146
|
+
shutil.move(f"{SRC_FRONTEND_DIR}/stores/useUserStore.tsx", f"{DST_FRONTEND_DIR}/stores/useUserStore.tsx")
|
|
147
|
+
shutil.move(f"{SRC_FRONTEND_DIR}/types/User.tsx", f"{DST_FRONTEND_DIR}/types/User.tsx")
|
|
148
|
+
shutil.move(f"{SRC_FRONTEND_DIR}/App.tsx", f"{DST_FRONTEND_DIR}/App.tsx")
|
|
149
|
+
case "API":
|
|
150
|
+
# Backend
|
|
151
|
+
shutil.move(f"{SRC_BACKEND_DIR}/api", f"{DST_BACKEND_DIR}/api")
|
|
152
|
+
shutil.move(f"{SRC_BACKEND_DIR}/backend/settings/api.py", f"{DST_BACKEND_DIR}/{project_name}/settings/api.py")
|
|
153
|
+
with open(f"{DST_BACKEND_DIR}/{project_name}/settings/settings.py", "a") as file:
|
|
154
|
+
file.write("from .api import *\n")
|
|
155
|
+
edit_line_containing(
|
|
156
|
+
f"{project_name}/backend/{project_name}/urls.py",
|
|
157
|
+
["]"],
|
|
158
|
+
[" path(\"api/\", include(\"api.urls\")),\n]"]
|
|
159
|
+
)
|
|
160
|
+
success(f"{feature} feature added successfully.")
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def main():
|
|
165
|
+
global FEATURES
|
|
166
|
+
FEATURES = [
|
|
167
|
+
"Authentication",
|
|
168
|
+
"API",
|
|
169
|
+
]
|
|
170
|
+
|
|
171
|
+
answers = questionary.form(
|
|
172
|
+
project_name = questionary.text("What is the name of your project?", validate=RequiredValidator),
|
|
173
|
+
features = questionary.checkbox("Select the features you want to include in your project:", choices=FEATURES)
|
|
174
|
+
).ask()
|
|
175
|
+
|
|
176
|
+
project_name = answers['project_name']
|
|
177
|
+
selected_features = answers['features']
|
|
178
|
+
|
|
179
|
+
try:
|
|
180
|
+
log("Cloning the repository...")
|
|
181
|
+
Repo.clone_from("https://github.com/Soulflys02/web-dev-framework.git", "template_repo")
|
|
182
|
+
success("Repository cloned successfully.")
|
|
183
|
+
init_project(project_name, selected_features)
|
|
184
|
+
add_features(project_name, selected_features)
|
|
185
|
+
shutil.rmtree("template_repo")
|
|
186
|
+
success("Project setup completed successfully.")
|
|
187
|
+
except Exception as e:
|
|
188
|
+
error(e)
|
|
189
|
+
|
|
190
|
+
if __name__ == "__main__":
|
|
191
|
+
main()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import questionary
|
|
2
|
+
|
|
3
|
+
class RequiredValidator(questionary.Validator):
|
|
4
|
+
def validate(self, document):
|
|
5
|
+
if len(document.text) == 0:
|
|
6
|
+
raise questionary.ValidationError(
|
|
7
|
+
message="Please enter a value.",
|
|
8
|
+
cursor_position=len(document.text)
|
|
9
|
+
)
|
|
10
|
+
return True
|
|
11
|
+
|
|
12
|
+
def log(message):
|
|
13
|
+
questionary.print(f"[INFO] {message}", style="bold fg:yellow")
|
|
14
|
+
|
|
15
|
+
def success(message):
|
|
16
|
+
questionary.print(f"[SUCCESS] {message}", style="bold fg:green")
|
|
17
|
+
|
|
18
|
+
def error(message):
|
|
19
|
+
questionary.print(f"[ERROR] {message}", style="bold fg:red")
|
|
20
|
+
|
|
21
|
+
def edit_line_containing(file_path, lines_to_edit, new_lines=None):
|
|
22
|
+
"""
|
|
23
|
+
Modifies lines in a file containing specific values.
|
|
24
|
+
|
|
25
|
+
:param file_path: Path to the file to be modified.
|
|
26
|
+
:param lines_to_edit: List of values of the lines to be modified.
|
|
27
|
+
"""
|
|
28
|
+
with open(file_path, 'r') as file:
|
|
29
|
+
lines = file.readlines()
|
|
30
|
+
|
|
31
|
+
# Filter the lines to keep
|
|
32
|
+
filtered_lines = []
|
|
33
|
+
for line in lines:
|
|
34
|
+
for i, line_to_edit in enumerate(lines_to_edit):
|
|
35
|
+
if not line_to_edit in line:
|
|
36
|
+
filtered_lines.append(line)
|
|
37
|
+
else:
|
|
38
|
+
if new_lines:
|
|
39
|
+
# Add the new lines in place of the matching line
|
|
40
|
+
filtered_lines.append(new_lines[i])
|
|
41
|
+
|
|
42
|
+
# Rewrite the file with the filtered lines
|
|
43
|
+
with open(file_path, 'w') as file:
|
|
44
|
+
file.writelines(filtered_lines)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: project-initializer
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Home-page: https://github.com/Soulflys02/web-dev-framework
|
|
5
|
+
Author: Vervloessem Lucas
|
|
6
|
+
Author-email: lucas.vervloessem.atc@gmail.com
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Requires-Dist: questionary
|
|
12
|
+
Requires-Dist: gitpython
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: author-email
|
|
15
|
+
Dynamic: classifier
|
|
16
|
+
Dynamic: home-page
|
|
17
|
+
Dynamic: requires-dist
|
|
18
|
+
Dynamic: requires-python
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
setup.py
|
|
2
|
+
project_initializer/__init__.py
|
|
3
|
+
project_initializer/initilizer.py
|
|
4
|
+
project_initializer/utils.py
|
|
5
|
+
project_initializer.egg-info/PKG-INFO
|
|
6
|
+
project_initializer.egg-info/SOURCES.txt
|
|
7
|
+
project_initializer.egg-info/dependency_links.txt
|
|
8
|
+
project_initializer.egg-info/entry_points.txt
|
|
9
|
+
project_initializer.egg-info/requires.txt
|
|
10
|
+
project_initializer.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
project_initializer
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="project-initializer",
|
|
5
|
+
version="1.0.0",
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
install_requires=[
|
|
8
|
+
"questionary",
|
|
9
|
+
"gitpython",
|
|
10
|
+
],
|
|
11
|
+
entry_points={
|
|
12
|
+
"console_scripts": [
|
|
13
|
+
"init-project=project_initializer.initilizer:main",
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
url="https://github.com/Soulflys02/web-dev-framework",
|
|
17
|
+
author="Vervloessem Lucas",
|
|
18
|
+
author_email="lucas.vervloessem.atc@gmail.com",
|
|
19
|
+
classifiers=[
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
],
|
|
24
|
+
python_requires=">=3.7",
|
|
25
|
+
)
|