Files
maskanx_crm_backend/scripts/run-python.cjs
T

58 lines
1.3 KiB
JavaScript
Raw Normal View History

2026-08-01 10:28:41 +05:30
const { existsSync } = require("node:fs");
const { join, resolve } = require("node:path");
const { spawnSync } = require("node:child_process");
const root = resolve(__dirname, "..");
function canRun(command) {
const result = spawnSync(command, ["--version"], {
cwd: root,
shell: false,
stdio: "ignore",
});
return result.status === 0;
}
const configured = process.env.MASKAN_CRM_PYTHON;
const localCandidates =
process.platform === "win32"
? [
join(root, ".venv", "Scripts", "python.exe"),
join(root, "..", ".venv311", "Scripts", "python.exe"),
]
: [
join(root, ".venv", "bin", "python"),
join(root, "..", ".venv311", "bin", "python"),
];
const candidates = [
configured,
...localCandidates.filter(existsSync),
process.platform === "win32" ? "python" : "python3",
"python",
].filter(Boolean);
const python = candidates.find(canRun);
if (!python) {
console.error(
"Python was not found. Create .venv or set MASKAN_CRM_PYTHON.",
);
process.exit(1);
}
const result = spawnSync(python, process.argv.slice(2), {
cwd: root,
env: process.env,
shell: false,
stdio: "inherit",
});
if (result.error) {
console.error(result.error.message);
process.exit(1);
}
process.exit(result.status ?? 1);