# expand-target

> Expand target definitions in a declarative configuration.

Latest version **0.6.6** (published 2016-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install expand-target
pnpm add expand-target
yarn add expand-target
bun add expand-target
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.6 |
| Published | 2016-08-11 |
| First published | 2015-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Jon Schlinkert |
| Maintainers | doowb, jonschlinkert |
| Keywords | config, configuration, dest, destination, expand, files, files array, files object, normalize, options, src, src-dest, target, task |

## Links

- npm: https://www.npmjs.com/package/expand-target
- Repository: https://github.com/jonschlinkert/expand-target
- Issues: https://github.com/jonschlinkert/expand-target/issues
- npm.io page: https://npm.io/package/expand-target

## Dependencies (6)

- [base](https://npm.io/package/base.md) ^0.11.1
- [lazy-cache](https://npm.io/package/lazy-cache.md) ^2.0.1
- [base-plugins](https://npm.io/package/base-plugins.md) ^0.4.13
- [expand-files](https://npm.io/package/expand-files.md) ^0.8.4
- [expand-utils](https://npm.io/package/expand-utils.md) ^0.2.2
- [define-property](https://npm.io/package/define-property.md) ^0.2.5

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.6.6 (latest) — 2016-08-11
- 0.6.5 — 2016-07-19
- 0.6.4 — 2016-06-26
- 0.6.3 — 2016-06-12
- 0.6.2 — 2016-06-03
- 0.6.1 — 2016-06-03
- 0.5.3 — 2016-01-06
- 0.5.2 — 2016-01-06
- 0.5.1 — 2015-11-13
- 0.5.0 — 2015-11-13
- 0.4.0 — 2015-11-12
- 0.3.0 — 2015-10-31
- 0.2.3 — 2015-09-04
- 0.2.2 — 2015-09-02
- 0.2.1 — 2015-09-02
- … 5 more at https://npm.io/package/expand-target/versions

## README

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

Expand target definitions in a declarative configuration.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save expand-target
```

## Usage

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

Write declarative "target" definitions similar in concept to those used by [grunt](http://gruntjs.com/) and [make](https://www.gnu.org/software/make/). This is useful for shared configs or to dynamically build-up a configuration that can be passed to any build system (even [gulp](http://gulpjs.com)!).

**Basic example**

```js
target({
  files: {
    'a/': ['*.js'],
    'b/': ['*.js'],
    'c/': ['*.js']
  }
});
```

**results in**

```js
{
  files: [
    {
      src: ['examples.js', 'index.js'],
      dest: 'a/'
    },
    {
      src: ['examples.js', 'index.js'],
      dest: 'b/'
    },
    {
      src: ['examples.js', 'index.js'],
      dest: 'c/'
    }
  ]
}
```

> the same example with `expand: true` defined on the options

```js
target({
  options: { expand: true },
  files: {
    'a/': ['*.js'],
    'b/': ['*.js'],
    'c/': ['*.js']
  }
});
```

**results in**

```js
{
  options: {
    expand: true
  },
  files: [
    {
      src: ['examples.js'],
      dest: 'a/examples.js'
    },
    {
      src: ['index.js'],
      dest: 'a/index.js'
    },
    {
      src: ['examples.js'],
      dest: 'b/examples.js'
    },
    {
      src: ['index.js'],
      dest: 'b/index.js'
    },
    {
      src: ['examples.js'],
      dest: 'c/examples.js'
    },
    {
      src: ['index.js'],
      dest: 'c/index.js'
    }
  ]
}
```

See [more examples](./examples.md). Visit [expand-files](https://github.com/jonschlinkert/expand-files) for the full range of options and documentation.

## Plugins

Plugins must be registered before the configuration is expanded, which means you need to use the `expand` method instead of passing your config directly to the constructor.

```js
var target = new Target({cwd: 'foo'});

target
  .use(foo)
  .use(bar)
  .use(baz);

target.expand({
  src: '*.js',
  dest: ''
});
```

### Writing plugins

Plugins are just functions where the only parameter exposed is the current "context".

**Examples**

In the following plugin, `config` is the target instance:

```js
target.use(function(config) {
  config.foo = 'bar';
});
console.log(target.foo);
//=> 'bar'
```

To have the plugin called in a "child" context, like for iterating over files nodes as they're expanded, just return the plugin function until you get the node you want:

```js
target.use(function fn(config) {
  if (!config.node) return fn;
  console.log(config);
});
```

**Contexts**

To see all available contexts, just do the following:

```js
target.use(function fn(config) {
  console.log('-----', config._name, '----');
  console.log(config);
  console.log('---------------------------');
  return fn;
});
```

## Options

Any option from [expand-files](https://github.com/jonschlinkert/expand-files) may be used. Please see that project for the full range of options and documentation.

### options properties

The below "special" properties are fine to use either on an `options` object or on the root of the object passed to `expand-files`.

Either way they will be normalized onto the `options` object to ensure that [globby](https://github.com/sindresorhus/globby) and consuming libraries are passed the correct arguments.

**special properties**

* `base`
* `cwd`
* `destBase`
* `expand`
* `ext`
* `extDot`
* `extend`
* `flatten`
* `rename`
* `process`
* `srcBase`

**example**

Both of the following will result in `expand` being on the `options` object.

```js
files({src: '*.js', dest: 'dist/', options: {expand: true}});
files({src: '*.js', dest: 'dist/', expand: true});
```

## About

### Related projects

* [expand-config](https://www.npmjs.com/package/expand-config): Expand tasks, targets and files in a declarative configuration. | [homepage](https://github.com/jonschlinkert/expand-config "Expand tasks, targets and files in a declarative configuration.")
* [expand-files](https://www.npmjs.com/package/expand-files): Expand glob patterns in a declarative configuration into src-dest mappings. | [homepage](https://github.com/jonschlinkert/expand-files "Expand glob patterns in a declarative configuration into src-dest mappings.")
* [expand-target](https://www.npmjs.com/package/expand-target): Expand target definitions in a declarative configuration. | [homepage](https://github.com/jonschlinkert/expand-target "Expand target definitions in a declarative configuration.")
* [expand-task](https://www.npmjs.com/package/expand-task): Expand and normalize task definitions in a declarative configuration. | [homepage](https://github.com/jonschlinkert/expand-task "Expand and normalize task definitions in a declarative configuration.")
* [files-objects](https://www.npmjs.com/package/files-objects): Expand files objects into src-dest mappings. | [homepage](https://github.com/jonschlinkert/files-objects "Expand files objects into src-dest mappings.")

### Contributing

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

### Building docs

_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_

To generate the readme and API documentation with [verb](https://github.com/verbose/verb):

```sh
$ npm install -g verb verb-generate-readme && verb
```

### 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/jonschlinkert/expand-target/blob/master/LICENSE).

***

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

---
_Source: https://npm.io/package/expand-target · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
