gulp-file-contents-to-json
Slurp in some files, output a JSON representation of their contents.
Check out the broccoli equivalent here.
Installation
$ npm install gulp-file-contents-to-json
How it works
Given a nested directory of files like so,
my-files
├── bar.txt
├── foo.txt
└── my-folder
└── baz.txt
gulp-file-contents-to-json reads in each file, and outputs a single JSON file representing the contents of each file within the folder. When a directory is encountered, it becomes a nested object within the JSON blob, like so:
How to Use
For example, to read in the contents of the my-files
folder and output dist/contents.json
, simply add the following gulp task inside gulpfile.js
:
var gulp = ;var fc2json = ; gulp;
Options may be included.
extname
as false removes file extensions and this is useful when wanting dot notation.strip
takes a RegExp to strip content off the file name. This is useful if you have a directory of template files (e.g. contactTemplate.html, hoursTemplate.html) and need to strip the "Template" naming convention off each file.flat
as true removes the path and therefore the resulting json object is one layer deep (be careful to avoid duplicate filenames when using the flat option).flatpathdelimiter
will likeflat
result in a one layer deep json object, but where the path is included, separated with the custom delimiter set inflatpathdelimiter
.
Simply run the following and you're done:
$ gulp create-json-blob
Author
Brian Gonzalez |
License
MIT