-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.bat
More file actions
221 lines (194 loc) · 7.04 KB
/
package.bat
File metadata and controls
221 lines (194 loc) · 7.04 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
@echo off
REM ============================================================================
REM PureSimpleHTTPServer - Packaging Script
REM ============================================================================
REM Creates Windows installer and portable package
REM
REM Requirements:
REM - PureBasic compiler (for build.bat)
REM - NSIS installed at: C:\Program Files\NSIS\
REM - PowerShell (for ZIP creation - built into Windows)
REM
REM Outputs:
REM - dist\PureSimpleHTTPServer-{version}-windows-portable.zip
REM - dist\PureSimpleHTTPServer-{version}-windows-setup.exe
REM ============================================================================
setlocal EnableDelayedExpansion
REM Configuration
set VERSION=2.5.0
set APP_NAME=PureSimpleHTTPServer
set OUTPUT_DIR=dist
set NSIS_COMPILER=C:\Program Files\NSIS\makensis.exe
set PORTABLE_DIR=dist\portable
REM Colors
set "INFO=[92m"
set "WARN=[93m"
set "ERROR=[91m"
set "RESET=[0m"
echo.
echo %INFO%===========================================================================%RESET%
echo %INFO%PureSimpleHTTPServer Packaging Script%RESET%
echo %INFO%===========================================================================%RESET%
echo.
echo Version: %VERSION%
echo.
REM Step 1: Build executable
echo %INFO%Step 1: Building executable...%RESET%
call build.bat
if errorlevel 1 (
echo %ERROR%ERROR: Build failed!%RESET%
echo.
pause
exit /b 1
)
echo.
REM Step 2: Prepare portable package
echo %INFO%Step 2: Creating portable package...%RESET%
REM Create portable directory
if exist %PORTABLE_DIR% rmdir /s /q %PORTABLE_DIR%
mkdir %PORTABLE_DIR%
REM Copy executable
copy "%OUTPUT_DIR%\%APP_NAME%.exe" "%PORTABLE_DIR%\" >nul
if errorlevel 1 (
echo %ERROR%ERROR: Failed to copy executable!%RESET%
pause
exit /b 1
)
REM Copy wwwroot directory
if exist wwwroot (
xcopy /E /I /Y wwwroot "%PORTABLE_DIR%\wwwroot\" >nul
) else (
echo %WARN%WARNING: wwwroot directory not found, creating placeholder...%RESET%
mkdir "%PORTABLE_DIR%\wwwroot%"
echo ^<html^> > "%PORTABLE_DIR%\wwwroot\index.html"
echo ^<head^>^<title^>PureSimpleHTTPServer^</title^>^</head^> >> "%PORTABLE_DIR%\wwwroot\index.html"
echo ^<body^>^<h1^>Welcome to PureSimpleHTTPServer!^</h1^>^</body^> >> "%PORTABLE_DIR%\wwwroot\index.html"
echo ^</html^> >> "%PORTABLE_DIR%\wwwroot\index.html"
)
REM Convert and copy documentation
echo %INFO%Converting documentation to text format...%RESET%
REM Convert README.md to README.txt
powershell -Command "Get-Content README.md | Out-File -Encoding ASCII %PORTABLE_DIR%\README.txt" 2>nul
if not exist "%PORTABLE_DIR%\README.txt" (
echo %WARN%WARNING: Could not convert README.md, copying as-is...%RESET%
copy README.md "%PORTABLE_DIR%\README.txt" >nul 2>&1
)
REM Copy LICENSE as LICENSE.txt
copy LICENSE "%PORTABLE_DIR%\LICENSE.txt" >nul 2>&1
REM Convert CHANGELOG.md to CHANGELOG.txt
powershell -Command "Get-Content CHANGELOG.md | Out-File -Encoding ASCII %PORTABLE_DIR%\CHANGELOG.txt" 2>nul
if not exist "%PORTABLE_DIR%\CHANGELOG.txt" (
copy CHANGELOG.md "%PORTABLE_DIR%\CHANGELOG.txt" >nul 2>&1
)
REM Create quickstart.txt
echo %INFO%Creating quick start guide...%RESET%
(
echo PureSimpleHTTPServer v%VERSION% - Quick Start Guide
echo ==================================================
echo.
echo Getting Started:
echo ----------------
echo 1. Double-click PureSimpleHTTPServer.exe to start the server
echo 2. Open your web browser to: http://localhost:8080
echo 3. The server will serve files from the wwwroot directory
echo.
echo Command-Line Options:
echo ---------------------
echo --port N : Set port number ^(default: 8080^)
echo --root DIR : Set web root directory ^(default: wwwroot^)
echo --browse : Enable directory browsing
echo --spa : Enable Single Page Application mode
echo --log FILE : Enable access log to FILE
echo --error-log FILE : Enable error log to FILE
echo --log-level LEVEL : Set log level ^(0=none, 1=error, 2=warn, 3=info, 4=debug^)
echo --clean-urls : Enable clean URLs ^(extensionless paths try .html^)
echo --rewrite FILE : Load rewrite rules from FILE
echo --help : Show all options
echo.
echo Examples:
echo ---------
echo PureSimpleHTTPServer.exe
echo Start on port 8080 serving wwwroot
echo.
echo PureSimpleHTTPServer.exe --port 3000 --root C:\MyWebsite
echo Start on port 3000 serving C:\MyWebsite
echo.
echo PureSimpleHTTPServer.exe --browse --log access.log
echo Start with directory browsing and access logging
echo.
echo Stopping the Server:
echo --------------------
echo Press Ctrl+C in the console window to stop the server
echo.
echo Support:
echo --------
echo GitHub: https://github.com/woraj/PureSimpleHTTPServer
echo Documentation: See README.txt for complete documentation
echo.
echo License: MIT License - See LICENSE.txt
echo.
) > "%PORTABLE_DIR%\quickstart.txt"
REM Create ZIP archive
echo %INFO%Creating portable ZIP archive...%RESET%
set ZIP_NAME=%APP_NAME%-%VERSION%-windows-portable.zip
REM Remove existing ZIP if it exists
if exist "%OUTPUT_DIR%\%ZIP_NAME%" del "%OUTPUT_DIR%\%ZIP_NAME%"
REM Create ZIP using PowerShell
powershell -Command "Compress-Archive -Path '%PORTABLE_DIR%\*' -DestinationPath '%OUTPUT_DIR%\%ZIP_NAME%' -Force"
if errorlevel 1 (
echo %ERROR%ERROR: Failed to create ZIP archive!%RESET%
pause
exit /b 1
)
echo.
echo %INFO%Portable package created: %OUTPUT_DIR%\%ZIP_NAME%%RESET%
REM Step 3: Create installer
echo.
echo %INFO%Step 3: Creating installer...%RESET%
REM Check if NSIS is installed
if not exist "%NSIS_COMPILER%" (
echo %ERROR%ERROR: NSIS compiler not found!%RESET%
echo %ERROR%Expected location: %NSIS_COMPILER%%RESET%
echo.
echo Please install NSIS from: https://nsis.sourceforge.io/
echo.
echo Skipping installer creation...
goto skip_installer
)
REM Check if NSIS script exists
if not exist installer\PureSimpleHTTPServer.nsi (
echo %ERROR%ERROR: NSIS script not found: installer\PureSimpleHTTPServer.nsi%RESET%
goto skip_installer
)
REM Build installer
"%NSIS_COMPILER%" installer\PureSimpleHTTPServer.nsi
if errorlevel 1 (
echo %ERROR%ERROR: Installer creation failed!%RESET%
pause
exit /b 1
)
skip_installer:
echo.
echo %INFO%===========================================================================%RESET%
echo %INFO%Packaging complete!%RESET%
echo %INFO%===========================================================================%RESET%
echo.
echo Output files:
echo -------------
if exist "%OUTPUT_DIR%\%ZIP_NAME%" (
echo [+] Portable: %OUTPUT_DIR%\%ZIP_NAME%
for %%A in ("%OUTPUT_DIR%\%ZIP_NAME%") do echo Size: %%~zA bytes
)
if exist "%OUTPUT_DIR%\%APP_NAME%-%VERSION%-windows-setup.exe" (
echo [+] Installer: %OUTPUT_DIR%\%APP_NAME%-%VERSION%-windows-setup.exe
for %%A in ("%OUTPUT_DIR%\%APP_NAME%-%VERSION%-windows-setup.exe") do echo Size: %%~zA bytes
)
echo.
REM Cleanup portable directory
if exist %PORTABLE_DIR% rmdir /s /q %PORTABLE_DIR%
echo %INFO%Package creation complete!%RESET%
echo.
echo Distribution files are ready in the %OUTPUT_DIR% directory.
echo.
pause
exit /b 0