grunt-fileindex

Write index files of directory contents

npm install grunt-fileindex
2 downloads in the last week
63 downloads in the last month

grunt-fileindex

Dependency Status

Write index files of directory contents

Getting Started

This plugin requires Grunt ~0.4.1

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-fileindex --save-dev

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

grunt.loadNpmTasks('grunt-fileindex');

The "fileindex" task

Leverage the standard grunt file selector api to select files and output lists of according to various pluggable formats. Currently supported as format parameter:

  • lines - newline seperated
  • json_flat - simple json array
  • script_src - list of document.write('<script src="{path}"></script>'); (useful to update javascript includes, like a list of tests).
  • callback function: function(list, options, dest){ ... } that returns the data to write, or undefined to skip.

More will added later or at request.

Options

//default options:
format: 'lines'
sort: false
absolute: false

//not supported by all formats:
pretty: true

Usage Examples

grunt.initConfig({
    fileindex: {
        lines: {
            options: {
                format: 'lines',
                absolute: true,
            },
            files: [
                {dest: 'tmp/index.txt', src: ['**/*']}
            ]
        },
        list: {
            options: {
                format: 'json_flat',
                pretty: true
            },
            files: [
                {dest: 'tmp/list.json', src: ['**/*']}
            ]
        },
        scripts: {
            options: {
                format: 'script_src'
            },
            files: [
                {dest: 'test/all.js', src: ['**/*.test.js'], cwd: 'test', filter: 'isFile'}
            ]
        },
        custom: {
            options: {
                format: function(list, options, dest) {
                    return '<p>\n' + list.sort().reverse().join('<br>\n') + '\n</p>\n';
                }
            },
            files: [
                {dest: 'tmp/custom.txt', src: ['**/*'], cwd: 'test/files', filter: 'isFile'}
            ]
        }
    }
})

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.

History

  • 0.1.0 - First release

License

Copyright (c) 2013 Bart van der Schoor Licensed under the MIT license.

npm loves you