From f91226e7123c3180552c6f761e7668f9108d5903 Mon Sep 17 00:00:00 2001 From: ChinhLee <76194645+chinhkrb113@users.noreply.github.com> Date: Thu, 2 Apr 2026 21:27:46 +0700 Subject: [PATCH] docs: cross-platform backend dev launcher with automatic command fallback Add a small Node script that starts `backend/run.py` in a robust cross-platform way. It should detect and try backend launch commands in order, so Windows users can still use one command (`npm run dev`) even if `uv` is not installed but `python`/`py` is available. Affected files: dev-backend.js Signed-off-by: ChinhLee <76194645+chinhkrb113@users.noreply.github.com> --- scripts/dev-backend.js | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/dev-backend.js diff --git a/scripts/dev-backend.js b/scripts/dev-backend.js new file mode 100644 index 0000000000..10f3e20153 --- /dev/null +++ b/scripts/dev-backend.js @@ -0,0 +1,45 @@ +#!/usr/bin/env node +/** + * Cross-platform backend dev launcher. + * Tries launch commands in order: uv, python3, python, py + * so Windows users without uv can still run `npm run dev`. + */ + +const { spawn } = require('child_process'); +const path = require('path'); + +const backend_script = path.join(__dirname, '..', 'backend', 'run.py'); + +const candidates = [ + ['uv', ['run', 'python', backend_script]], + ['python3', [backend_script]], + ['python', [backend_script]], + ['py', [backend_script]], +]; + +function try_next(index) { + if (index >= candidates.length) { + console.error('No suitable Python interpreter found. Install uv, python3, python, or py.'); + process.exit(1); + } + + const [cmd, args] = candidates[index]; + console.log(`Trying: ${cmd} ${args.join(' ')}`); + + const child = spawn(cmd, args, { + stdio: 'inherit', + shell: process.platform === 'win32', + }); + + child.on('error', () => { + try_next(index + 1); + }); + + child.on('exit', (code) => { + if (code !== 0) { + process.exit(code); + } + }); +} + +try_next(0);