Files
CRM_ENVR/scripts/run-python.mjs
T
Ace d35c806d5b feat: Enhance provider components with detailed documentation and comments
- Added comprehensive comments and JSDoc-style documentation to NotificationProvider, ThemeProvider, UserProvider, and WebsiteThemeProvider for better clarity and maintainability.
- Improved type definitions in index.ts for better code understanding and usage.
- Introduced Docker support with Dockerfiles for various services including AI server, signaling server, and browser-use service.
- Created a docker-compose.yml file to orchestrate multiple services including PostgreSQL, AI, scraper, and frontend.
- Added a startup guide (startup.txt) for setting up the CRM environment on Ubuntu with Docker.
- Included a .dockerignore file to exclude unnecessary files from Docker builds.
2026-07-13 13:05:30 +02:00

51 lines
2.0 KiB
JavaScript

// ── Python Runner ──────────────────────────────────────────────────
// Detects the system's Python executable (python vs python3) and runs
// a given script with arguments. Used by the dev:browser-use npm script.
// Avoids shell:true — spawns Python directly with its full path.
// Cross-platform: uses where (Windows) or which (Linux/Mac).
import { execSync, spawn } from "node:child_process"
import { platform } from "node:os"
import { statSync } from "node:fs"
/** Locate the Python 3 executable. Checks common install paths first, then the system PATH. */
function detectPython() {
// Pre-check common Windows install directories to avoid PATH lookup
const commonPaths = [
`${process.env.LOCALAPPDATA}\\Programs\\Python\\Python313\\python.exe`,
`${process.env.LOCALAPPDATA}\\Programs\\Python\\Python312\\python.exe`,
`${process.env.ProgramFiles}\\Python313\\python.exe`,
`${process.env.ProgramFiles}\\Python312\\python.exe`,
]
for (const p of commonPaths) {
try {
statSync(p)
return p
} catch {}
}
// Fall back to PATH resolution (prefer python3 on Unix)
const candidates = platform() === "win32" ? ["python", "python3"] : ["python3", "python"]
for (const cmd of candidates) {
try {
const out = execSync(platform() === "win32" ? `where ${cmd}` : `which ${cmd}`, { encoding: "utf8", timeout: 5000 })
const path = out.trim().split("\n")[0].replace(/\r$/, "")
if (path) return path
} catch {}
}
console.error("Python not found. Install Python 3 from https://python.org")
process.exit(1)
}
const PYTHON = detectPython()
const script = process.argv[2]
const args = process.argv.slice(3)
if (!script) {
console.error("Usage: node run-python.mjs <script> [args...]")
process.exit(1)
}
// Spawn Python with inherited stdio so the script's output is visible in real-time
const proc = spawn(PYTHON, [script, ...args], { stdio: "inherit" })
proc.on("exit", (code) => process.exit(code ?? 1))