1.0.4 • Published 27 days ago

@figliolia/child-process v1.0.4

Weekly downloads
-
License
-
Repository
-
Last release
27 days ago

Child Process

A small wrapper around the Node.js ChildProcess.spawn function that provides access to not only the child process, but a wrapping promise to use in your JavaScript logic.

Getting Started

Installation

npm install --save @figliolia/child-process
# or
yarn add @figliolia/child-process

Basic Usage

import { ChildProcess } from "@figliolia/child-process";

const CP = new ChildProcess(
  "some shell command"
);

// Await the completion of your command
await CP.handler;

// Use the raw child process in your code
CP.process.on("something", () => {});

// If you do not need access to the underlying child process, 
// but instead wish to have just a promise with stdio access
const { stdout, stderr } = await ChildProcess.execute("your command");

Advanced Usage

It's fairly common to require the management of multiple sub-process when building complex applications such as development environments, CI's, and more.

This library provides a means for handling multiple child processes as well as binding to kill exit signals that may cause an underlying application to fail.

import { ChildProcess } from "@figliolia/child-process";

class MyApplication {

	public static run() {
		const shells = this.bootStuffUp();
		// Kill each shell if the parent process receives
		// a kill signal or uncaught exception
		ChildProcess.bindExits(shells);
		// Await the completion of all commands
		return Promise.all(shells.map(CP => CP.handler));
	}

	private static bootStuffUp() {
		return [
			new ChildProcess(
				"some shell command"
			),
			new ChildProcess(
				"another shell command"
			),
			new ChildProcess(
				"perhaps another shell command"
			),
		]
	}
}
1.0.4

27 days ago

1.0.3

4 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago