Simple process runner for Deno - a thin wrapper around Deno.run
.
import { Process } from "https://denopkg.com/iamnathanj/[email protected]/mod.ts";
const proc = new Process({
name: "my-process",
cmd: "deno some-file.ts"
});
proc.on("stdout", event => {
// e.target will be a Process object
Deno.stdout.writeSync(event.detail);
});
proc.on("stderr", event => {
// e.target will be a Process object
Deno.stderr.writeSync(event.detail);
});
proc.start();
await proc.complete();
import { Process, Plex } from "https://denopkg.com/iamnathanj/[email protected]/mod.ts";
const multiProcess = new Plex([
new Process({
name: "process-1",
cmd: "echo 1"
}),
new Process({
name: "process-2",
cmd: "echo 2"
})
]);
// .listen will read from both stdout and stderr
multiProcess.listen(e => {
// e.target will be a Process object
Deno.stdout.writeSync(e.detail);
});
multiProcess.start()
await multiProcess.complete();
Watching uses file system polling with fs-poll. This is temporary and will be replaced with Deno fsEvents soon.
new Process({ name: "my process", cmd: "long running"}).watch({ root: Deno.cwd() });
Things are chainable if you like that sort of thing.
await new Process({ name: "my process", cmd: "some task" })
.watch({ root: Deno.cwd() })
.on("stdout", e => Deno.stdout.writeSync(e.detail))
.on("stderr", e => Deno.stdout.writeSync(e.detail))
.start()
.complete();
await new Plex([
new Process({ name: "proc-1", cmd: "my cmd"}).watch({ root: "./some/dir" }),
new Process({ name: "proc-2", cmd: "my cmd 2" }).watch({ root: "some/other/dir" })
])
.listen(e => Deno.stdout.writeSync(e.detail))
.start()
.complete();