Repository navigation
Expand file tree
/
Copy pathdev-script.js
More file actions
71 lines (62 loc) · 2.11 KB
/
Copy pathdev-script.js
File metadata and controls
71 lines (62 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { exec, spawn } from "child_process";
import dotenv from "dotenv";
dotenv.config({ path: ".env.local" }); // Load from .env.local (Vite convention; covered by *.local gitignore rule)
// Function to kill process on port 5173
function killPort() {
return new Promise((resolve) => {
console.log("Attempting to kill any process on port 5173...");
exec("npx kill-port 5173", (error, stdout, stderr) => {
if (error) {
console.log(
"No process running on port 5173 or failed to kill process"
);
} else {
console.log("Successfully killed process on port 5173");
}
// Resolve in either case
resolve();
});
exec("npx kill-port 5174", (error, stdout, stderr) => {
if (error) {
console.log(
"No process running on port 5174 or failed to kill process"
);
} else {
console.log("Successfully killed process on port 5174");
}
// Resolve in either case
resolve();
});
});
}
// Main function
async function startDev() {
try {
// First try to kill any process on port 5173
await killPort();
// Wait a bit to ensure port is released
await new Promise((resolve) => setTimeout(resolve, 1000));
// Start Vite
console.log("Starting Vite dev server...");
// Log environment variables to confirm they're loaded (will show in terminal)
console.log("Loaded environment variables:");
console.log("VITE_SUPABASE_URL:", process.env.VITE_SUPABASE_URL ? "✓ Defined" : "✗ Undefined");
console.log("VITE_SUPABASE_PUBLISHABLE_KEY:", process.env.VITE_SUPABASE_PUBLISHABLE_KEY ? "✓ Defined" : "✗ Undefined");
// Pass environment variables to the Vite process
const vite = spawn("npx", ["vite"], {
stdio: "inherit",
shell: true,
env: {
...process.env, // Include all existing environment variables
}
});
// Handle process exit
vite.on("close", (code) => {
console.log(`Vite process exited with code ${code}`);
});
} catch (error) {
console.error("Error:", error);
}
}
// Run the main function
startDev();