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

batcher

v3.0.0

Published

Batch processor of shell commands and javascript functions over shared state object. Async, sequential, parallel.

Downloads

74

Readme

batcher NPM Module

Batch processor of shell commands and javascript functions over shared state object. Async, sequential, parallel.

Linux Build MacOS Build Windows Build

Coverage Status Dependency Status

Notice of change of ownership: Starting version 1.0.0 this package has changed it's owner and goals. Old version (0.0.2) is still available on npm via npm install [email protected]. Thank you.

Why

Some tasks (e.g. deploy scripts) better implemented using shell commands, some tasks require nodejs power, this module allows to bring them together in a simple, yet powerful "batch" script and combine via shared state object.

Features

  • Executes provided shell commands asynchronously and sequentially.
  • Shares state object among all specified tasks.
  • Allows to update state with output from shell commands.
  • Allows for parallel execution of the commands.
  • Accepts custom (sync and async) functions as tasks.
  • Provides markdown-compatible default reporter.
  • Natively supports custom reporters.

Install

npm install --save batcher

Examples

Following setup:

var batcher = require('batcher');

batcher({
  word: 'ABC'
},
[
  // simple shell command
  'echo A',

  // using state variable
  'echo word is ${word}',

  // updating state
  {twoWords: 'echo ${word} + ${word}'},

  // reusing updated state
  'echo two words are ${twoWords}',

  // parallel execution
  ['echo Marco', 'echo Polo'],

  // custom sync function as a task
  function()
  {
    return this.twoWords.substr(0, 5);
  },

  // custom async function as a task
  function(cb)
  {
    cb(null, this.twoWords.substr(0, 8));
  },

  // for arrow functions it passes context as first argument
  { newWord: context => `${context.word}/${context.word}` },

  // same goes for asynchronous arrow functions
  (context, cb) => {
    cb(null, context.newWord.split('/'))
  }
]);

Outputs (with default reporter):

# Started batch process

## Initial State:

```
{
  "word": "ABC"
}
```

## Execution


### Executing `` echo A ``...

> Finished execution of `` echo A ``:
```
A
```

### Executing `` echo word is ${word} ``...

> Finished execution of `` echo word is ${word} ``:
```
word is ABC
```

### Executing `` echo ${word} + ${word} ``...

> Storing output into `` twoWords ``

> Finished execution of `` echo ${word} + ${word} ``:
```
ABC + ABC
```

### Executing `` echo two words are ${twoWords} ``...

> Finished execution of `` echo two words are ${twoWords} ``:
```
two words are ABC + ABC
```

### Executing `` echo Marco ``...


### Executing `` echo Polo ``...

> Finished execution of `` echo Marco ``:
```
Marco
```
> Finished execution of `` echo Polo ``:
```
Polo
```

### Executing `` function () { return this.twoWords.substr(0, 5); } ``...

> Finished execution of `` function () { return this.twoWords.substr(0, 5); } ``:
```
ABC +
```

### Executing `` function (cb) { cb(null, this.twoWords.substr(0, 8)); } ``...

> Finished execution of `` function (cb) { cb(null, this.twoWords.substr(0, 8)); } ``:
```
ABC + AB
```

### Executing `` context => `${context.word}/${context.word}` ``...

> Storing output into `` newWord ``

> Finished execution of `` context => `${context.word}/${context.word}` ``:
```
ABC/ABC
```

### Executing `` (context, cb) => { cb(null, context.newWord.split('/')) } ``...

> Finished execution of `` (context, cb) => { cb(null, context.newWord.split('/')) } ``:
```
ABC
ABC
```

## Final State:

```
{
  "newWord": "ABC/ABC",
  "twoWords": "ABC + ABC",
  "word": "ABC"
}
```

For more examples check out example.js and example.md for default output, and tests folder for advanced usage examples.

License

Batcher is released under the MIT license.