-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.cmd
More file actions
91 lines (86 loc) · 3.25 KB
/
run.cmd
File metadata and controls
91 lines (86 loc) · 3.25 KB
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
@echo off
setlocal
rem 1. Resolve BOBBIT_HOME — directory containing this script
set "BOBBIT_HOME=%~dp0"
rem Remove trailing backslash
if "%BOBBIT_HOME:~-1%"=="\" set "BOBBIT_HOME=%BOBBIT_HOME:~0,-1%"
rem 2. Check node is available
where node >nul 2>nul
if errorlevel 1 (
echo Error: Node.js is required but not found on PATH. >&2
exit /b 1
)
rem 3. Auto-bootstrap if needed
if not exist "%BOBBIT_HOME%\node_modules" (
echo First run — installing dependencies and building...
pushd "%BOBBIT_HOME%"
call npm install
if errorlevel 1 (
echo Error: npm install failed. >&2
popd
exit /b 1
)
call npm run build
if errorlevel 1 (
echo Error: npm run build failed. >&2
popd
exit /b 1
)
popd
)
if not exist "%BOBBIT_HOME%\dist\server\cli.js" (
echo Building server...
pushd "%BOBBIT_HOME%"
call npm run build:server
if errorlevel 1 (
echo Error: build:server failed. >&2
popd
exit /b 1
)
popd
)
if not exist "%BOBBIT_HOME%\dist\ui\index.html" (
echo Building UI...
pushd "%BOBBIT_HOME%"
call npm run build:ui
if errorlevel 1 (
echo Error: build:ui failed. >&2
popd
exit /b 1
)
popd
)
rem 3b. Rebuild if source is newer than build output
if exist "%BOBBIT_HOME%\dist\server\cli.js" (
for /f %%R in ('powershell -NoProfile -Command "$ref = (Get-Item -LiteralPath '%BOBBIT_HOME%\dist\server\cli.js').LastWriteTime; $dirs = @('%BOBBIT_HOME%\src\server'); $files = @('%BOBBIT_HOME%\package.json','%BOBBIT_HOME%\tsconfig.server.json'); $stale = $false; foreach ($d in $dirs) { if (Get-ChildItem -LiteralPath $d -Recurse -File | Where-Object { $_.LastWriteTime -gt $ref } | Select-Object -First 1) { $stale = $true; break } }; if (-not $stale) { foreach ($f in $files) { if ((Get-Item -LiteralPath $f).LastWriteTime -gt $ref) { $stale = $true; break } } }; if ($stale) { Write-Output 'stale' } else { Write-Output 'fresh' }"') do (
if "%%R"=="stale" (
echo ⚡ Server source changed — rebuilding...
pushd "%BOBBIT_HOME%"
call npm run build:server
if errorlevel 1 (
echo Error: build:server failed. >&2
popd
exit /b 1
)
popd
)
)
)
if exist "%BOBBIT_HOME%\dist\ui\index.html" (
for /f %%R in ('powershell -NoProfile -Command "$ref = (Get-Item -LiteralPath '%BOBBIT_HOME%\dist\ui\index.html').LastWriteTime; $dirs = @('%BOBBIT_HOME%\src\ui','%BOBBIT_HOME%\src\app'); $stale = $false; foreach ($d in $dirs) { if (Get-ChildItem -LiteralPath $d -Recurse -File | Where-Object { $_.LastWriteTime -gt $ref } | Select-Object -First 1) { $stale = $true; break } }; if ($stale) { Write-Output 'stale' } else { Write-Output 'fresh' }"') do (
if "%%R"=="stale" (
echo ⚡ UI source changed — rebuilding...
pushd "%BOBBIT_HOME%"
call npm run build:ui
if errorlevel 1 (
echo Error: build:ui failed. >&2
popd
exit /b 1
)
popd
)
)
)
:launch
rem 4. Launch with implicit --cwd as current directory, forwarding all args
node "%BOBBIT_HOME%\dist\server\cli.js" --cwd "%CD%" %*