# gulp-count

> count files in vinyl streams

Latest version **1.0.0** (published 2018-01-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-count
pnpm add gulp-count
yarn add gulp-count
bun add gulp-count
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-01-02 |
| First published | 2015-01-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Palantir Technologies |
| Maintainers | giladgray |
| Keywords | gulp, gulpplugin, count, debug, files |

## Links

- npm: https://www.npmjs.com/package/gulp-count
- Repository: https://github.com/palantir/gulp-count
- Issues: https://github.com/palantir/gulp-count/issues
- npm.io page: https://npm.io/package/gulp-count

## Dependencies (4)

- [xtend](https://npm.io/package/xtend.md) ^4.0.1
- [through2](https://npm.io/package/through2.md) ^2.0.3
- [ansi-colors](https://npm.io/package/ansi-colors.md) ^1.0.1
- [lodash.template](https://npm.io/package/lodash.template.md) ^4.4.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-01-02
- 0.3.0 — 2016-09-15
- 0.2.0 — 2016-02-03
- 0.1.0 — 2015-01-23
- 0.0.2 — 2015-01-23
- 0.0.1 — 2015-01-23

## README

# gulp-count [![npm](https://img.shields.io/npm/v/gulp-count.svg)](https://www.npmjs.com/package/gulp-count) [![CircleCI](https://circleci.com/gh/palantir/gulp-count.svg?style=svg)](https://circleci.com/gh/palantir/gulp-count)

> Count files in vinyl streams. Log pretty messages.

![gulp-count in action](screenshot.png)

This plugin solves a similar problem to [gulp-debug](https://github.com/sindresorhus/gulp-debug) but is designed as an actual permanent part of your workflow, not just a debug tool (though it still makes a great debug tool!). As such, it provides more control over logging to customize as needed.

## Usage
First, install `gulp-count` as a development dependency:

```shell
> npm install --save-dev gulp-count
```

Then, add it to your `gulpfile.js`:

```javascript
var count = require('gulp-count');

gulp.task('copy', function() {
    gulp.src('assets/**.*')
        .pipe(gulp.dest('build'))
        .pipe(count('## assets copied'));
});
```


## API
gulp-count can be called with a string message template, an options object, or both.

```javascript
gulp.src('*.html')
    .pipe(count()) // logs "36 files"
    .pipe(count('<%= counter %> HTML files'))  // logs "36 HTML files"
    .pipe(count('found ## pages', {logFiles: true})) // logs each path and "found 36 pages"
    .pipe(count({
        message: '<%= files %>? That\'s ## too many!'
        logger: (msg) -> alert(msg) // alerts "36 files? That's 36 too many!"
    });
```

### `count(options?)`
### `count(message, options?)`

##### `options.message: boolean | string = "<%= files %>"`

Template string for total count message, passed through [`gutil.template`](https://github.com/gulpjs/gulp-util#templatestring-data).

Template can use two variables:

1. `counter` - the number of files encountered in this stream,
2. `files` - a correctly pluralized string of the format "X file[s]" where X is `counter`.

The template also expands the shorthand `"##"` to `"<%= counter %>"`.

An explicit `false` value will disable the message (use `logFiles` or `logEmpty` instead).

##### `options.logFiles: boolean | string = false`

Whether to log each file path as it is encountered. `options.cwd` determines base path for logging.

If a string is provided then it is used as the message template. Template receives two variables:

1. `file` - the current Vinyl file instance
2. `path` - file path resolved relative to `options.cwd` and colored yellow.

##### `options.logEmpty: boolean | string = false`

Whether to log the message when the stream is empty.

If a string is provided then it is used as the message template and receives the same variables as `options.message`.

Setting `{ message: false, logEmpty: true }` will log _if and only if_ the stream is empty.

##### `options.title: string`

String prepended to every message to distinguish the output of multiple instances logging at once.
A falsy value will print nothing.

##### `options.cwd: string = ""`

Current working directory against which file paths are resolved in template strings.

##### `options.logger: (message) => any = gutil.log`

Logger function, called with each formatted message. Defaults to gulp-util's [`log(msg...)`](https://github.com/gulpjs/gulp-util#logmsg) function.


## License
MIT &copy; [Palantir Technologies](http://palantir.com)

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