Update on auto setup

This commit is contained in:
Ace
2026-06-26 13:07:40 +02:00
parent 5feb95187c
commit 9ce9506e8e
9 changed files with 769 additions and 265 deletions
+9
View File
@@ -1,3 +1,9 @@
// ── Ollama Launcher ────────────────────────────────────────────────
// Checks if Ollama is already running. If not, finds the binary and
// starts it as a detached background process.
// Cross-platform: uses tasklist (Windows) or pgrep (Linux/Mac) to
// detect running process; uses where/which to find the binary.
import { execSync, spawn } from "node:child_process"
import { platform } from "node:os"
@@ -16,6 +22,7 @@ function isRunning() {
function findOllama() {
if (platform() === "win32") {
// Try PATH first, then common install locations
try {
return execSync("where ollama", { encoding: "utf8", timeout: 3000 }).trim().split("\n")[0]
} catch {}
@@ -36,11 +43,13 @@ if (!isRunning()) {
process.exit(1)
}
console.log("Starting Ollama...")
// Spawn detached so it outlives this script and the npm process
if (platform() === "win32") {
spawn(bin, ["serve"], { stdio: "ignore", detached: true, windowsHide: true }).unref()
} else {
spawn(bin, ["serve"], { stdio: "ignore", detached: true }).unref()
}
// Give it a moment to start listening
execSync("sleep 3", { stdio: "ignore", timeout: 5000 })
} else {
console.log("Ollama already running")
+6
View File
@@ -1,3 +1,9 @@
// ── Browser Opener ─────────────────────────────────────────────────
// Opens the splash page in the user's default browser after an 8-second
// delay. The delay gives all services time to start before the user
// sees the loading screen.
// Cross-platform: uses start (Windows), open (Mac), or xdg-open (Linux).
import { execSync } from "node:child_process"
import { platform } from "node:os"
+8
View File
@@ -1,9 +1,16 @@
// ── Port Precheck ──────────────────────────────────────────────────
// Kills any existing processes on ports 3001, 3006, 3007, 3008.
// These are the AI server, Next.js frontend, Signaling server, and
// Python scraper respectively.
// Runs before anything else starts to avoid EADDRINUSE errors.
import { execSync } from "node:child_process"
import { platform } from "node:os"
const PORTS = [3001, 3006, 3007, 3008]
if (platform() === "win32") {
// Windows: use netstat + findstr to find listening PIDs, then taskkill
for (const port of PORTS) {
try {
const out = execSync(`netstat -ano | findstr "LISTENING" | findstr ":${port} "`, { encoding: "utf8", timeout: 5000 })
@@ -18,6 +25,7 @@ if (platform() === "win32") {
} catch {}
}
} else {
// Linux/Mac: use lsof -ti to find PIDs, then kill -9
for (const port of PORTS) {
try {
const pid = execSync(`lsof -ti:${port} 2>/dev/null`, { encoding: "utf8", timeout: 5000 }).trim()
+7
View File
@@ -1,3 +1,9 @@
// ── 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"
@@ -23,5 +29,6 @@ if (!script) {
process.exit(1)
}
// Spawn Python with inherited stdio so the script's output is visible
const proc = spawn(PYTHON, [script, ...args], { stdio: "inherit" })
proc.on("exit", (code) => process.exit(code ?? 1))
+17 -4
View File
@@ -1,9 +1,21 @@
// ── One-command Setup ──────────────────────────────────────────────
// Run via: npm run setup
// Does the following in order:
// 1. npm install (Node.js dependencies)
// 2. pip install -r requirements.txt (Python dependencies)
// 3. playwright install firefox chromium (Playwright browsers)
// 4. Copies .env.example to .env.local if not exists
//
// All steps are cross-platform (Windows, Mac, Linux).
// Uses execSync for simplicity since each step blocks the next.
import { execSync } from "node:child_process"
import { existsSync, copyFileSync } from "node:fs"
import { platform } from "node:os"
const SEP = platform() === "win32" ? "&" : ";"
// Auto-detect Python executable (python vs python3)
function detectPython() {
const candidates = platform() === "win32" ? ["python", "python3"] : ["python3", "python"]
for (const cmd of candidates) {
@@ -16,6 +28,7 @@ function detectPython() {
process.exit(1)
}
// Auto-detect pip (pip vs pip3), fall back to python -m pip
function detectPip(python) {
const candidates = platform() === "win32" ? ["pip", "pip3"] : ["pip3", "pip"]
for (const cmd of candidates) {
@@ -45,13 +58,13 @@ console.log("=== CoastIT CRM Setup ===\n")
// 1. Node dependencies
run("npm install", "Installing Node.js dependencies")
// 2. Python dependencies
// 2. Python dependencies (run from browser-use-service directory)
run(`cd browser-use-service ${SEP} ${PIP} install -r requirements.txt`, "Installing Python dependencies")
// 3. Playwright browsers
// 3. Playwright browsers (Firefox for primary scraping, Chromium for Chrome/Edge/Opera + Agent fallback)
run(`${PY} -m playwright install firefox chromium`, "Installing Playwright browsers")
// 4. .env file
// 4. .env file — create from template if it doesn't exist
if (!existsSync(".env.local")) {
console.log("\n── Creating .env.local ──")
copyFileSync(".env.example", ".env.local")
@@ -60,7 +73,7 @@ if (!existsSync(".env.local")) {
console.log("\n── .env.local already exists, skipping ──")
}
// 5. Ollama model
// 5. Remaining manual steps
console.log("\n── Next steps ──")
console.log(" 1. Make sure PostgreSQL is running with database 'crm'")
console.log(" 2. Pull the Ollama model: ollama pull dolphin-llama3:8b")