You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.9 KiB
Batchfile
105 lines
2.9 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
|
|
REM Load environment variables from .env file if it exists
|
|
if exist "..\.env" (
|
|
for /f "tokens=*" %%a in ('type "..\.env" ^| findstr /v "^#"') do (
|
|
for /f "tokens=1,2 delims==" %%b in ("%%a") do (
|
|
set "%%b=%%c"
|
|
)
|
|
)
|
|
)
|
|
|
|
REM Use environment variables with defaults
|
|
if not defined FTP_HOST (
|
|
set FTP_HOST=myserver.com
|
|
echo Warning: FTP_HOST not set, using default value
|
|
)
|
|
if not defined FTP_USER (
|
|
set FTP_USER=myuser
|
|
echo Warning: FTP_USER not set, using default value
|
|
)
|
|
if not defined FTP_PASSP (
|
|
set FTP_PASSP=mypass
|
|
echo Warning: FTP_PASSP not set, using default value
|
|
)
|
|
if not defined FTP_PORT set FTP_PORT=21
|
|
if not defined FTP_REMOTE_PATH set FTP_REMOTE_PATH=/packages
|
|
|
|
REM Read package version from package.json
|
|
if not exist "..\package.json" (
|
|
echo Error: package.json not found
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
REM Use PowerShell to extract the version from package.json
|
|
for /f "usebackq tokens=*" %%i in (`powershell -command "(Get-Content -Raw ..\package.json | ConvertFrom-Json).version"`) do (
|
|
set PACKAGE_VERSION=%%i
|
|
)
|
|
|
|
echo Detected package version: !PACKAGE_VERSION!
|
|
|
|
REM Check if WinSCP is installed and accessible
|
|
where winscp.com >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo Error: WinSCP is not found in PATH. Please install WinSCP and add it to your PATH.
|
|
echo Download: https://winscp.net/
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
REM Get the dist directory path
|
|
set DIST_DIR=%~dp0..\dist
|
|
|
|
REM Check if dist directory exists
|
|
if not exist "%DIST_DIR%" (
|
|
echo Error: Dist directory does not exist. Please run build/pack command first.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
REM Check if there are any .tgz files matching the current version to upload
|
|
set COUNT=0
|
|
for %%f in ("%DIST_DIR%\*!PACKAGE_VERSION!*.tgz") do set /a COUNT+=1
|
|
for %%f in ("%DIST_DIR%\*-latest.tgz") do set /a COUNT+=1
|
|
if !COUNT! EQU 0 (
|
|
echo No .tgz files found in dist directory matching version !PACKAGE_VERSION! And named `latest`
|
|
pause
|
|
exit /b 0
|
|
)
|
|
|
|
echo Found !COUNT! package files to upload for version !PACKAGE_VERSION!
|
|
|
|
@REM exit /b 0
|
|
|
|
REM Create a temporary script file with actual values
|
|
set TEMP_SCRIPT=%TEMP%\winscp_script_%RANDOM%.txt
|
|
echo option batch abort > "%TEMP_SCRIPT%"
|
|
echo option confirm off >> "%TEMP_SCRIPT%"
|
|
echo open ftp://!FTP_USER!:!FTP_PASSP!@!FTP_HOST!:!FTP_PORT! >> "%TEMP_SCRIPT%"
|
|
echo cd !FTP_REMOTE_PATH! >> "%TEMP_SCRIPT%"
|
|
echo put "%DIST_DIR%\*!PACKAGE_VERSION!*.tgz" >> "%TEMP_SCRIPT%"
|
|
echo put "%DIST_DIR%\index.html" >> "%TEMP_SCRIPT%"
|
|
echo close >> "%TEMP_SCRIPT%"
|
|
echo exit >> "%TEMP_SCRIPT%"
|
|
|
|
REM Run WinSCP with the temporary script file
|
|
echo Uploading packages via WinSCP...
|
|
winscp.com /script="%TEMP_SCRIPT%"
|
|
|
|
set RESULT=%ERRORLEVEL%
|
|
|
|
REM Clean up the temporary script file
|
|
del "%TEMP_SCRIPT%"
|
|
|
|
if !RESULT! neq 0 (
|
|
echo Upload failed!
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo Upload completed successfully!
|
|
@REM pause
|
|
exit /b 0
|