forked from Ortus-Solutions/commandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
box-cli.bat
139 lines (138 loc) · 3.81 KB
/
box-cli.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
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
@echo off
set CFDISTRO_HOME=%userprofile%\cfdistro
set FILE_URL="http://cfmlprojects.org/artifacts/cfdistro/latest/cfdistro.zip"
set FILE_DEST=%CFDISTRO_HOME%\cfdistro.zip
set buildfile=build/build.xml
set ANT_HOME=%CFDISTRO_HOME%\ant
set ANT_CMD=%CFDISTRO_HOME%\ant\bin\ant.bat
if not exist "%CFDISTRO_HOME%" (
mkdir "%CFDISTRO_HOME%"
)
REM if build file does not exist
if not exist "%CFDISTRO_HOME%\build.xml" (
REM Try to download cfdistro file
if not exist "%FILE_DEST%" (
echo Downloading with powershell: %FILE_URL% to %FILE_DEST%
powershell.exe -command "$webclient = New-Object System.Net.WebClient; $url = \"%FILE_URL%\"; $file = \"%FILE_DEST%\"; $webclient.DownloadFile($url,$file);"
REM if error encountered, try another method to download
REM using file existance check as errorlevel does not get reset properly
if not exist "%FILE_DEST%" (
echo Powershell download failed. Trying with ActiveXObject
cscript /nologo build/resource/wget.js %FILE_URL% %FILE_DEST%
if not exist "%FILE_DEST%" (
echo 2nd Download attempt failed.
echo Try to manually download from %FILE_URL%
echo and expand in %FILE_DEST%
EXIT /B
) else (
echo Download successful
)
)
)
)
REM if build file does not exist
if not exist "%CFDISTRO_HOME%\build.xml" (
if exist "%FILE_DEST%" (
echo Expanding with powershell to: %CFDISTRO_HOME%
powershell -command "$shell_app=new-object -com shell.application; $zip_file = $shell_app.namespace(\"%FILE_DEST%\"); $destination = $shell_app.namespace(\"%CFDISTRO_HOME%\"); $destination.Copyhere($zip_file.items())"
REM remove zip file
del %FILE_DEST%
)
)
REM must have build file for remainder of file, so check it exists
if not exist "%CFDISTRO_HOME%\build.xml" (
echo Build file does not exist at %CFDISTRO_HOME%\build.xml
echo Exiting.
EXIT /B
)
if "%1" == "" goto MENU
set args=%1
SHIFT
:Loop
IF "%1" == "" GOTO Continue
SET args=%args% -D%1%
SHIFT
IF "%1" == "" GOTO Continue
SET args=%args%=%1%
SHIFT
GOTO Loop
:Continue
if not exist %buildfile% (
set buildfile="%CFDISTRO_HOME%\build.xml"
)
call "%ANT_CMD%" -nouserlib -f %buildfile% %args%
goto end
:MENU
cls
echo.
echo box-cli menu
REM echo usage: box-cli.bat [start|stop|{target}]
echo.
echo 0. Build
echo 1. Start server and open browser
echo 2. Stop server
echo 3. List available targets
echo 4. Update project
echo 5. Run Target
echo 6. Quit
echo.
set choice=
set /p choice= Enter option 0, 1, 2, 3, 4, 5 or 6 :
echo.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='0' goto build
if '%choice%'=='1' goto startServer
if '%choice%'=='2' goto stopServer
if '%choice%'=='3' goto listTargets
if '%choice%'=='4' goto updateProject
if '%choice%'=='5' goto runTarget
if '%choice%'=='6' goto end
::
echo.
echo.
echo "%choice%" is not a valid option - try again
echo.
pause
goto MENU
::
:startServer
cls
call "%ANT_CMD%" -nouserlib -f %buildfile% build.start.launch
echo to stop the server, run this again or run: box-cli.bat stop
goto end
::
:stopServer
call "%ANT_CMD%" -nouserlib -f %buildfile% server.stop
goto end
::
:listTargets
call "%ANT_CMD%" -nouserlib -f %buildfile% help
echo press any key ...
pause > nul
goto MENU
::
:build
call "%ANT_CMD%" -nouserlib -f %buildfile% build
echo press any key ...
pause > nul
goto MENU
::
:updateProject
call "%ANT_CMD%" -nouserlib -f %buildfile% project.update
echo press any key ...
pause > nul
goto MENU
::
:runTarget
set target=
set /p target= Enter target name:
if not "%target%"=="" call %0 %target%
echo press any key ...
pause > nul
goto MENU
::
:end
set choice=
echo press any key ...
pause
REM EXIT