grunt-watch-idle

0.1.1 • Public • Published

grunt-watch-idle

Make something when nothing happens.

Getting Started

This plugin requires Grunt ~0.4.5 with grunt-contrib-watch plugin.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-contrib-watch grunt-watch-idle --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-watch-idle');

The "watch_idle" task

Overview

"watch_idle" is a multiTask plugin, configuration objects for various targets must contains timeout integer
and action callback. If watch event not emitted in timeout period, action will be fired, over and over again.

grunt.initConfig({
  watch_idle: {
    foo: {
      timeout: 60 * 60 * 1000,
      action: function() {
        grunt.log.writeln('foo callback invoked after hour of inactivity');
      }
    },
  },
});

When no configuration provided, plugin starts log messages into console on every 15 minutes of idle.

Options

options.off

Type: Any
Default: on

Prevent plugin from loading. GWIDL_OFF environment variable also used for this purpose.
Since plugin loaded automatically, this is a fast way to temporarily disable it.

options.immediate

Type: Any
Default: disabled

Targets starts their countdowns only after first emitted watch event. immediate option allow start timers immediately, but with any grunt task, not watch only.

Usage Examples

Short example with on-screen notifications in Ubuntu.

var spawn = require('child_process').spawn;
 
module.exports = function(grunt) {
  grunt.initConfig({
    watch_idle: {
      visual: {
        timeout: 10 * 60 * 1000,
        action: function() {
          spawn('/usr/bin/notify-send', [
            '-i', '/usr/share/icons/hicolor/32x32/actions/system-restart.png',
            'Where you commits?',
            'Get up, man!'
          ]);
        }
      },
    },
  });
};

More examples in grunt/watch_idle.js.example

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.

Release History

  • 2016-03-24 v0.1.1 Fix Grunt 1.0.0-rc suggestion
  • 2016-01-01   v0.1.0   Happy New Code!

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.1
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.1
    2
  • 0.1.0
    0

Package Sidebar

Install

npm i grunt-watch-idle

Weekly Downloads

2

Version

0.1.1

License

MIT

Last publish

Collaborators

  • domelaz