iAmNathanJ / plex

Deno process multiplexer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plex

Simple process runner for Deno - a thin wrapper around Deno.run.

Usage

Single Process

import { Process } from "https://denopkg.com/iamnathanj/plex@v1.3.0/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();

Multiple Processes

import { Process, Plex } from "https://denopkg.com/iamnathanj/plex@v1.3.0/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

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() });

Chaining

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();

About

Deno process multiplexer


Languages

Language:TypeScript 100.0%