Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ericclemmons committed Mar 5, 2013
1 parent 5dec010 commit 3d7fcd8
Show file tree
Hide file tree
Showing 11 changed files with 463 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules
npm-debug.log
tmp
14 changes: 14 additions & 0 deletions .jshintrc
@@ -0,0 +1,14 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"boss": true,
"eqnull": true,
"node": true,
"es5": true
}
78 changes: 78 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,78 @@
/*
* grunt-verbosity
* https://github.com/ericclemmons/grunt-verbosity
*
* Copyright (c) 2013 Eric Clemmons
* Licensed under the MIT license.
*/

'use strict';

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({

jshint: {
all: [
'Gruntfile.js',
'tasks/*.js',
'<%= nodeunit.tests %>',
],
options: {
jshintrc: '.jshintrc',
},
},

// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp'],
},

copy: {
fixtures: {
files: [
{ expand: true, cwd: 'test/fixtures/', src: '**', dest: 'tmp/' }
]
}
},

// Configuration to be run (and then tested).
verbosity: {
hidden: {
tasks: ['copy']
},
oneline: {
options: { mode: 'oneline' },
tasks: ['copy:fixtures']
},
normal: {
options: { mode: 'normal' },
tasks: ['copy:fixtures']
}
},

// Unit tests.
nodeunit: {
tests: ['test/*_test.js'],
},

});

// Actually load this plugin's task(s).
grunt.loadTasks('tasks');

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-nodeunit');

// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
grunt.registerTask('test', ['clean', 'verbosity:hidden', 'copy', 'verbosity:oneline', 'copy', 'verbosity:normal', 'copy', 'nodeunit']);

// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);

};
22 changes: 22 additions & 0 deletions LICENSE-MIT
@@ -0,0 +1,22 @@
Copyright (c) 2013 Eric Clemmons

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
74 changes: 71 additions & 3 deletions README.md
@@ -1,4 +1,72 @@
grunt-mute
==========
# grunt-verbosity

Mute (quiet) output from specific, noisy grunt tasks!
> Adjust verbosity for individual grunt tasks
This plugin simply hooks until `grunt.log.writeln` to allow you to cleanup log output.


## Getting Started

This plugin requires Grunt `~0.4.0`

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-verbosity --save-dev
```

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

```js
grunt.loadNpmTasks('grunt-verbosity');
```


## The `verbosity` task

### Usage
In your project's Gruntfile, add a section named `verbosity` to the data object passed into `grunt.initConfig()`.

```js
grunt.initConfig({
verbosity: {
// Default
option1: {
// options: { mode: 'hidden' },
tasks: ['copy']
},

// Output is rewritten on the line to show progress but save space
option2: {
options: { mode: 'oneline' },
tasks: ['copy:files']
},

// Output is normal. Useful for debugging without commenting out the whole block
option3: {
options: { mode: 'normal' },
tasks: ['copy:something']
}
},
})
```


### Options

#### options.mode
Type: `String`
Default value: `normal`

A string value to determine how to modify `grunt.log.writeln` output.

- `hidden` (Default): See the task get executed, but not its output
- `oneline`: See the output overwrite the same line to conserve space
- `normal`: See the output without modification. Useful for debugging.


## 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)_
48 changes: 48 additions & 0 deletions package.json
@@ -0,0 +1,48 @@
{
"name": "grunt-verbosity",
"description": "Adjust verbosity for individual grunt tasks",
"version": "0.1.0",
"homepage": "https://github.com/ericclemmons/grunt-verbosity",
"author": {
"name": "Eric Clemmons",
"email": "eric@smarterspam.com"
},
"repository": {
"type": "git",
"url": "git://github.com/ericclemmons/grunt-verbosity.git"
},
"bugs": {
"url": "https://github.com/ericclemmons/grunt-verbosity/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/ericclemmons/grunt-verbosity/blob/master/LICENSE-MIT"
}
],
"main": "Gruntfile.js",
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "grunt test"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt": "~0.4.0"
},
"peerDependencies": {
"grunt": "~0.4.0"
},
"keywords": [
"gruntplugin",
"quiet",
"log",
"verbose",
"verbosity",
"mute",
"output"
]
}
95 changes: 95 additions & 0 deletions tasks/lib/verbosity.js
@@ -0,0 +1,95 @@
/*
* verbosity
*
* Copyright (c) 2013 Eric Clemmons
* Licensed under the MIT license.
*/

'use strict';

module.exports = Verbosity;

function Verbosity(logger, mode, targets) {
this.logger = logger;
this.mode = (mode || 'normal').toUpperCase();
this.targets = targets;
this.enabled = false;

this.disable = function() {
this.enabled = logger.muted = false;
};

this.enable = function() {
this.enabled = logger.muted = true;
};

this.before = function(message) {
if (!message) {
return false;
}

if (Verbosity.match(message)) {
var was = this.enabled;

this.disable();

// Finish last modified line
if (was) {
logger.write("\n");
}
} else if (this.enabled && message) {
this.disable();
logger.write(this.wrap(message));
this.enable();
}
};

this.after = function(message) {
if (!message) {
return false;
}

var tasks = Verbosity.match(message);

if (tasks) {
var raw = tasks[0];
var specific = tasks[1];
var generic = tasks[2];
var targets = this.targets.filter(function(target) {
return tasks.indexOf(target) !== -1;
});

// Start modifying verbosity for expected targets
if (targets.length) {
this.enable();
}
}
};

this.wrap = function(message) {
var wrapper = Verbosity.modes[this.mode];

return wrapper(message);
};

if (!Verbosity.hasMode(this.mode)) {
throw new Error('Verbosity mode not defined: ' + this.mode);
}
};

Verbosity.modes = {
'HIDDEN': function(message) { return null; },
'NORMAL': function(message) { return message + "\n"; },
'ONELINE': function(message) { return message + "\r"; }
};

Verbosity.PATTERN = /Running\s\"(.+)\"\s\((.+)\)\stask/;

Verbosity.hasMode = function(mode) {
return mode && Verbosity.modes.hasOwnProperty(mode);
};

Verbosity.match = function(message) {
return message && message.match(Verbosity.PATTERN);
};

36 changes: 36 additions & 0 deletions tasks/verbosity_task.js
@@ -0,0 +1,36 @@
/*
* grunt-verbosity
* https://github.com/ericclemmons/grunt-verbosity
*
* Copyright (c) 2013 Eric Clemmons
* Licensed under the MIT license.
*/

'use strict';

var Verbosity = require('./lib/verbosity');

module.exports = function(grunt) {

grunt.registerMultiTask('verbosity', 'Adjust verbosity for individual grunt tasks', function(target) {
var name = this.name || 'verbosity';
var hooker = grunt.util.hooker;
var settings = this.options({
mode: 'HIDDEN'
});

this.requiresConfig([name, this.target, 'tasks'].join('.'));

var verbosity = new Verbosity(grunt.log, settings.mode, this.data.tasks);

hooker.hook(grunt.log, 'writeln', {
pre: function(message) {
verbosity.before(message);
},
post: function(result, message) {
verbosity.after(message);
}
});
});

};
1 change: 1 addition & 0 deletions test/fixtures/123
@@ -0,0 +1 @@
1 2 3
1 change: 1 addition & 0 deletions test/fixtures/testing
@@ -0,0 +1 @@
Testing

0 comments on commit 3d7fcd8

Please sign in to comment.