forked from openmovementproject/openmovement-axconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.cmd
62 lines (48 loc) · 2.37 KB
/
watch.cmd
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
@echo off
setlocal
rem openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem && openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out server.crt
rem http-server -S -K key.pem -C server.crt
::: Kill existing processes (token 3 if specific, token 10 if all)
set "FIELDS=handle^,name^,commandline"
rem taskkill /im "ngrok.exe" 2>nul
for /f "delims=, tokens=3" %%f in ('wmic path win32_process get %FIELDS% /format:"%WINDIR%\System32\wbem\en-us\csv" ^| findstr /v findstr.exe ^| findstr ngrok.exe') do (
if not "%%f"=="name" (
echo PID/ngrok: %%f
TASKKILL /PID %%f
)
)
rem taskkill /im cmd.exe /fi "WINDOWTITLE eq http-server*"
for /f "delims=, tokens=3" %%f in ('wmic path win32_process get %FIELDS% /format:"%WINDIR%\System32\wbem\en-us\csv" ^| findstr /v findstr.exe ^| findstr node.exe ^| findstr [lh][it][vt][ep]-server') do (
if not "%%f"=="name" (
echo PID/http-server: %%f
TASKKILL /PID %%f /F
)
)
taskkill /im WindowsTerminal.exe /fi "WINDOWTITLE eq http-server*" >nul
::: Live server on port 8080 (rather than parcel's dev mode on port 1234) as this WebSocket works through ngrok's https
rem start "http-server" cmd /c npx live-server --no-browser dist
::: Ngrok to make public
rem start "ngrok" ngrok http 8080
start "http-server-ngrok" wt new-tab --title "http-server-ngrok" -d . cmd /c "title http-server-ngrok && npx live-server --no-browser dist" ; split-pane --title "http-server-ngrok" ngrok http 8080
::: Wait for Ngrok to start
:wait_for_ngrok
echo.Waiting for ngrok...
choice /C 0 /D 0 /T 1 >nul
::: Display Ngrok current forwarding details
SET TUNNEL=
FOR /F "tokens=* USEBACKQ" %%F IN (`curl -s http://127.0.0.1:4040/api/tunnels ^| bash -c "grep -Eo 'https://[0-9a-f]+-[0-9]+-[0-9]+-[0-9]+-[0-9]+\.ngrok-free\.app'"`) DO (
SET TUNNEL=%%F
)
IF "%TUNNEL%"=="" GOTO wait_for_ngrok
ECHO Now listening on: %TUNNEL%
SET QRCODE=
FOR %%X IN (qrcode.exe) do set QRCODE=%%~$PATH:X
IF DEFINED QRCODE "%QRCODE%" --invert --output:medium "%TUNNEL%"
ECHO.%TUNNEL%
echo.Brief delay for server to start listening...
choice /C 0 /D 0 /T 1 >nul
rem adb shell am start -n com.android.chrome/org.chromium.chrome.browser.ChromeTabbedActivity -d "%TUNNEL%" --activity-clear-task
rem (open local Chrome and use "Send to your devices" to open on phone).
IF NOT "%TUNNEL%"=="" start chrome.exe "%TUNNEL%#debug&nodetails&config=0"
::: Start parcel's watch mode
npm run dev