An open API service indexing awesome lists of open source software.

https://github.com/generate/generate-target

Generate the files in a declarative "target" configuration.
https://github.com/generate/generate-target

Last synced: 2 months ago
JSON representation

Generate the files in a declarative "target" configuration.

Awesome Lists containing this project

README

          

# generate-target [![NPM version](https://img.shields.io/npm/v/generate-target.svg?style=flat)](https://www.npmjs.com/package/generate-target) [![NPM downloads](https://img.shields.io/npm/dm/generate-target.svg?style=flat)](https://npmjs.org/package/generate-target) [![Build Status](https://img.shields.io/travis/generate/generate-target.svg?style=flat)](https://travis-ci.org/generate/generate-target)

Plugin for automatically creating tasks from declarative `target` configurations. Works with generate, assemble, verb, or any other base application with plugin support.

## Usage

Can be used with any [base](https://github.com/node-base/base) application, including [assemble](https://github.com/assemble/assemble), [generate](https://github.com/generate/generate), and [update](https://github.com/update/update).

```js
var target = require('generate-target');
```

## Example

```js
var Base = require('base');
var targets = require('base-target');
var app = new Base({isApp: true});
app.use(targets());

// create a target
app.target('abc', {
src: 'templates/*.hbs',
dest: 'site',
});

// get a target
app.target('abc')
.generate({cwd: 'fo'}) // build the files in a target
.on('error', console.error)
.on('end', function() {
console.log('done!');
});
```

See the [expand-target](https://github.com/jonschlinkert/expand-target) library for additional information and API documentation.

## API

### [.targetSeries](index.js#L86)

Asynchronously generate files from a declarative [target](https://github.com/jonschlinkert/expand-target) configuration.

**Params**

* `target` **{Object}**: Target configuration object.
* `next` **{Function}**: Optional callback function. If not passed, `.targetStream` will be called and a stream will be returned.

**Example**

```js
var Target = require('target');
var target = new Target({
options: {cwd: 'source'},
src: ['content/*.md']
});

app.targetSeries(target, function(err) {
if (err) console.log(err);
});
```

### [.targetStream](index.js#L124)

Generate files from a declarative [target](https://github.com/jonschlinkert/expand-target) configuration.

**Params**

* `target` **{Object}**: [target](https://github.com/jonschlinkert/expand-target) configuration object.
* `returns` **{Stream}**: returns a stream with all processed files.

**Example**

```js
var Target = require('target');
var target = new Target({
options: {},
files: {
src: ['*'],
dest: 'foo'
}
});

app.targetStream(target)
.on('error', console.error)
.on('end', function() {
console.log('done!');
});
```

## Tasks

If the instance has a `task` method, a task is automatically created for each target.

**Example**

```js
app.target('docs', {src: 'src/docs/*.md', dest: 'docs'});
app.target('site', {src: 'src/site/*.hbs', dest: 'site'});

app.build(['docs', 'site'], function(err) {
if (err) return console.log(err);
console.log('done!');
});
```

**Disable auto-tasks**

Pass options to the plugin to disable this feature.

```js
app.use(targets({tasks: false}));
```

## About

### Related projects

* [base-scaffold](https://www.npmjs.com/package/base-scaffold): Base plugin that adds support for generating files from a declarative scaffold configuration. | [homepage](https://github.com/node-base/base-scaffold "Base plugin that adds support for generating files from a declarative scaffold configuration.")
* [base-target](https://www.npmjs.com/package/base-target): Plugin that adds support for defining declarative `target` configurations that directly map to functional tasks. | [homepage](https://github.com/node-base/base-target "Plugin that adds support for defining declarative `target` configurations that directly map to functional tasks.")
* [generate-scaffold](https://www.npmjs.com/package/generate-scaffold): Generate a scaffold from a declarative configuration. | [homepage](https://github.com/generate/generate-scaffold "Generate a scaffold from a declarative configuration.")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Running tests

Install dev dependencies:

```sh
$ npm install -d && npm test
```

### Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

### License

Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/generate/generate-target/blob/master/LICENSE).

***

_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on July 19, 2016._