From 61a01b425340bd08e6937f579a07683ec53a1b68 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Thu, 3 Oct 2024 13:54:23 +0100 Subject: [PATCH] Remove python3 build dependency --- README.md | 2 +- crates/librqbit/webui/package.json | 2 +- crates/librqbit/webui/post-build | 49 ++++++++++++++---------------- docker/Dockerfile.xx | 2 +- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index c689455..d41318c 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Just a regular Rust binary build process. cargo build --release -The "webui" feature requires npm and python3 installed. +The "webui" feature requires npm installed. ## Useful options diff --git a/crates/librqbit/webui/package.json b/crates/librqbit/webui/package.json index f7ad2c8..95e62d3 100644 --- a/crates/librqbit/webui/package.json +++ b/crates/librqbit/webui/package.json @@ -4,7 +4,7 @@ "type": "module", "scripts": { "dev": "vite", - "build": "tsc --noEmit && vite build && python3 post-build", + "build": "tsc --noEmit && vite build && node post-build", "preview": "vite preview" }, "dependencies": { diff --git a/crates/librqbit/webui/post-build b/crates/librqbit/webui/post-build index a0672f1..4227c99 100755 --- a/crates/librqbit/webui/post-build +++ b/crates/librqbit/webui/post-build @@ -1,33 +1,30 @@ -#!/usr/bin/env python3 +#!/usr/bin/env node -import os -import os.path -import json -import re -import itertools +import fs from 'fs'; +import path from 'path'; -os.chdir('dist') +// Change directory to 'dist' +process.chdir('dist'); -with open(os.path.join('.vite', 'manifest.json'), 'r') as f: - manifest = json.load(f) +// Read and parse the manifest file +const manifestPath = path.join('.vite', 'manifest.json'); +const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8')); +// Read the 'index.html' file +let indexHtml = fs.readFileSync('index.html', 'utf-8'); -# For rust to "include_str!", we need to have predictable filenames. -# So strip all hashes out of the generated files. +// List of files to process +const files = [ + { dst: 'assets/logo.svg', src: manifest['assets/logo.svg'].file }, + { dst: 'assets/index.css', src: manifest['index.html'].css[0] }, + { dst: 'assets/index.js', src: manifest['index.html'].file } +]; -with open('index.html', 'r') as f: - index_html = f.read() +// Replace and rename files +files.forEach(({ dst, src }) => { + indexHtml = indexHtml.replace(`/${src}`, dst); + fs.renameSync(src, dst); +}); -for dst, src in [ - ("assets/logo.svg", manifest["assets/logo.svg"]["file"]), - ("assets/index.css", manifest["index.html"]["css"][0]), - ("assets/index.js", manifest["index.html"]["file"]) -]: - generated_file = src - new_file = dst - - index_html = index_html.replace("/" + generated_file, new_file) - os.rename(generated_file, new_file) - -with open('index.html', 'w') as f: - f.write(index_html) \ No newline at end of file +// Write the updated 'index.html' +fs.writeFileSync('index.html', indexHtml, 'utf-8'); diff --git a/docker/Dockerfile.xx b/docker/Dockerfile.xx index b1f0aa9..8b79038 100644 --- a/docker/Dockerfile.xx +++ b/docker/Dockerfile.xx @@ -4,7 +4,7 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx FROM --platform=$BUILDPLATFORM rust:alpine AS builder COPY --from=xx / / -RUN apk update && apk add clang lld npm python3 pkgconf +RUN apk update && apk add clang lld npm pkgconf ARG TARGETPLATFORM RUN xx-apk add gcc musl-dev openssl-dev openssl-libs-static