-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got subprocesses with logging working
- Loading branch information
1 parent
316fd48
commit a3fa92f
Showing
2 changed files
with
34 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,41 @@ | ||
const DEV_CMDS = [ | ||
// { cmd: [ "bun", "--watch", "server/index.ts"], options: { cwd: "./api" } }, | ||
{ cmd: [ "bun", "--watch", "server/index.ts"], options: { stdout: "inherit" } }, | ||
type DevCmd = { | ||
name: string, | ||
cmd: string[], | ||
options: { | ||
cwd?: string, | ||
stderr?: "inherit" | "pipe" | "ignore" , | ||
} | ||
} | ||
|
||
const DEV_CMDS: DevCmd[] = [ | ||
{ name: "API", cmd: [ "bun", "--watch", "server/index.ts"], options: { cwd: "../api" } }, | ||
{ name: "WEB", cmd: [ "npm", "run", "dev" ], options: { cwd: "../web" } }, | ||
] | ||
|
||
const procs = DEV_CMDS.map(({ cmd, options }) => { | ||
return Bun.spawn(cmd, options) | ||
}) | ||
function consoleWriteForName(name: string) { | ||
const consoleWrite = new WritableStream({ | ||
write(chunk) { | ||
const buffer = new ArrayBuffer(1) | ||
const view = new Uint8Array(buffer) | ||
view[0] = chunk | ||
const decoded = new TextDecoder("utf-8").decode(chunk) | ||
console.log(name, ":", decoded.replace(/\n$/, "")) | ||
} | ||
}) | ||
|
||
for (const proc of procs) { | ||
// console.log(proc.stdout.pipeTo(process.stdout)) | ||
return consoleWrite | ||
} | ||
|
||
console.log(DEV_CMDS) | ||
const procs = DEV_CMDS.map(({ cmd, name, options }) => { | ||
let spawnedProc = Bun.spawn(cmd, { ...options, stdout: "pipe" }) | ||
spawnedProc.stdout?.pipeTo(consoleWriteForName(name)) | ||
|
||
return spawnedProc | ||
}) | ||
|
||
process.on("SIGINT", () => { | ||
console.info("SIGINT signal received... quitting all processes") | ||
procs.forEach(proc => proc.kill()) | ||
process.exit() | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"name": "scripts", | ||
"scripts": { | ||
"dev:all": "bun dev.all.ts" | ||
}, | ||
"devDependencies": { | ||
"bun-types": "^0.7.0" | ||
} | ||
|