Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cjs-runner

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cjs-runner

Simple task runner.

  • 1.5.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
345
decreased by-9.69%
Maintainers
1
Weekly downloads
 
Created
Source

Task runner

build status npm version dependencies status devDependencies status Gitter RunKit

Set of methods to synchronize asynchronous operations.

Installation

npm install cjs-runner

Usage

Add to the scope:

var Runner = require('cjs-runner'),
    runner = new Runner();

Create a simple sync task:

runner.task('lint', function () {
    // some actions
});

Create a simple async task:

runner.task('build', function ( done ) {
    someAsyncCall(function () {
        // handle call result
        done();
    });
});

Create a task with serial subtasks:

runner.task('serve', runner.serial('lint', 'build'));

Create a task with parallel subtasks:

runner.task('build', runner.parallel('jade:build', 'sass:build'));

It's possible to use either anonymous or named functions as well:

runner.task('build', runner.parallel('jade:build', 'sass:build', function lessBuild ( done ) {
    // function name "lessBuild" is used as task name
    // otherwise <noname> is printed
    done();
}));

Batch tasks creation:

Object.assign(runner.tasks,
    {
        taskName1: taskFunction1,
        taskName2: taskFunction2
    },
    {
        taskName3: taskFunction3,
        taskName4: taskFunction4
    }
);

Execute a task by name:

runner.run('lint');

Execute a task and handle the result:

runner.run('lint', function ( error ) {
    if ( error ) {
        console.log('the task has failed!');
    }
});

Execute a task as a named or anonymous function:

runner.run(function ( done ) {
    done();
});

Execute task series:

runner.run(runner.parallel('lint', 'build'));

Execute task chain:

// no result check
runner.start();

// hook on task completion
runner.start(function () {
    console.log('finished');
});

// hook on task completion
runner.start(function ( error ) {
    if ( error ) {
        console.log('failed!');
    }
});

Hook on task start/stop events:

runner.addListener('start', function ( event ) {
    // {id: 'lint'}
    console.log(event);
});

runner.addListener('finish', function ( event ) {
    // {id: 'lint', time: 1}
    console.log(event);
});

Contribution

If you have any problems or suggestions please open an issue according to the contribution rules.

License

cjs-runner is released under the MIT License.

Keywords

FAQs

Package last updated on 04 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc