Skip to content

Commit 5efb213

Browse files
committed
test
1 parent a0da012 commit 5efb213

2 files changed

Lines changed: 389 additions & 2 deletions

File tree

_build.new.bat

Lines changed: 387 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,387 @@
1+
@ECHO OFF
2+
setlocal enabledelayedexpansion
3+
4+
SET "dlurl=https://github.com/HL7/fhir-ig-publisher/releases/latest/download/publisher.jar"
5+
SET "publisher_jar=publisher.jar"
6+
SET "input_cache_path=%CD%\input-cache\"
7+
SET "skipPrompts=false"
8+
SET "upper_path=..\"
9+
SET "scriptdlroot=https://raw.githubusercontent.com/HL7/ig-publisher-scripts/main"
10+
SET "build_bat_url=%scriptdlroot%/_build.bat"
11+
SET "build_sh_url=%scriptdlroot%/_build.sh"
12+
13+
14+
15+
:: Debugging statements to check jar file location
16+
ECHO Checking for publisher.jar in %input_cache_path%
17+
IF EXIST "%input_cache_path%%publisher_jar%" (
18+
SET "jar_location=%input_cache_path%%publisher_jar%"
19+
ECHO Found publisher.jar in input-cache
20+
) ELSE (
21+
ECHO Checking for publisher.jar in %upper_path%
22+
IF EXIST "%upper_path%%publisher_jar%" (
23+
SET "jar_location=%upper_path%%publisher_jar%"
24+
ECHO Found publisher.jar in parent folder
25+
) ELSE (
26+
SET "jar_location=not_found"
27+
SET "default_choice=1"
28+
SET "default_reason=publisher not found"
29+
ECHO publisher.jar not found in input-cache or parent folder
30+
)
31+
)
32+
33+
34+
:: Handle command-line argument to bypass the menu
35+
:: Known first arguments select a menu option; anything else is passed through to the publisher
36+
SET "extraArgs="
37+
IF "%~1"=="" GOTO showMenu
38+
IF /I "%~1"=="update" SET "userChoice=1" & GOTO parseExtra
39+
IF /I "%~1"=="build" SET "userChoice=2" & GOTO parseExtra
40+
IF /I "%~1"=="nosushi" SET "userChoice=3" & GOTO parseExtra
41+
IF /I "%~1"=="notx" SET "userChoice=4" & GOTO parseExtra
42+
IF /I "%~1"=="jekyll" SET "userChoice=5" & GOTO parseExtra
43+
IF /I "%~1"=="clean" SET "userChoice=6" & GOTO parseExtra
44+
IF /I "%~1"=="exit" SET "userChoice=0" & GOTO parseExtra
45+
:: Unknown first arg - default to build, pass all args through
46+
SET "userChoice=2"
47+
GOTO collectArgs
48+
:parseExtra
49+
SHIFT
50+
:collectArgs
51+
IF "%~1"=="" GOTO executeChoice
52+
SET "extraArgs=!extraArgs! %1"
53+
SHIFT
54+
GOTO collectArgs
55+
:showMenu
56+
57+
echo ---------------------------------------------------------------
58+
ECHO Checking internet connection...
59+
powershell -Command "try { $r=[System.Net.WebRequest]::Create('https://tx.fhir.org/r4/metadata'); $r.Timeout=4000; $r.GetResponse().Close(); exit 0 } catch { exit 1 }"
60+
IF %ERRORLEVEL% EQU 0 (SET "online_status=true") ELSE (SET "online_status=false")
61+
62+
IF "%online_status%"=="true" (
63+
ECHO We are online and tx.fhir.org is available.
64+
FOR /F "tokens=2 delims=:" %%a IN ('curl -s https://api.github.com/repos/HL7/fhir-ig-publisher/releases/latest ^| findstr "tag_name"') DO SET "latest_version=%%a"
65+
SET "latest_version=!latest_version:"=!"
66+
SET "latest_version=!latest_version: =!"
67+
SET "latest_version=!latest_version:~0,-1!"
68+
) ELSE (
69+
ECHO.
70+
ECHO *** WARNING: Working offline - this is not the normal mode.
71+
ECHO Some features including terminology rendering will not work.
72+
ECHO.
73+
SET "txoption=-tx n/a"
74+
SET "latest_version=unknown"
75+
SET "default_choice=4"
76+
SET "default_reason=working offline"
77+
)
78+
79+
echo ---------------------------------------------------------------
80+
81+
82+
IF NOT "%jar_location%"=="not_found" (
83+
FOR /F "tokens=*" %%i IN ('java "-Dfile.encoding=UTF-8" -jar "%jar_location%" -v 2^>^&1') DO SET "publisher_version=%%i"
84+
SET "publisher_version=!publisher_version:"=!"
85+
ECHO Detected publisher version: !publisher_version!
86+
) ELSE (
87+
SET "publisher_version=unknown"
88+
ECHO publisher.jar location is not found
89+
)
90+
91+
ECHO Publisher version: !publisher_version!; Latest is !latest_version!
92+
93+
IF NOT "%online_status%"=="true" (
94+
ECHO We are offline.
95+
) ELSE (
96+
IF NOT "!publisher_version!"=="!latest_version!" (
97+
ECHO An update is recommended.
98+
SET "default_choice=1"
99+
SET "default_reason=newer version available"
100+
) ELSE (
101+
ECHO Publisher is up to date.
102+
SET "default_choice=2"
103+
SET "default_reason=publisher is up to date"
104+
)
105+
)
106+
107+
echo ---------------------------------------------------------------
108+
echo.
109+
110+
echo Please select an option:
111+
echo 1. Download or update publisher
112+
echo 2. Build IG
113+
echo 3. Build IG - no sushi
114+
echo 4. Build IG - force no TX server
115+
echo 5. Jekyll build
116+
echo 6. Clean up temp directories
117+
echo 0. Exit
118+
echo.
119+
120+
choice /C 12345670 /N /CS /D %default_choice% /T 5 /M "Choose an option number or wait 5 seconds for default (%default_choice% - %default_reason%):"
121+
SET "userChoice=%ERRORLEVEL%"
122+
123+
124+
:executeChoice
125+
echo You selected: %userChoice%
126+
127+
IF "%userChoice%"=="1" GOTO downloadpublisher
128+
IF "%userChoice%"=="2" GOTO publish_once
129+
IF "%userChoice%"=="3" GOTO publish_nosushi
130+
IF "%userChoice%"=="4" GOTO publish_notx
131+
IF "%userChoice%"=="5" GOTO debugjekyll
132+
IF "%userChoice%"=="6" GOTO clean
133+
IF "%userChoice%"=="0" EXIT /B
134+
GOTO endscript
135+
136+
:debugjekyll
137+
echo Running Jekyll build...
138+
jekyll build -s temp/pages -d output
139+
GOTO endscript
140+
141+
142+
:clean
143+
echo Cleaning up directories...
144+
if exist ".\input-cache\publisher.jar" (
145+
echo Preserving publisher.jar and removing other files in .\input-cache...
146+
move ".\input-cache\publisher.jar" ".\"
147+
rmdir /s /q ".\input-cache"
148+
mkdir ".\input-cache"
149+
move ".\publisher.jar" ".\input-cache"
150+
) else (
151+
if exist ".\input-cache\" (
152+
rmdir /s /q ".\input-cache"
153+
)
154+
)
155+
if exist ".\temp\" (
156+
rmdir /s /q ".\temp"
157+
echo Removed: .\temp
158+
)
159+
if exist ".\output\" (
160+
rmdir /s /q ".\output"
161+
echo Removed: .\output
162+
)
163+
if exist ".\template\" (
164+
rmdir /s /q ".\template"
165+
echo Removed: .\template
166+
)
167+
168+
GOTO endscript
169+
170+
171+
:downloadpublisher
172+
ECHO Downloading Publisher...
173+
:processflags
174+
SET ARG=%1
175+
IF DEFINED ARG (
176+
IF "%ARG%"=="-f" SET FORCE=true
177+
IF "%ARG%"=="--force" SET FORCE=true
178+
SHIFT
179+
GOTO processflags
180+
)
181+
182+
FOR %%x IN ("%CD%") DO SET upper_path=%%~dpx
183+
184+
ECHO.
185+
IF NOT EXIST "%input_cache_path%%publisher_jar%" (
186+
IF NOT EXIST "%upper_path%%publisher_jar%" (
187+
SET jarlocation="%input_cache_path%%publisher_jar%"
188+
SET jarlocationname=Input Cache
189+
ECHO IG Publisher is not yet in input-cache or parent folder.
190+
REM we don't use jarlocation below because it will be empty because we're in a bracketed if statement
191+
GOTO create
192+
) ELSE (
193+
ECHO IG Publisher FOUND in parent folder
194+
SET jarlocation="%upper_path%%publisher_jar%"
195+
SET jarlocationname=Parent folder
196+
GOTO upgrade
197+
)
198+
) ELSE (
199+
ECHO IG Publisher FOUND in input-cache
200+
SET jarlocation="%input_cache_path%%publisher_jar%"
201+
SET jarlocationname=Input Cache
202+
GOTO upgrade
203+
)
204+
205+
:create
206+
IF DEFINED FORCE (
207+
MKDIR "%input_cache_path%" 2> NUL
208+
GOTO download
209+
)
210+
211+
IF "%skipPrompts%"=="true" (
212+
SET create=Y
213+
) ELSE (
214+
SET /p create="Download? (Y/N) "
215+
)
216+
IF /I "%create%"=="Y" (
217+
ECHO Will place publisher jar here: %input_cache_path%%publisher_jar%
218+
MKDIR "%input_cache_path%" 2> NUL
219+
GOTO download
220+
)
221+
GOTO done
222+
223+
:upgrade
224+
IF "%skipPrompts%"=="true" (
225+
SET overwrite=Y
226+
) ELSE (
227+
SET /p overwrite="Overwrite %jarlocation%? (Y/N) "
228+
)
229+
230+
IF /I "%overwrite%"=="Y" (
231+
GOTO download
232+
)
233+
GOTO done
234+
235+
:download
236+
ECHO Downloading most recent publisher to %jarlocationname% - it's ~200 MB, so this may take a bit
237+
238+
FOR /f "tokens=4-5 delims=. " %%i IN ('ver') DO SET VERSION=%%i.%%j
239+
IF "%version%" == "10.0" GOTO win10
240+
IF "%version%" == "6.3" GOTO win8.1
241+
IF "%version%" == "6.2" GOTO win8
242+
IF "%version%" == "6.1" GOTO win7
243+
IF "%version%" == "6.0" GOTO vista
244+
245+
ECHO Unrecognized version: %version%
246+
GOTO done
247+
248+
:win10
249+
CALL POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%dlurl%\",\"%jarlocation%\") } else { Invoke-WebRequest -Uri "%dlurl%" -Outfile "%jarlocation%" }
250+
251+
GOTO done
252+
253+
:win7
254+
rem this may be triggering the antivirus - bitsadmin.exe is a known threat
255+
rem CALL bitsadmin /transfer GetPublisher /download /priority normal "%dlurl%" "%jarlocation%"
256+
257+
rem this didn't work in win 10
258+
rem CALL Start-BitsTransfer /priority normal "%dlurl%" "%jarlocation%"
259+
260+
rem this should work - untested
261+
call (New-Object Net.WebClient).DownloadFile('%dlurl%', '%jarlocation%')
262+
GOTO done
263+
264+
:win8.1
265+
:win8
266+
:vista
267+
GOTO done
268+
269+
270+
271+
:done
272+
273+
274+
275+
276+
ECHO.
277+
ECHO Updating scripts
278+
IF "%skipPrompts%"=="true" (
279+
SET updateScripts=Y
280+
) ELSE (
281+
SET /p updateScripts="Update scripts? (Y/N) "
282+
)
283+
IF /I "%updateScripts%"=="Y" (
284+
GOTO scripts
285+
)
286+
GOTO endscript
287+
288+
289+
:scripts
290+
291+
REM Download all batch files (and this one with a new name)
292+
293+
SETLOCAL DisableDelayedExpansion
294+
295+
296+
297+
:dl_script_1
298+
ECHO Updating _build.sh
299+
call POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%build_sh_url%\",\"_build.new.sh\") } else { Invoke-WebRequest -Uri "%build_sh_url%" -Outfile "_build.new.sh" }
300+
if %ERRORLEVEL% == 0 goto upd_script_1
301+
echo "Errors encountered during download: %errorlevel%"
302+
goto dl_script_2
303+
:upd_script_1
304+
start copy /y "_build.new.sh" "_build.sh" ^&^& del "_build.new.sh" ^&^& exit
305+
306+
307+
:dl_script_2
308+
ECHO Updating _build.bat
309+
call POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%build_bat_url%\",\"_build.new.bat\") } else { Invoke-WebRequest -Uri "%build_bat_url%" -Outfile "_build.new.bat" }
310+
if %ERRORLEVEL% == 0 goto upd_script_2
311+
echo "Errors encountered during download: %errorlevel%"
312+
goto endscript
313+
:upd_script_2
314+
start copy /y "_build.new.bat" "_build.bat" ^&^& del "_build.new.bat" ^&^& exit
315+
316+
317+
GOTO endscript
318+
319+
320+
:publish_once
321+
322+
SET JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
323+
324+
:: Debugging statements before running publisher
325+
ECHO jar_location is: %jar_location%
326+
IF NOT "%jar_location%"=="not_found" (
327+
ECHO IG Publisher FOUND, Publishing...
328+
java %JAVA_OPTS% -jar "%jar_location%" -ig . %txoption% %extraArgs%
329+
) ELSE (
330+
ECHO IG Publisher NOT FOUND in input-cache or parent folder. Please run the script and update the publisher. Aborting...
331+
)
332+
333+
GOTO endscript
334+
335+
336+
337+
:publish_nosushi
338+
339+
SET JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
340+
341+
:: Debugging statements before running publisher
342+
ECHO jar_location is: %jar_location%
343+
IF NOT "%jar_location%"=="not_found" (
344+
java %JAVA_OPTS% -jar "%jar_location%" -ig . %txoption% -no-sushi %extraArgs%
345+
) ELSE (
346+
ECHO IG Publisher NOT FOUND in input-cache or parent folder. Please run the script and update the publisher. Aborting...
347+
)
348+
349+
GOTO endscript
350+
351+
352+
:publish_notx
353+
SET txoption=-tx n/a
354+
355+
SET JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
356+
357+
:: Debugging statements before running publisher
358+
ECHO jar_location is: %jar_location%
359+
IF NOT "%jar_location%"=="not_found" (
360+
java %JAVA_OPTS% -jar "%jar_location%" -ig . %txoption% %extraArgs%
361+
) ELSE (
362+
ECHO IG Publisher NOT FOUND in input-cache or parent folder. Please run the script and update the publisher. Aborting...
363+
)
364+
365+
GOTO endscript
366+
367+
368+
:publish_continuous
369+
370+
SET JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
371+
372+
ECHO jar_location is: %jar_location%
373+
IF NOT "%jar_location%"=="not_found" (
374+
java %JAVA_OPTS% -jar "%jar_location%" -ig . %txoption% -watch %extraArgs%
375+
) ELSE (
376+
ECHO IG Publisher NOT FOUND in input-cache or parent folder. Please run the script and update the publisher. Aborting...
377+
)
378+
379+
GOTO endscript
380+
381+
382+
:endscript
383+
384+
:: Pausing at the end
385+
IF NOT "%skipPrompts%"=="true" (
386+
PAUSE
387+
)

0 commit comments

Comments
 (0)