npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cmd-spawn

v1.4.0

Published

Run shell commands as string. Typescript(+typings) ES6 module. Node 6+ spawn with promises, buffered and unbuffered output

Downloads

43

Readme

Build Status Coverage Status npm

cmd-spawn

Run shell commands as string. Typescript(+typings) ES2015/ES2017 module. Node 6+ spawn with promises, buffered and unbuffered output, inspired by node-buffered-spawn.

Features:

  • Written in typescript and typings are auto generated.
  • Promise based (Bluebird instance returned).
  • child process exposed in returned promise as cp property.
  • If shell option is passed to spawn, the shell commands can be run as is, even with pipes.
  • Auto passed process.env if spawn env not overriden.
  • Normal version and buffered(collects all output and then resolve) option.
  • Uses cross-spawn by default, can be disabled.

Install

npm -S i cmd-spawn

Usage

unbuffered(normal spawn)

import { cmdSpawn } from 'cmd-spwawn';
// Inherit process.env auto if not overriden

// Told to run the command as is in a shell
// Returns Bluebird Promise
const promise = cmdSpawn('GITHUB_TOKEN=$TOKEN_ENV git clone [email protected]:beckend/cmd-spawn.git', {
  spawnOpts:
    shell: true
  }
});

// child process is always in property p
promise.cp.on('data', (data: Buffer) => {
  console.log(data.toString());
});

promise.cp.once('close', (code) => {
  if (code === 0) {
    console.log('success');
  } else {
    console.log('fail');
  }
});

buffered spawn

// compile typescript project
const promise = cmdSpawn('tsc --p src/tsconfig-es2015.json', { buffer: true });
// Bluebird
promise
  .then((result) => {
    console.log(result.stdout);
    console.log(result.stderr);
  })
  .catch((er) => {
    // child process error
    console.log(er);
  })
  .finally(() => {
    console.log('done');
  });

More usage examples

Can be found in src/__test__/cmd-spawn.spec.ts.

API

import { cmdSpawn } from 'cmd-spawn';

usage: cmdSpawn(cmd, options)

| Parameter | Default | Type | Description | |:---|:---|:---|:---| | cmd | undefined | string or Array<string> | command to run, if array is given, the first index is the command and rest becomes arguments. | | options | { spawnOpts: {}, crossSpawn: true, buffer: false } | object | Options described below. |

options - ? means optional

{
  // Options passed to spawn
  spawnOpts?: SpawnOptions;
  // buffer output flag, default false
  buffer?: boolean;
  // crossSpawn flag, default enabled
  crossSpawn?: boolean;
}

Contributing

Requires

  • node@6+
  • [email protected] because of package.json - prepare script. (only required to run hook when publish)
  • npm -g i gulp-cli jest-cli.

Usage

  • gulp --tasks to get going.

Developing

  • jest --watchAll to watch recompiled files and rerun tests.

Testing

Supports:

  • jest, needs jest-cli installed. it will execute the transpiled files from typescript.

Dist

  • gulp will run default task which consist of running tasks:
  • lint, clean, build, minify then jest and collect coverage.

Note: All minified files are only ES5.