mirror of
https://github.com/wled/WLED.git
synced 2025-11-06 17:48:51 +00:00
Fix runtime release name replacement - move to build-time
Co-authored-by: netmindz <442066+netmindz@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
Import("env")
|
||||
import shutil
|
||||
import os
|
||||
|
||||
node_ex = shutil.which("node")
|
||||
# Check if Node.js is installed and present in PATH if it failed, abort the build
|
||||
@@ -12,6 +13,21 @@ else:
|
||||
print('\x1b[6;33;42m' + 'Installing node packages' + '\x1b[0m')
|
||||
env.Execute("npm ci")
|
||||
|
||||
# Extract the release name from build flags
|
||||
release_name = "Custom"
|
||||
build_flags = env.get("BUILD_FLAGS", [])
|
||||
for flag in build_flags:
|
||||
if 'WLED_RELEASE_NAME=' in flag:
|
||||
# Extract the release name, remove quotes and handle different formats
|
||||
parts = flag.split('WLED_RELEASE_NAME=')
|
||||
if len(parts) > 1:
|
||||
release_name = parts[1].split()[0].strip('\"\\')
|
||||
break
|
||||
|
||||
# Set environment variable for cdata.js to use
|
||||
os.environ['WLED_RELEASE_NAME'] = release_name
|
||||
print(f'Building web UI with release name: {release_name}')
|
||||
|
||||
# Call the bundling script
|
||||
exitCode = env.Execute("npm run build")
|
||||
|
||||
|
||||
@@ -96,10 +96,9 @@ function adoptVersionAndRepo(html) {
|
||||
html = html.replaceAll("##VERSION##", version);
|
||||
}
|
||||
|
||||
// Replace ##RELEASE## with a placeholder that will be replaced at runtime
|
||||
// Since we can't determine the exact release name at build time (it depends on build flags),
|
||||
// we'll use a special marker that gets replaced in the server code
|
||||
html = html.replaceAll("##RELEASE##", "%RELEASE%");
|
||||
// Replace ##RELEASE## with the actual release name from build environment
|
||||
const releaseName = process.env.WLED_RELEASE_NAME || 'Custom';
|
||||
html = html.replaceAll("##RELEASE##", releaseName);
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -177,13 +177,7 @@ static String msgProcessor(const String& var)
|
||||
return String();
|
||||
}
|
||||
|
||||
static String updateProcessor(const String& var)
|
||||
{
|
||||
if (var == F("RELEASE")) {
|
||||
return String(releaseString);
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
|
||||
static void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool isFinal) {
|
||||
if (!correctPIN) {
|
||||
@@ -810,18 +804,5 @@ void serveSettings(AsyncWebServerRequest* request, bool post) {
|
||||
case SUBPAGE_WELCOME : content = PAGE_welcome; len = PAGE_welcome_length; break;
|
||||
default: content = PAGE_settings; len = PAGE_settings_length; break;
|
||||
}
|
||||
|
||||
#ifndef WLED_DISABLE_OTA
|
||||
// Use processor for update page to replace %RELEASE% placeholder
|
||||
if (subPage == SUBPAGE_UPDATE) {
|
||||
if (handleIfNoneMatchCacheHeader(request, code, 0)) return;
|
||||
AsyncWebServerResponse *response = request->beginResponse_P(code, contentType, content, len, updateProcessor);
|
||||
if (content != PAGE_settingsCss) response->addHeader(FPSTR(s_content_enc), F("gzip"));
|
||||
setStaticContentCacheHeaders(response, code, 0);
|
||||
request->send(response);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
handleStaticContent(request, "", code, contentType, content, len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user