Remove python3 build dependency

This commit is contained in:
Igor Katson 2024-10-03 13:54:23 +01:00
parent 8b66119746
commit 61a01b4253
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
4 changed files with 26 additions and 29 deletions

View file

@ -84,7 +84,7 @@ Just a regular Rust binary build process.
cargo build --release cargo build --release
The "webui" feature requires npm and python3 installed. The "webui" feature requires npm installed.
## Useful options ## Useful options

View file

@ -4,7 +4,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc --noEmit && vite build && python3 post-build", "build": "tsc --noEmit && vite build && node post-build",
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {

View file

@ -1,33 +1,30 @@
#!/usr/bin/env python3 #!/usr/bin/env node
import os import fs from 'fs';
import os.path import path from 'path';
import json
import re
import itertools
os.chdir('dist') // Change directory to 'dist'
process.chdir('dist');
with open(os.path.join('.vite', 'manifest.json'), 'r') as f: // Read and parse the manifest file
manifest = json.load(f) 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. // List of files to process
# So strip all hashes out of the generated files. 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: // Replace and rename files
index_html = f.read() files.forEach(({ dst, src }) => {
indexHtml = indexHtml.replace(`/${src}`, dst);
fs.renameSync(src, dst);
});
for dst, src in [ // Write the updated 'index.html'
("assets/logo.svg", manifest["assets/logo.svg"]["file"]), fs.writeFileSync('index.html', indexHtml, 'utf-8');
("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)

View file

@ -4,7 +4,7 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx
FROM --platform=$BUILDPLATFORM rust:alpine AS builder FROM --platform=$BUILDPLATFORM rust:alpine AS builder
COPY --from=xx / / COPY --from=xx / /
RUN apk update && apk add clang lld npm python3 pkgconf RUN apk update && apk add clang lld npm pkgconf
ARG TARGETPLATFORM ARG TARGETPLATFORM
RUN xx-apk add gcc musl-dev openssl-dev openssl-libs-static RUN xx-apk add gcc musl-dev openssl-dev openssl-libs-static