grunt-dump-dir
Grunt task to dump a dictionary (all files and their content) into a JSON object
grunt-dump-dir lets you select a directory and generates a JSON representation with keys being filepaths and values - their content encoded in base64.
The main use case for this plugin is virtual filesystem generation for browserify projects.
Getting Started
This plugin requires Grunt ~0.4.2
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-dump-dir --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt;
Dump Dir task
In your project's Gruntfile, add a section named dump_dir
to the data object passed into grunt.initConfig()
.
grunt;
Options
options.rootPath
Type: String
Default value: ``
A string value which is trimmed from physical path when JSON keys are created.
options.pre
Type: string
Default value: module.exports =
String which prefixes generated JSON. Should be used to specify the assignment. The default module.exports =
is not very functional unless the file is used as input to browserify.
Usually you should set it to something like var myVariable =
Usage Examples
Default Options
If you don't specify options.rootPath
:
grunt;
the output will contain full-path keys:
"directory/filename.txt": "base64-encoded-content" "directory/filename2.jpg": "base64-encoded-content"
RootPath
If rootPath
is provided:
grunt;
we'll get the following JSON:
"filename.txt": "base64-encoded-content" "filename2.jpg": "base64-encoded-content"