/gulp-directory-map

Convert a buffer of files into a JSON representation of the file structure using gulp

Primary LanguageJavaScriptMIT LicenseMIT

gulp-directory-map

NPM version Build Status Coverage Status Dependency Status Dependency Status

Convert a buffer of files into a JSON representation of the directory structure using gulp

Usage

First, install gulp-directory-map as a development dependency:

npm install --save-dev git+ssh://git@mxgit.mobilex.intra:thai/gulp-directory-map.git

Then, add it to your gulpfile.js:

var directoryMap = require("gulp-directory-map");
  
gulp.src('app/**/*.html')
  .pipe(directoryMap({
    filename: 'urls.json'
  }))
  .pipe(gulp.dest('dist'));

Given this directory structure...

app
  |_bundle.js
  |_index.html
  |_vendor.bundle.js
  |_version.json

... this JSON object would be written to dist/urls.json:

{
  "timestamp":1435583692,
  "version":"0.0.3"
  "files":[
    {
      "name":"ae887de183bbb7867b7033d2ff04bc9b.db","position":0
    },
    {
      "name":"bundle.js","position":0
    },
    {
      "name":"index.html","position":0
    },
    {
      "name":"vendor.bundle.js","position":0
    }
  ]
}

The version number is read out from the version key in the package.json file.

This is useful for mapping out a directory structure after passing files through a pre-processor, generating data to create navigation during build, and more. Have fun!

API

directory-map(options)

options.filename

Type: String
Default: urls.json

The path to write the directory structure JSON file to.

options.prefix

Type: String Default: none

The a string to prepend to every url.

Given the directory structure above, specifiying prefix: 'prefixed-folder' would generate this JSON:

{
  "prefixed-folder": {
    "index.html": "prefixed-folder/index.html",
    "nested-folder-1": {
      "faq.html": "prefixed-folder/nested-folder-1/faq.html",
      "index.html": "prefixed-folder/nested-folder-1/index.html",
      "nested-folder-1-1": {
        "index.html": "prefixed-folder/nested-folder-1/nested-folder-1-1/index.html"
      }
    },
    "nested-folder-2": {
      "index.html": "prefixed-folder/nested-folder-2/index.html"
    }
  }
}

License

MIT License

Thanks

Thanks to @hparra for creating the generator-gulp-plugin. It has lots of great examples and boilerplate setup, and was used to get this plugin bootstrapped.