grunt-spelunk

Flatten a folder to a JSON representation of its contents

npm install grunt-spelunk
1 downloads in the last day
3 downloads in the last week
17 downloads in the last month

grunt-spelunk

Grunt task to traverse a folder and flatten it to a JSON representation. Previously existed as grunt-dir2json (grunt-spelunk extracts the core functionality into a separate module - spelunk - and improves performance).

See the spelunk docs for an introduction.

Getting Started

This plugin requires Grunt ~0.4.0

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

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

grunt.loadNpmTasks('grunt-spelunk');

The "spelunk" task

Overview

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

grunt.initConfig({
  spelunk: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})

Options

exclude

Type: String or Array

A pattern, or array of patterns, of filenames to exclude, e.g. **/README.md. Uses the standard globbing syntax. .DS_Store and Thumbs.db files will always be excluded - you don't need to specify these.

replacer

Type: Function or Array

Transforms values and properties when stringifying JSON. See the MDN docs

space

Type: String

Pretty-prints the result using this string. See the MDN docs

jsonpCallback

Type: String

If supplied, spelunk will create JSONP instead of JSON (note that the destination filename should end .js and not .json in this case)

amd

Type: Boolean

If true, spelunk will create an AMD module (as above, extension should be .js)

Usage Examples

Default Options

This will read the contents of project/data and write a JSON file representing its contents to project/src/data.json, excluding any README files:

grunt.initConfig({
  spelunk: {
    data: {
      root: 'project/data',
      dest: 'project/src/data.json',
      options: {
        exclude: '**/README.md'
      }
    }
  }
})

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.

npm loves you