fix(ci): 更新构建脚本并修复umami分析配置

更新构建发布脚本以增强可靠性和清理逻辑
将umami分析ID和域名更新为最新配置
This commit is contained in:
祀梦
2025-12-15 17:50:00 +08:00
parent 01c3741b9a
commit 1726ac9828
2 changed files with 104 additions and 88 deletions

View File

@@ -85,9 +85,9 @@ export default defineUserConfig({
requiredMeta: ['nick']
}),
umamiAnalyticsPlugin({
id: 'a4f0ca65-2da6-4e6b-a01b-f3b3157d05a3',
id: '2114ab32-5543-4be1-b5e8-c4f2c9269d0d',
link: 'https://umami.simengweb.com/script.js',
domains: ['notes.simengweb.com'],
domains: ['www.simengweb.com'],
cache: true
}),
],

View File

@@ -1,69 +1,103 @@
@echo off
setlocal EnableExtensions
setlocal EnableExtensions EnableDelayedExpansion
REM ==========================================
REM Configuration
REM ==========================================
chcp 65001 >nul
REM Paths and settings
REM Move to project root
cd /d "%~dp0.."
set "PROJECT_DIR=%CD%\"
set "DIST_DIR=%PROJECT_DIR%docs\.vuepress\dist"
set "CACHE_DIR=%PROJECT_DIR%docs\.vuepress\.cache"
set "TEMP_DIR=%PROJECT_DIR%docs\.vuepress\.temp"
set "PUBLISH_DIR=%PROJECT_DIR%_publish"
set "REMOTE_URL=https://gitea.simengweb.com/si-meng-spec/build_notes_simengweb.git"
set "BRANCH=main"
REM High memory limit for better performance/stability (8GB)
set "NODE_OPTIONS=--max-old-space-size=8192"
REM Args
set "LIGHT_FLAG=%~1"
set "COMMIT_MSG=%~2"
set "COMMIT_MSG=%~1"
if "%COMMIT_MSG%"=="" set "COMMIT_MSG=Build: %DATE% %TIME%"
echo [Info] Working dir: %PROJECT_DIR%
echo ==========================================
echo Start Build and Publish
echo Project Dir: %PROJECT_DIR%
echo Memory Limit: 8192 MB
echo ==========================================
REM Pre-checks
where npm >nul 2>&1
if errorlevel 1 goto :npm_missing
where git >nul 2>&1
if errorlevel 1 goto :git_missing
REM ==========================================
REM 1. Cleanup
REM ==========================================
echo [1/5] Cleaning up old artifacts...
REM Install deps on first run
if not exist "%PROJECT_DIR%node_modules" (
echo [Info] Installing deps ^(npm ci^)...
if exist "%DIST_DIR%" (
echo - Removing %DIST_DIR%
rd /s /q "%DIST_DIR%"
)
if exist "%CACHE_DIR%" (
echo - Removing %CACHE_DIR%
rd /s /q "%CACHE_DIR%"
)
if exist "%TEMP_DIR%" (
echo - Removing %TEMP_DIR%
rd /s /q "%TEMP_DIR%"
)
REM Clean node_modules for a fresh install every time (Ensures clean state)
if exist "%PROJECT_DIR%node_modules" (
echo - Removing node_modules (Fresh Install Mode)
rd /s /q "%PROJECT_DIR%node_modules"
)
REM ==========================================
REM 2. Install Dependencies
REM ==========================================
echo [2/5] Installing dependencies (npm ci)...
call npm ci
if errorlevel 1 goto :fail
) else (
echo [Info] node_modules exists, skip install.
if %ERRORLEVEL% NEQ 0 (
echo [Error] npm ci failed.
exit /b 1
)
REM Light build mode
if /I "%LIGHT_FLAG%"=="light" (
set "LIGHT_BUILD=1"
echo [Info] LIGHT_BUILD=1 enabled
)
set "NODE_OPTIONS=--max-old-space-size=4096"
echo [Info] Building docs...
REM ==========================================
REM 3. Build
REM ==========================================
echo [3/5] Building docs...
call npm run docs:build
if errorlevel 1 goto :fail
if %ERRORLEVEL% NEQ 0 (
echo [Error] Build failed.
exit /b 1
)
if not exist "%DIST_DIR%" goto :no_dist
if not exist "%DIST_DIR%" (
echo [Error] Dist directory not found after build.
exit /b 1
)
REM ==========================================
REM 4. Prepare Publish Directory
REM ==========================================
echo [4/5] Preparing publish directory...
REM Prepare publish repo
if not exist "%PUBLISH_DIR%\.git" (
echo [Info] Cloning publish repo...
echo - Cloning publish repo...
if exist "%PUBLISH_DIR%" rd /s /q "%PUBLISH_DIR%"
git clone "%REMOTE_URL%" "%PUBLISH_DIR%"
if errorlevel 1 goto :fail
if !ERRORLEVEL! NEQ 0 exit /b 1
) else (
echo [Info] Updating publish repo...
echo - Updating publish repo...
pushd "%PUBLISH_DIR%"
git fetch --all
if errorlevel 1 goto :gitfail
git checkout "%BRANCH%"
if errorlevel 1 goto :gitfail
git reset --hard "origin/%BRANCH%"
if errorlevel 1 goto :gitfail
popd
)
echo [Info] Cleaning publish directory ^(keep .git^)...
echo - Cleaning publish directory content (preserving .git)...
pushd "%PUBLISH_DIR%"
for /f "delims=" %%F in ('dir /a /b') do (
if /I not "%%F"==".git" (
@@ -76,58 +110,40 @@ for /f "delims=" %%F in ('dir /a /b') do (
)
popd
echo [Info] Copying dist to publish...
echo - Copying new build artifacts...
robocopy "%DIST_DIR%" "%PUBLISH_DIR%" *.* /E /NFL /NDL /NP /NJH /NJS >nul
if errorlevel 8 goto :fail
if %ERRORLEVEL% GEQ 8 (
echo [Error] Robocopy failed.
exit /b 1
)
REM ==========================================
REM 5. Push to Remote
REM ==========================================
echo [5/5] Pushing changes...
pushd "%PUBLISH_DIR%"
if defined GIT_USERNAME git config user.name "%GIT_USERNAME%"
if defined GIT_EMAIL git config user.email "%GIT_EMAIL%"
git add -A
if "%COMMIT_MSG%"=="" set "COMMIT_MSG=Build: %DATE% %TIME%"
set "HAS_CHANGES=1"
git diff --cached --quiet
if not errorlevel 1 set "HAS_CHANGES=0"
if "%HAS_CHANGES%"=="0" (
echo [Info] No changes to commit; skipping push.
if %ERRORLEVEL% EQU 0 (
echo [Info] No changes to commit.
) else (
git commit -m "%COMMIT_MSG%"
if errorlevel 1 (
popd
goto :fail
)
echo - Pushing to %BRANCH%...
git push origin "%BRANCH%"
if errorlevel 1 (
if !ERRORLEVEL! NEQ 0 (
echo [Error] Git push failed.
popd
goto :fail
)
echo [Info] Pushed to %REMOTE_URL% ^(branch %BRANCH%^).
)
popd
echo [Success] Build and publish done.
exit /b 0
:npm_missing
echo [ERROR] npm not found. Please install Node.js.
goto :fail
:git_missing
echo [ERROR] git not found. Please install Git.
goto :fail
:no_dist
echo [ERROR] Dist directory not found: %DIST_DIR%
goto :fail
:gitfail
echo [ERROR] Git operation failed.
popd
goto :fail
:fail
exit /b 1
)
echo [Success] Pushed successfully.
)
popd
echo ==========================================
echo All Done!
echo ==========================================
exit /b 0