-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
executable file
·43 lines (33 loc) · 840 Bytes
/
index.mjs
File metadata and controls
executable file
·43 lines (33 loc) · 840 Bytes
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
#!/usr/bin/env node
/**
* run.js "command -1" "command -2" "command -3"
*/
import { spawn } from "node:child_process"
const [, , ...commands] = process.argv
if (!Array.isArray(commands)) {
throw new RangeError("`commands` is not array")
}
if (commands.length === 0) {
throw new RangeError("`commands` is empty")
}
const abort = new AbortController()
const signal = abort.signal
process.on("exit", function () {
abort.abort()
})
process.on("SIGINT", function () {
abort.abort()
})
commands.forEach(function (command, index) {
const [c, ...args] = command.split(" ")
const process = spawn(c, args, {
signal,
stdio: "inherit"
})
process.on("error", function (err) {
if (err.name === "AbortError") {
return // ignore abort errors
}
console.error(format(`${command}: error ${err}`))
})
})