-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive.py
More file actions
160 lines (133 loc) · 4.59 KB
/
interactive.py
File metadata and controls
160 lines (133 loc) · 4.59 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import os
import subprocess
import time
from InquirerPy import inquirer
import src.print as print
import src.initialize as initialize
class Calls:
def __init__(self):
self.cwd = os.getcwd()
def projectName(self):
projectName = inquirer.text(
message="Enter a project name (e.g; pyder-project)\n >",
).execute()
if projectName == "":
print.error("Project name cannot be empty.")
exit()
# check if `projectName` has spaces, special characters and/or caps
if " " in projectName or not projectName.isalnum() or not projectName.islower():
# convert:
# - spaces -> dashes
# - remove special characters
# - lowercase everything
projectID = "".join(
c.lower() if c.isalnum() else "-" if c == " " else ""
for c in projectName
).strip("-")
print.log(f"`{projectName}` has been converted to `{projectID}` for projectID.")
else:
projectID = projectName
return projectName, projectID
def domainSystem(self):
domainSystem = inquirer.text(
message="Enter a domain system (e.g; io.github.pinpointtools)\n >",
).execute()
if domainSystem == "":
print.error("Domain system cannot be empty.")
exit()
return domainSystem
def qtorgtk(self):
qtorgtk = inquirer.select(
message="For Linux, do you want to use Qt or GTK?",
choices=[
"GTK",
"Qt",
],
).execute()
return qtorgtk
def framework(self):
framework = inquirer.select(
message="Select a framework",
choices=[
"Vanilla",
"Svelte",
"React",
"Vue",
],
).execute()
return framework
def variant(self):
variant = inquirer.select(
message="Select a variant",
choices=[
"JavaScript",
"TypeScript"
],
).execute()
return variant
def packageManager(self):
packageManager = inquirer.select(
message="Select a package manager",
choices=[
"npm",
"pnpm",
],
).execute()
return packageManager
class Checks:
def __init__(self):
pass
def npm(self):
try:
subprocess.run(["npm", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print.success("npm is installed.")
return True
except subprocess.CalledProcessError:
print.error("npm is not installed.")
return False
def pnpm(self):
try:
subprocess.run(["pnpm", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print.success("pnpm is installed.")
return True
except subprocess.CalledProcessError:
print.error("pnpm is not installed.")
return False
def python(self):
try:
subprocess.run(["python", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print.success("Python is installed.")
return True
except subprocess.CalledProcessError:
print.error("Python is not installed.")
return False
def inOrder():
calls = Calls()
projectName, projectID = calls.projectName()
domainSystem = calls.domainSystem()
qtorgtk = calls.qtorgtk()
framework = calls.framework()
variant = calls.variant()
packageManager = calls.packageManager()
return projectName, projectID, domainSystem, qtorgtk, framework, variant, packageManager
def check(packageManager):
check = Checks()
# package manager
if packageManager == "npm":
check.npm()
elif packageManager == "pnpm":
check.pnpm()
# python
check.python()
def start():
projectName, projectID, domainSystem, qtorgtk, framework, variant, packageManager = inOrder()
print.empty()
check(packageManager)
print.empty()
_continue = inquirer.confirm(
message=f"Continue with {framework}? This will start {packageManager}.",
).execute()
if _continue:
initialize.start(projectName, projectID, domainSystem, qtorgtk, framework, variant, packageManager)
else:
print.log("Pyder selection cancelled.")