-
Notifications
You must be signed in to change notification settings - Fork 23
/
start.bat
75 lines (60 loc) · 2.17 KB
/
start.bat
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
@echo off
:initArgs
:: asks for the -foo argument and store the value in the variables
:: ./start.bat [ -port port ] [ -host http://host.url ] [ -bot botfoldername ] [ -env dev|quali|prod ] [ -cred passphrase ] [ -ui nodereduiroute]
call:getArgWithValue "-port" "PORT" "%~1" "%~2" && shift && shift && goto :initArgs
call:getArgWithValue "-host" "HOST" "%~1" "%~2" && shift && shift && goto :initArgs
call:getArgWithValue "-bot" "BOT" "%~1" "%~2" && shift && shift && goto :initArgs
call:getArgWithValue "-env" "NODE_ENV" "%~1" "%~2" && shift && shift && goto :initArgs
call:getArgWithValue "-cred" "CREDENTIAL_SECRET" "%~1" "%~2" && shift && shift && goto :initArgs
call:getArgWithValue "-ui" "NODE_RED_ROUTE" "%~1" "%~2" && shift && shift && goto :initArgs
:: Project paths
SET FRAMEWORK_ROOT=%~dp0
CD ..
SET ROOT_DIR=%~dp0
:: Project default settings
if "%PORT%" == "" SET PORT=1880
if "%HOST%" == "" SET HOST=http://127.0.0.1
if "%NODE_ENV%" == "" SET NODE_ENV=dev
if "%BOT%" == "" (
@echo Warning - No bot specified
SET BOT_ROOT="."
SET CONFIG_PATH="."
) else (
SET BOT_ROOT=%ROOT_DIR%projects\%BOT%
SET CONFIG_PATH=%ROOT_DIR%projects\%BOT%\conf\config.js
)
SET ENABLE_PROJECTS=true
SET NODE_RED_DISABLE_EDITOR=false
:: Project configs
IF "%NODE_RED%" == "" SET NODE_RED=%FRAMEWORK_ROOT%node_modules\node-red\red.js
IF "%NODE_RED_CONFIG%" == "" SET NODE_RED_CONFIG=%FRAMEWORK_ROOT%conf\node-red-config.js
:: Required to fix SSL issues
SET NODE_TLS_REJECT_UNAUTHORIZED=0
:: MUST start in the project folder
@echo Starting Node-RED
CD %BOT_ROOT%
node "%NODE_RED%" -s "%NODE_RED_CONFIG%"
EXIT /B 0
goto:eof
:: =====================================================================
:: This function sets a variable from a cli arg with value
:: 1 cli argument name
:: 2 variable name
:: 3 current Argument Name
:: 4 current Argument Value
:getArgWithValue
if "%~3"=="%~1" (
if "%~4"=="" (
REM unset the variable if value is not provided
set "%~2="
exit /B 1
)
set "%~2=%~4"
exit /B 0
)
exit /B 1
goto:eof
:helper
@echo "Error - usage : ./start.bat -bot [ botfoldername ] [ -port port ] [ -host http://host.url ] [ -env dev|quali|prod ] [ -cred passphrase ]"
:END