workshop/main.ts
2025-06-23 15:35:06 -07:00

35 lines
1.1 KiB
TypeScript

import { spawn } from "bun"
console.log("\n\n----------------------------------")
console.log(`Node Environment: ${process.env.NODE_ENV || "development"}`)
console.log(`Bun Version: ${Bun.version}`)
console.log("----------------------------------\n\n")
const run = async (cmd: string[]) => {
const commandText = cmd.join(" ")
const proc = spawn(cmd, { stdout: "inherit", stderr: "inherit" })
console.log(`🪴 "${commandText}" spawned with PID ${proc.pid}`)
try {
const status = await proc.exited
console.log(`👋 Process ${commandText}(PID ${proc.pid}) exited with code ${status}`)
if (status !== 0) {
throw new Error(`Process "${commandText}" failed with exit code ${status}`)
}
return status
} catch (err) {
console.error(`💥 Error waiting for "${commandText}" exit:`, err)
throw err
}
}
try {
await Promise.all([run(["bun", "bot:discord"]), run(["bun", "http"])])
console.log("✅ All processes completed successfully")
} catch (error) {
console.error("❌ One or more processes failed:", error)
process.exit(1)
}