forked from flojoy-ai/studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflojoy.ps1
293 lines (252 loc) · 8.18 KB
/
flojoy.ps1
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass
# Run all services required by Flojoy Studio
$success_color = 'Green'
$warning_color = 'Yellow'
$error_color = 'Red'
$info_color = 'Cyan'
$general_color = 'Magenta'
$info_mark = '👉'
$check_mark = '✔'
$alert_mark = '⚠️'
$error_mark = '❌'
function success_msg {
param (
$message
)
Write-Host "$check_mark $message " -ForegroundColor $success_color
Write-Host ""
}
function info_msg {
param (
$message
)
Write-Host "$info_mark $message " -ForegroundColor $info_color
Write-Host ""
}
function warning_msg {
param (
$message
)
Write-Host "$alert_mark $message " -ForegroundColor $warning_color
Write-Host ""
}
function error_msg {
param (
$message
)
Write-Host "$error_mark $message " -ForegroundColor $error_color
Write-Host ""
Write-Host ""
}
Write-Host ""
Write-Host ""
Write-Host " ===============================================================" -ForegroundColor $general_color
Write-Host " || Welcome to Flojoy! ||" -ForegroundColor $general_color
Write-Host " || ||" -ForegroundColor $general_color
Write-Host " || For Installation, Follow the Link Below ||" -ForegroundColor $general_color
Write-Host " || https://docs.flojoy.io/getting-started/install/ ||" -ForegroundColor $general_color
Write-Host " || ||" -ForegroundColor $general_color
Write-Host " ===============================================================" -ForegroundColor $general_color
Write-Host ""
$initNodePackages = $true
$initPythonPackages = $true
$initSubmodule = $true
$enableSentry = $true
$enableTelemetry = $false
$isDebugMode = $false
# Gives Feedback if the command run is successful or failed, if failed it exits the execution.
function feedback {
param (
$is_successful,
$message,
$help_message
)
if ($is_successful -eq $true) {
success_msg $message
}
else {
error_msg $help_message
exit
}
}
# Help function
function helpFunction {
Write-Host ""
Write-Host "Usage: $0 -n -p -s -S -T -v venv -d"
Write-Host " -n: To NOT install npm packages"
Write-Host " -p: To NOT install python packages"
Write-Host " -s: To NOT update submodules"
Write-Host " -S: To NOT enable Sentry"
Write-Host " -T: To enable Telemetry"
Write-Host " -v: To use virtual env"
Write-Host " -d: To enable debug mode"
}
# Assign command-line arguments to a variable
$arguments = $args
# Parse command-line arguments
$index = 0
while ($arguments) {
$key = $arguments[$index]
if ($index -eq $arguments.Length) {
break
}
if ($key -ceq "-n") {
$initNodePackages = $false
$index = $index + 1
continue
}
elseif ($key -ceq "-p") {
$initPythonPackages = $false
$index = $index + 1
continue
}
elseif ($key -ceq "-S") {
$enableSentry = $false
$index = $index + 1
continue
}
elseif ($key -ceq "-s") {
$initSubmodule = $false
$index = $index + 1
continue
}
elseif ($key -ceq "-T") {
$enableTelemetry = $true
$index = $index + 1
continue
}
elseif ($key -ceq "-d") {
$isDebugMode = $true
$index = $index + 1
continue
}
elseif ($key -ceq "-v") {
$venvPath = $arguments[$index + 1]
$index = $index + 2
continue
}
else {
Write-Host "Unknown option: $key"
helpFunction
exit 1
}
}
$CWD = $PWD
function createFlojoyDirectoryWithYmlFile {
$FOLDER = "$HOME/.flojoy"
$FILE = "$HOME/.flojoy/flojoy.yaml"
if (Test-Path $FOLDER) {
if (Test-Path $FILE) {
info_msg "$FILE exists."
Set-Content $FILE "PATH: $CWD"
feedback $? "Updated file path in flojoy.yaml file." "Couldn't update file path in flojoy.yaml file, check the permission or sign in as root user"
}
else {
info_msg "file flojoy.yaml in directory $FOLDER does not exist."
New-Item $FILE -ItemType File | Out-Null
Set-Content $FILE "PATH: $CWD"
feedback $? "Successfully created flojoy.yaml file in $FOLDER directory." "Couldn't create flojoy.yaml file in $FOLDER directory, check the permission or sign in as root user"
}
}
else {
info_msg "directory ~/.flojoy/flojoy.yaml does not exist."
New-Item -ItemType Directory $FOLDER | Out-Null
New-Item $FILE -ItemType File | Out-Null
Set-Content $FILE "PATH: $CWD"
feedback $? "Created new $FOLDER directory with flojoy.yaml file." "Failed to create file in the home directory, check the permission or sign in as root user"
}
$CREDENTIALS_FILE = "$FOLDER/credentials"
if (-not (Test-Path $CREDENTIALS_FILE)) {
warning_msg " Warning: Credentials are not set for your project! You can set credentials by creating a file named 'credentials' in the directory '~/.flojoy' and adding your credentials to the file."
}
else {
$FRONTIER_API_KEY_PATTERN = "FRONTIER_API_KEY:"
$FRONTIER_API_KEY = Select-String $CREDENTIALS_FILE -Pattern $FRONTIER_API_KEY_PATTERN -Quiet
if (-not $FRONTIER_API_KEY) {
warning_msg " Warning: Frontier API key not set for your project! To set Frontier API key, simply follow this pattern in the '~/.flojoy/credentials' file: FRONTIER_API_KEY:<your key>"
}
}
}
createFlojoyDirectoryWithYmlFile
if ($venvPath) {
info_msg "Venv path is given, will use: $venvPath"
& $venvPath\Scripts\activate
}
if ($initSubmodule -eq $true) {
# Update submodules
& git submodule update --init --recursive > $null
feedback $? 'Updated submodules successfully' 'Failed to update submodules, check if git is installed correctly and configured with your github account.'
}
# Check if Python, Pip, or npm is missing.
. ./check-dependencies.ps1
# Call the function to check for dependencies
$missing_dependencies = check_dependencies
# If there are missing dependencies, print the list of them
if ($missing_dependencies) {
error_msg "$missing_dependencies"
exit 1
}
function check_and_install_py_pckg() {
param (
$pckg_name,
$pip_cmd
)
& pip show $pckg_name 2>$1 > $null
$is_installed = $LastExitCode
if ($is_installed -ne 0) {
$install_cmd = "python -m $pip_cmd install $pckg_name"
Invoke-Expression $install_cmd 2>$1 | Out-Null
}
}
# Install Python packages
if ($initPythonPackages) {
info_msg "Flag -p is not provided, Python packages will be installed from requirements.txt file"
Set-Location $CWD
check_and_install_py_pckg "pipwin" "pip"
check_and_install_py_pckg "matplotlib==3.5.2" "pipwin"
$pip_cmd = "python -m pip install -r requirements.txt"
Invoke-Expression $pip_cmd
feedback $? 'Python packages installed successfully!' "Python package installation failed! check error details printed above."
}
# Install Node packages
if ($initNodePackages) {
info_msg "Argument -n is not provided, Node packages will be installed from package.json"
& npm install
feedback $? 'Installed Node packages successfully.' 'Node packages installation failed! check error details printed above.'
}
# jsonify python functions
& python .\scripts\write_python_metadata.py
feedback $? 'Jsonified Python functions and written to JS-readable directory' 'Error occurred while Jsonifying Python functions. Check errors printed above!'
# Generate Manifest
& python .\PYTHON\generate_manifest.py
feedback $? 'Successfully generated manifest for Python nodes to frontend' 'Failed to generate manifest for Python nodes. Check errors printed above!'
# Setup Sentry env var
if ( $enableSentry -eq $true ) {
info_msg "Sentry will be enabled!"
$Env:FLOJOY_ENABLE_SENTRY = 1
}
else {
info_msg "Sentry will be disabled!"
$Env:FLOJOY_ENABLE_SENTRY = 0
}
# Setup Telemetry
if ( $enableTelemetry -eq $true ) {
info_msg "Telemetry will be enabled!"
$Env:FLOJOY_ENABLE_TELEMETRY = 1
}
else {
info_msg "Telemetry will be disabled!"
$Env:FLOJOY_ENABLE_TELEMETRY = 0
}
# Start the project
info_msg 'Starting the project...'
if ($isDebugMode -eq $true) {
info_msg "Debug mode will be enabled!"
$Env:DEBUG = $true
$startProjectCmd = "npm run start-project:win:debug"
}
else {
$Env:DEBUG = $false
$startProjectCmd = "npm run start-project:win"
}
Invoke-Expression $startProjectCmd