Add paskia-js to Python build; update build-frontend to use fastapi-vue utils for JS_RUNTIME that also can be set via env now. Fix paskia-js compatibility issue with deno, now works with all three runtimes.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import { resolve } from 'path'
|
||||
import { resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import dts from 'vite-plugin-dts'
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [dts({ rollupTypes: true })],
|
||||
build: {
|
||||
|
||||
+23
-23
@@ -1,44 +1,44 @@
|
||||
import shutil
|
||||
"""Hatch build hook for building paskia-js and Vue frontend during package build."""
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from sys import stderr
|
||||
|
||||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
||||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface # type: ignore
|
||||
|
||||
# Import utilities from fastapi-vue
|
||||
exec(Path(__file__).parent.joinpath("fastapi-vue", "util.py").read_text("UTF-8")) # noqa: S102
|
||||
|
||||
|
||||
def run(cmd, **kwargs):
|
||||
"""Run a command and display it."""
|
||||
display_cmd = [Path(cmd[0]).name, *cmd[1:]]
|
||||
stderr.write(f"### {' '.join(display_cmd)}\n")
|
||||
subprocess.run(cmd, check=True, **kwargs)
|
||||
|
||||
|
||||
def find_build_tool():
|
||||
install = [
|
||||
("deno", "install", "--allow-scripts=npm:vue-demi"),
|
||||
("npm", "install"),
|
||||
("bun", "--bun", "install"),
|
||||
]
|
||||
|
||||
build = [
|
||||
("deno", "task", "build"),
|
||||
("npm", "run", "build"),
|
||||
("bun", "--bun", "run", "build"),
|
||||
]
|
||||
|
||||
for i, b in zip(install, build, strict=False):
|
||||
if tool := shutil.which(i[0]):
|
||||
return [tool, *i[1:]], [tool, *b[1:]]
|
||||
|
||||
raise RuntimeError("Deno, npm or Bun is required for building but none was found")
|
||||
|
||||
|
||||
class CustomBuildHook(BuildHookInterface):
|
||||
"""Build hook that compiles paskia-js and Vue frontend before packaging."""
|
||||
|
||||
def initialize(self, version, build_data):
|
||||
super().initialize(version, build_data)
|
||||
stderr.write(">>> Building the frontend\n")
|
||||
stderr.write(">>> Building paskia-js library\n")
|
||||
|
||||
install_cmd, build_cmd = find_build_tool()
|
||||
|
||||
try:
|
||||
# Install dependencies for paskia-js
|
||||
run(install_cmd, cwd="paskia-js")
|
||||
stderr.write("\n")
|
||||
# Build paskia-js
|
||||
run(build_cmd, cwd="paskia-js")
|
||||
stderr.write("\n")
|
||||
except Exception as e:
|
||||
stderr.write(f"Error occurred while building paskia-js: {e}\n")
|
||||
raise
|
||||
|
||||
stderr.write(">>> Building the frontend\n")
|
||||
|
||||
try:
|
||||
run(install_cmd, cwd="frontend")
|
||||
stderr.write("\n")
|
||||
|
||||
Reference in New Issue
Block a user