Skip to content

buildfirst/grunt-wordcount

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Writing Your Own Task: grunt-wordcount

This repository is part of the JavaScript Application Design: A Build First Approach book's code samples, the full original for the code samples can be found here. You can learn more about the book itself here.

This tutorial is part of the code samples accompanying the book in the appendix Introduction to Grunt, which walks you through the kind of things you can do, using Grunt.

You might want to create your own Grunt tasks to help you shape your workflows. This example shows you how to do just that.

For the code in the book to work as a Grunt plugin, I just placed it inside an exported task function, like below.

module.exports = function (grunt) {
  // register task
};

Which is pretty much the same pattern we see in a Gruntfile.js. Learn more about Grunt plugins here.

The walkthrough itself can be found in the book.

Below is how this README would actually look like if I were serious about open-sourcing it.

grunt-wordcount

Grunt task to count words and set a word count threshold.

Check for updates in the changelog.

Install

To consume it, install it from npm.

npm i -D grunt-wordcount

Read quick tips about npm.

Usage

Pick which files to count words from. Provide an optional threshold. If a threshold is provided, the task will fail unless it counts less words than that.

wordcount: {
  everything: {
    files: {
      src: ['**/*', '!node_modules/**']
    }
  },
  capped: {
    files: {
      src: ['**/*', '!node_modules/**']
    },
    options: {
      threshold: 30
    }
  }
}

Options

Just the threshold for now.

License

MIT

About

Demonstration of how to write a Grunt task. Counts words in files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published