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
The "webui" feature requires npm and python3 installed.
The "webui" feature requires npm installed.
## Useful options

View file

@ -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": {

View file

@ -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)
// Write the updated 'index.html'
fs.writeFileSync('index.html', indexHtml, 'utf-8');

View file

@ -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