grunt-dump-dir

0.1.2 • Public • Published

grunt-dump-dir Build Status NPM version

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.loadNpmTasks('grunt-dump-dir');

Dump Dir task

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

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

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.initConfig({
  dump_dir: {
    options: {
    },
    files: {
      'dest.js': [ 'directory/**/*' ]
    },
  },
});

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.initConfig({
  dump_dir: {
    options: {
      'rootPath': 'directory/'
    },
    files: {
      'dest.js': [ 'directory/**/*' ]
    },
  },
});

we'll get the following JSON:

{
 "filename.txt": "base64-encoded-content",
 "filename2.jpg": "base64-encoded-content"
}

Readme

Keywords

Package Sidebar

Install

npm i grunt-dump-dir

Weekly Downloads

80

Version

0.1.2

License

none

Last publish

Collaborators

  • bpampuch