Permalink
Browse files

v0.1.0

  • Loading branch information...
1 parent 5dec010 commit 3d7fcd846f25b6c3a848106bba80a40a5ff7d808 @ericclemmons committed Mar 5, 2013
Showing with 463 additions and 3 deletions.
  1. +3 −0 .gitignore
  2. +14 −0 .jshintrc
  3. +78 −0 Gruntfile.js
  4. +22 −0 LICENSE-MIT
  5. +71 −3 README.md
  6. +48 −0 package.json
  7. +95 −0 tasks/lib/verbosity.js
  8. +36 −0 tasks/verbosity_task.js
  9. +1 −0 test/fixtures/123
  10. +1 −0 test/fixtures/testing
  11. +94 −0 test/verbosity_test.js
View
@@ -0,0 +1,3 @@
+node_modules
+npm-debug.log
+tmp
View
@@ -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
+}
View
@@ -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']);
+
+};
View
@@ -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.
View
@@ -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)_
View
@@ -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"
+ ]
+}
@@ -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);
+};
+
@@ -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);
+ }
+ });
+ });
+
+};
View
@@ -0,0 +1 @@
+1 2 3
@@ -0,0 +1 @@
+Testing
Oops, something went wrong. Retry.

0 comments on commit 3d7fcd8

Please sign in to comment.