# grunt-tail-wait

> Allows grunt to tail a file and wait for a specific keyword or phrase to appear.

Latest version **0.3.0** (published 2016-10-31) · 0 weekly downloads

## Install

```sh
npm install grunt-tail-wait
pnpm add grunt-tail-wait
yarn add grunt-tail-wait
bun add grunt-tail-wait
```

## 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.3.0 |
| Published | 2016-10-31 |
| First published | 2015-06-05 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jason Dryhurst-Smith |
| Maintainers | tigerswithguitars |
| Keywords | gruntplugin |

## Links

- npm: https://www.npmjs.com/package/grunt-tail-wait
- Repository: https://github.com/jasond-s/grunt-tail-wait
- Homepage: http://www.jasonds.co.uk/blog/grunt-tail-wait
- npm.io page: https://npm.io/package/grunt-tail-wait

## Dependencies (1)

- [tail](https://npm.io/package/tail.md) ^0.4.0

## Recent versions

- 0.3.0 (latest) — 2016-10-31
- 0.2.5 — 2015-06-17
- 0.2.2 — 2015-06-17
- 0.2.1 — 2015-06-17
- 0.1.4 — 2015-06-08
- 0.1.2 — 2015-06-05
- 0.1.1 — 2015-06-05
- 0.1.0 — 2015-06-05

## README

# grunt-tail-wait

> Allows grunt to tail a file and wait for a speciic line before continuing to the next task.

## Getting Started
This plugin requires Grunt `~0.4.5`

If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

```shell
npm install grunt-tail-wait --save-dev
```

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

```js
grunt.loadNpmTasks('grunt-tail-wait');
```

## The "tail_wait" task

### Overview
In your project's Gruntfile, add a section named `tail_wait` to the data object passed into `grunt.initConfig()`.

```js
grunt.initConfig({
  tail_wait: {
    namedOptions: {
      fileName: 'path/to/your/file.log',  // Required, this is the file to tail.
      regex: 'keyword',                   // Required, this is keyword/phrase you are waiting for.

      timeout: 1              // defaults to 30 seconds,
      lineSeparator: 'string' // defaults to '\n',

      fromBeginning: false,           // defaults to false.
      forceWatchFromBeginning: false, // defaults to false.
      printMatch: false,              // defaults to false.
    }
  },
});
```

Or if you want to wait for multiple files or need to use a grub string to select an unknown file path.

```js
grunt.initConfig({
  tail_wait: {
    namedOptions: {
      files: [{
        expand: true,
        cwd: './',
        src: ['./*.your.grub.string'],
        dest: './',
        ext: '.string'
      }],
      options: {
        // fileName: 'path/to/your/file.log', // This is no longer required
        regex: 'keyword',                     // Required, this is keyword/phrase you are waiting for.

        timeout: 1              // defaults to 30 seconds,
        lineSeparator: 'string' // defaults to '\n',

        fromBeginning: false,           // defaults to false.
        forceWatchFromBeginning: false, // defaults to false.
        printMatch: false,              // defaults to false.
      }
    }
  },
});
```


1. `fromBeginning` - Specified whether from the first file change detected by the watcher you would like to read the file fro mthe beginning.
2. `forceWatchFromBeginning` - Forces a file change by writting a Unicode U+0020 to the end of the file. This may be useful if the file you wish to watch may have already been finished writting to. Obviously, be aware this is, although minimally, changing the file.
3. `printMatch` - Specifies whether the line matching the regex should be printed out to the console.  This may be useful if the logfile contains an id or url that you'd like to print to the console at start up.


### Usage Examples

#### Custom Options

In this example, we are tailing a log file to look for a phrase before continuing. Here we are waiting for an application to report that the initialisation is complete.

Once this phrase has been found then grunt will continue to the next task.

```js
grunt.initConfig({
  tail_wait: {
    dev: {
      fileName: path.join(__dirname, 'dist/message.log'), // Watch a messages log file
      regex: 'init complete',                             // Wait for the initialisation to complete.

      timeout: 10000 ,      // Wait for 10secs, set in ms.
      lineSeparator: "\r\n" // Use some exotic line endings for the tail.
    }
  },
});
```

Or if the log file maybe has some generated string that is not known before start up. This is useful if you are using something like log4j or similar that might generate multiple files and rollover existing files during operation.


```js
grunt.initConfig({
  tail_wait: {
    dev:
      files: [{
        expand: true,
        cwd: './',
        src: ['./*.log.*'], // Where * represents an unknown string.
        dest: './',
        ext: '.log'
      }],
      options : {
        regex: 'init complete',                             // Wait for the initialisation to complete.

        timeout: 10000 ,      // Wait for 10secs, set in ms.
        lineSeparator: "\r\n" // Use some exotic line endings for the tail.
      }
    }
  },
});
```


## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).

## Release History
_(Nothing yet)_

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