This repository has been archived by the owner on Jan 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ml.bat
207 lines (166 loc) · 4.32 KB
/
ml.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
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
@echo off
set RUBYFOUND=
for %%e in (%PATHEXT%) do (
for %%X in (ruby%%e) do (
if not defined RUBYFOUND (
set RUBYFOUND=%%~$PATH:X
)
)
)
if not defined RUBYFOUND goto needruby
if "%1"=="self-test" goto selftest
IF not "%1"=="new" goto rubydeployer
SHIFT
IF "%1"=="" goto providename
IF "%1"=="-h" goto usage
IF "%1"=="--help" goto usage
REM check if we are already in a valid Roxy project
if NOT EXIST deploy\lib\ml.rb GOTO skip_roxy_exists
set /p response= "Running ml new from within a Roxy project is not recommended. Continue? [y/N] "
if /i "%response:~,1%" NEQ "Y" exit /b
:skip_roxy_exists
set app_name=%1
SHIFT
set GITFOUND=
for %%e in (%PATHEXT%) do (
for %%X in (git%%e) do (
if not defined GITFOUND (
set GITFOUND=%%~$PATH:X
)
)
)
if not defined GITFOUND goto needgit
set BRANCH=master
set INIT_GIT=0
set APPTYPE=mvc
set FORCE_INSTALL=0
set FORK=marklogic
:loop
if not "%1"=="" (
if "%1"=="--branch" (
set BRANCH=%2
shift
)
if "%1"=="--app-type" (
set APPTYPE=%2
shift
)
if "%1"=="--force" (
set FORCE_INSTALL=1
)
if "%1"=="--fork" (
set FORK=%2
shift
)
shift
goto :loop
)
if "%FORCE_INSTALL%"=="1" GOTO skip_already_exists
if EXIST %app_name% GOTO alreadyexists
:skip_already_exists
if not "%APPTYPE%"=="bare" if not "%APPTYPE%"=="mvc" if not "%APPTYPE%"=="rest" if not "%APPTYPE%"=="hybrid" (
echo Valid values for app-type are bare, mvc, rest and hybrid. Aborting.
exit /b
)
echo.
echo Creating new Application: %app_name%...
REM TODO: check errorlevel and bail out if any of the below commands fail..
if EXIST %app_name% (
cmd /c git clone git://github.com/%FORK%/roxy.git -b %BRANCH% %app_name%.tmp_1
xcopy %app_name%.tmp_1\* %app_name%\ /E
rmdir /s /q %app_name%.tmp_1
)
if NOT EXIST %app_name% (
cmd /c git clone git://github.com/%FORK%/roxy.git -b %BRANCH% %app_name%
)
pushd %app_name%
rmdir /Q /S .git
del /F /Q .gitignore
if not "%APPTYPE%"=="mvc" if not "%APPTYPE%"=="hybrid" (
REM For non-MVC applications, we won't be using the MVC code. Remove it.
rmdir /S /Q src
mkdir src
echo.
echo No initial source code is provided for non-MVC apps. You can capture code from a REST application, or add your own code.
)
for /f "tokens=1-2*" %%a in ("%*") do (
set arg-command=%%a
set arg-appname=%%b
set arg-options=%%c
)
cmd /c ml init %app_name% %arg-options%
popd
echo done
echo.
IF NOT EXIST %app_name% GOTO end
if not "%1"=="--git" goto end
pushd %app_name%
echo Creating a git repository
echo.
cmd /c git init
cmd /c git add .
cmd /c git commit -q -m "Initial Commit"
echo ...done
echo.
popd
goto end
:selftest
if NOT EXIST deploy\test\test_main.rb GOTO missingdeploy
REM Save original env variable value
set ROXY_TEST_SERVER_VERSION_ORG=%ROXY_TEST_SERVER_VERSION%
:loop2
if not "%1"=="" (
REM Look for --server-version param, and export that as env variable. Unit testing doesn't allow cmd params..
if "%1"=="--server-version" (
set ROXY_TEST_SERVER_VERSION=%2
shift
)
shift
goto :loop2
)
ruby -Ideploy -Ideploy\lib -Ideploy\test deploy\test\test_main.rb
REM Restore original env variable value
set ROXY_TEST_SERVER_VERSION=%ROXY_TEST_SERVER_VERSION_ORG%
set ROXY_TEST_SERVER_VERSION_ORG=
goto end
:rubydeployer
if NOT EXIST deploy\lib\ml.rb GOTO missingdeploy
ruby -Ideploy -Ideploy\lib deploy\lib\ml.rb %*
goto end
:missingdeploy
echo.
echo You must run this command inside a valid Roxy Project. Use 'ml new' to create a project.
echo.
goto usage
:needruby
echo.
echo Ruby is required to run the ml scripts.
echo.
goto end
:needgit
echo.
echo Git is required to use the new command.
echo.
goto end
:alreadyexists
echo.
echo %app_name% already exists. Aborting.
echo.
goto end
:providename
echo.
echo "NOTE: Please provide an app name.."
echo.
:usage
echo Usage: ml new app-name --server-version=[version] [--branch=branch] [--git] [--force]
echo.
echo.
echo use --server-version to specify the major version of MarkLogic you will
echo target in your project (4, 5, 6, 7)
echo use --branch to specify the GitHub branch of the Roxy project your project
echo will be based on (master, dev)
echo use --git to automatically configure a git repo
echo use --force to overwrite an existing directory
echo.
goto end
:end