A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.npmjs.com/package/composer below:

composer - npm

composer

Run and compose async tasks. Easily define groups of tasks to run in series or parallel.

Please consider following this project's author, Brian Woodward, and consider starring the project to show your ❤️ and support.

(TOC generated by verb using markdown-toc)

Install

Install with npm:

$ npm install --save composer

Usage

const Composer = require('composer');

const composer = new Composer();

 

composer.task('foo', callback => {

  callback(); 

});

composer.task('bar', callback => {

  callback(); 

});

 

composer.task('baz', ['foo'. 'bar']);

 

composer.build('baz')

  .then(() => console.log('done!'))

  .catch(console.error);

API .factory

Factory for creating a custom Tasks class that extends the given Emitter. Or, simply call the factory function to use the built-in emitter.

Params

Example

const Emitter = require('events');

const Tasks = require('composer/lib/tasks')(Emitter);

const Tasks = require('composer/lib/tasks')();

const composer = new Tasks();

Tasks

Create an instance of Tasks with the given options.

Params

Example

const Tasks = require('composer').Tasks;

const composer = new Tasks();

.task

Define a task. Tasks run asynchronously, either in series (by default) or parallel (when options.parallel is true). In order for the build to determine when a task is complete, one of the following things must happen: 1) the callback must be called, 2) a promise must be returned, or 3) a stream must be returned. Inside tasks, the "this" object is a composer Task instance created for each task with useful properties like the task name, options and timing information, which can be useful for logging, etc.

Params

Example

app.task('default', cb => {

  

  cb();

});

app.task('default', () => {

  return Promise.resolve(null);

});

app.task('default', function() {

  return vfs.src('foo/*.js');

});

.build

Run one or more tasks.

Params

Example

const build = app.series(['foo', 'bar', 'baz']);

build().then(console.log).catch(console.error);

build(function() {

  if (err) return console.error(err);

});

.series

Compose a function to run the given tasks in series.

Params

Example

const build = app.series(['foo', 'bar', 'baz']);

build().then(console.log).catch(console.error);

build(function() {

  if (err) return console.error(err);

});

.parallel

Compose a function to run the given tasks in parallel.

Params

Example

const build = app.parallel(['foo', 'bar', 'baz']);

build().then(console.log).catch(console.error);

build(function() {

  if (err) return console.error(err);

});

app.task('default', build);

.create

Static method for creating a custom Tasks class with the given `Emitter.

Params

.create

Static factory method for creating a custom Composer class that extends the given Emitter.

Params

Example

const Composer = require('composer');

const composer = new Composer();

 

const Emitter = require('some-emitter');

const CustomComposer = Composer.create(Emitter);

const composer = new CustomComposer();

Params

Example

const composer = new Composer();

Create a wrapped generator function with the given name, config, and fn.

Params

Returns true if the given value is a Composer generator object.

Params

.register

Alias to .setGenerator.

Params

Example

app.register('foo', function(app, base) {

  

  

});

.generator

Get and invoke generator name, or register generator name with the given val and options, then invoke and return the generator instance. This method differs from .register, which lazily invokes generator functions when .generate is called.

Params

Example

app.generator('foo', function(app, options) {

  

  

});

.setGenerator

Store a generator by file path or instance with the given name and options.

Params

Example

app.setGenerator('foo', function(app, options) {

  

  

});

.getGenerator

Get generator name from app.generators, same as [findGenerator], but also invokes the returned generator with the current instance. Dot-notation may be used for getting sub-generators.

Params

Example

const foo = app.getGenerator('foo');

 

const baz = app.getGenerator('foo.bar.baz');

.findGenerator

Find generator name, by first searching the cache, then searching the cache of the base generator. Use this to get a generator without invoking it.

Params

Example

const foo = app.findGenerator('foo');

 

const foo = app.findGenerator('generate-foo');

Params

Example

console.log(app.hasGenerator('foo'));

console.log(app.hasGenerator('foo.bar'));

.generate

Run one or more tasks or sub-generators and returns a promise.

Params

Events

Example

app.generate('foo', ['bar', 'baz']);

 

app.generate('foo:bar,baz');

 

app.generate('foo');

 

app.generate();

.toAlias

Create a generator alias from the given name. By default, generate- is stripped from beginning of the generator name.

Params

Example

const app = new Generate({ toAlias: require('camel-case') });

.isGenerators

Returns true if every name in the given array is a registered generator.

Params

.formatError

Format task and generator errors.

Params

.disableInspect

Disable inspect. Returns a function to re-enable inspect. Useful for debugging.

.base

Get the first ancestor instance of Composer. Only works if generator.parent is defined on child instances.

.name

Get or set the generator name.

Params

.alias

Get or set the generator alias. By default, the generator alias is created by passing the generator name to the .toAlias method.

Params

.namespace

Get the generator namespace. The namespace is created by joining the generator's alias to the alias of each ancestor generator.

Params

.depth

Get the depth of a generator - useful for debugging. The root generator has a depth of 0, sub-generators add 1 for each level of nesting.

Composer#parse

Static method that returns a function for parsing task arguments.

Params

Composer#isGenerator

Static method that returns true if the given val is an instance of Generate.

Params

Composer#create

Static method for creating a custom Composer class with the given `Emitter.

Params

Composer#Tasks

Static getter for getting the Tasks class with the same Emitter class as Composer.

Params

Composer#Task

Static getter for getting the Task class.

Example

const { Task } = require('composer');

Events task

app.on('task', function(task) {

  switch (task.status) {

    case 'starting':

      

      break;

    case 'finished':

      

      break;

  }

});

task-pending

Emitted after a task is registered.

task-preparing

Emitted when a task is preparing to run, right before it's called. You can use this event to dynamically skip tasks by updating task.skip to true or a function.

Release history

See the changelog.

About Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

Contributors Author

Brian Woodward

License

Copyright © 2018, Brian Woodward. Released under the MIT License.

This file was generated by verb-generate-readme, v0.8.0, on November 11, 2018.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4