unified

Project:vfile/vfile-reporter-folder-json

Package:vfile-reporter-folder-json@2.0.2

  1. Dependencies:0·Dependents:0
  2. vfile utility to create a JSON representation of files
  1. util 105
  2. utility 105
  3. file 24
  4. virtual 21
  5. vfile 17
  6. vfile-util 16
  7. vfile-reporter 5
  8. reporter 5
  9. formatter 4
  10. report 3
  11. json 3

vfile-reporter-folder-json

Build Coverage Downloads Sponsors Backers Chat

Construct a virtual JSON folder structure based off the paths of the given vfiles.

Install

npm:

npm install vfile-reporter-folder-json

…or yarn:

yarn add vfile-reporter-folder-json

Use

The plugin can be use added via unified-engine configuration:

{
  reporter: 'vfile-reporter-folder-json'
}

…or from the terminal with unified-args:

remark . --report vfile-reporter-folder-json

…or programmatically from unified-engine:

const engine = require('unified-engine')
const remark = require('remark')
const folderJson = require('vfile-reporter-folder-json')

engine(
  {
    // Custom reporter
    reporter: folderJson,
    // Standard engine configuration
    processor: remark,
    files: ['.'],
    extensions: ['md', 'markdown', 'mkd', 'mkdn', 'mkdown'],
    pluginPrefix: 'remark',
    rcName: '.remarkrc',
    packageField: 'remarkConfig',
    ignoreName: '.remarkignore',
    color: true
  },
  err => {
    if (err) throw err
  }
)

API

vfileReporterFolderJson(files[, options])

Pass a list of vfiles.

options.pretty

Indentation to use for printing json, can be a number or '\t' (optional).

options.raw

Output a raw (un-stringified) JSON object (default: false).

Returns

Virtual JSON folder, such as the following:

{
  type: 'folder',
  name: '',
  path: '.',
  children: [
    {
      type: 'file',
      path: 'README.md',
      extname: '.md',
      basename: 'README.md',
      history: [],
      messages: [],
      data: {}
    },
    {
      type: 'folder',
      name: 'example',
      path: 'example',
      children: [
        {
          type: 'file',
          path: 'example/README.md',
          extname: '.md',
          basename: 'README.md',
          history: [],
          messages: [],
          data: {}
        },
        {
          type: 'folder',
          name: 'two',
          path: 'example/two',
          children: [
            {
              type: 'file',
              path: 'example/two/README.md',
              extname: '.md',
              basename: 'README.md',
              history: [],
              messages: [],
              data: {}
            }
          ]
        }
      ]
    }
  ]
}

Contribute

See contributing.md in vfile/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Christian Murphy