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 - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

license.md

235

index.js
/**
* @author Stanislav Kalashnik <darkpark.main@gmail.com>
* @license GNU GENERAL PUBLIC LICENSE Version 3
* @license The MIT License (MIT)
* @copyright Stanislav Kalashnik <darkpark.main@gmail.com>
*/

@@ -8,3 +8,232 @@

var Emitter = require('cjs-emitter'),
parallel = require('cjs-async/parallel'),
serial = require('cjs-async/serial');
/**
*
*
* @constructor
* @extends Emitter
*/
function Runner () {
console.assert(typeof this === 'object', 'must be constructed via new');
// parent constructor call
Emitter.call(this);
this.tasks = {};
this.tree = {};
//this.running = {};
}
// inheritance
Runner.prototype = Object.create(Emitter.prototype);
Runner.prototype.constructor = Runner;
/**
* Remove all attributes from the model.
*
* @param {string} id task name
* @param {function} body task method
*
* @return {function} task
*
* @fires Runner#clear
*/
Runner.prototype.task = function ( id, body ) {
if ( id && typeof id === 'string' && body && typeof body === 'function' ) {
this.tasks[id] = body;
body.id = id;
//console.log(body);
}
return body;
};
//function done ( instance, fn ) {
// // mark finished
// fn.running = false;
//
// // there are some listeners
// if ( instance.events['finish'] ) {
// // notify listeners
// instance.emit('finish', {id: fn.id});
// //console.log('finish', fn.id);
// }
//}
//
//function wrap ( instance, fn ) {
// // is there a callback for task?
// if ( fn.length === 0 ) {
// // start task sync
// fn();
// // finish
// done();
// } else {
// // start task async
// fn(done);
// }
//}
Runner.prototype.wrap = function ( task ) {
var self = this,
time;
return function ( cb ) {
var done = function () {
// mark finished
task.running = false;
time = Date.now() - time;
/*console.log('finish', task.id, time);/**/
// there are some listeners
if ( self.events['finish'] ) {
// notify listeners
self.emit('finish', {id: task.id, time: time});
}
// callback from user or
if ( cb && typeof cb === 'function' ) {
cb.apply(null, arguments);
}
},
result;
// exist and not already executing
if ( task && !task.running ) {
// mark to prevent multiple starts
task.running = true;
time = Date.now();
/*console.log('start', task.id);/**/
// there are some listeners
if ( self.events['start'] ) {
// notify listeners
self.emit('start', {id: task.id});
}
// is there a callback for task?
if ( task.length === 0 ) {
// start task sync
result = task();
// finish
done();
} else {
//console.log(task.id);
// start task async
result = task(done);
}
}
return result;
};
};
Runner.prototype.parallel = function () {
var self = this,
tasks = Array.prototype.slice.call(arguments),
func;
if ( tasks.length === 0 ) {
return null;
}
func = function ( done ) {
var readyTasks = [];
// wrap not running tasks only
tasks.forEach(function ( task ) {
task = self.tasks[task] || task;
if ( task && !task.running ) {
readyTasks.push(
function ( done ) {
return self.run(task, done);
}
);
}
});
parallel(readyTasks, done);
};
func.group = true;
func.type = 'parallel';
func.children = tasks;
return func;
};
Runner.prototype.serial = function () {
var self = this,
tasks = Array.prototype.slice.call(arguments),
func;
if ( tasks.length === 0 ) {
return null;
}
func = function ( done ) {
var readyTasks = [];
// wrap not running tasks only
tasks.forEach(function ( task ) {
task = self.tasks[task] || task;
if ( task && !task.running ) {
readyTasks.push(
function ( done ) {
return self.run(task, done);
}
);
}
});
serial(readyTasks, done);
};
func.group = true;
func.type = 'serial';
func.children = tasks;
return func;
};
/**
* Start task execution.
*
* @param {function|string} task task to run
* @param {function} [done] callback on task finish
*
* @return {*} task execution result
*/
Runner.prototype.run = function ( task, done ) {
var result;
task = this.tasks[task] || task;
if ( typeof task === 'function' && !task.running ) {
result = this.wrap(task)(done);
}
return result;
};
Runner.prototype.start = function ( done ) {
this.run(this.tasks.default, done);
};
// public
module.exports = {};
module.exports = Runner;

26

package.json
{
"name": "cjs-runner",
"version": "1.0.0",
"description": "Task runner.",
"version": "1.1.0",
"description": "Simple task runner.",
"author": {

@@ -9,8 +9,22 @@ "name": "Stanislav Kalashnik",

},
"repository": "cjssdk/runner",
"repository": {
"type": "git",
"url": "https://github.com/cjssdk/runner.git"
},
"scripts": {
"lint": "eslint ./*.js",
"test": "node ./tests/main.js",
"lint": "eslint .",
"mocha": "node ./tests/main.js",
"test": "npm run mocha && npm run lint",
"jsdoc": "jsdoc --destination doc *.js readme.md"
},
"dependencies": {
"cjs-async": "1.*.*",
"cjs-emitter": "1.*.*"
},
"devDependencies": {
"cjs-eslint-config": "1.*.*",
"eslint": "3.*.*",
"mocha": "3.*.*",
"should": "11.*.*"
},
"keywords": [

@@ -24,3 +38,3 @@ "commonjs",

],
"license": "GPL-3.0"
"license": "MIT"
}
Task runner
===========
[![Build Status](https://img.shields.io/travis/cjssdk/runner.svg?style=flat-square)](https://travis-ci.org/cjssdk/runner)
[![NPM version](https://img.shields.io/npm/v/cjs-runner.svg?style=flat-square)](https://www.npmjs.com/package/cjs-runner)
[![Dependencies Status](https://img.shields.io/david/cjssdk/runner.svg?style=flat-square)](https://david-dm.org/cjssdk/runner)
[![build status](https://img.shields.io/travis/cjssdk/runner.svg?style=flat-square)](https://travis-ci.org/cjssdk/runner)
[![npm version](https://img.shields.io/npm/v/cjs-runner.svg?style=flat-square)](https://www.npmjs.com/package/cjs-runner)
[![dependencies status](https://img.shields.io/david/cjssdk/runner.svg?style=flat-square)](https://david-dm.org/cjssdk/runner)
[![devDependencies status](https://img.shields.io/david/dev/cjssdk/runner.svg?style=flat-square)](https://david-dm.org/cjssdk/runner?type=dev)
[![Gitter](https://img.shields.io/badge/gitter-join%20chat-blue.svg?style=flat-square)](https://gitter.im/DarkPark/cjssdk)
[![RunKit](https://img.shields.io/badge/RunKit-try-yellow.svg?style=flat-square)](https://runkit.com/npm/cjs-runner)

@@ -25,6 +27,26 @@

```js
var runner = require('cjs-runner');
var Runner = require('cjs-runner'),
runner = new Runner();
```
Create a simple task:
```js
runner.task('make', function () {
// some actions
});
```
```js
t1 = runner.task('static', runner.serial('jade:build', 'sass:build'));
t1 = runner.task({
name: 'static',
dependency: ['jade:build', 'sass:build']
});
runner.start(['build']);
```
## Contribution ##

@@ -38,2 +60,2 @@

`cjs-runner` is released under the [GPL-3.0 License](http://opensource.org/licenses/GPL-3.0).
`cjs-runner` is released under the [MIT License](license.md).

Sorry, the diff of this file is not supported yet

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