# broccoli-spelunk

> Flatten a folder to a .js/.json representation of its contents, a la [spelunk](http://github.com/Rich-Harris/spelunk).

Latest version **0.1.2** (published 2014-07-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install broccoli-spelunk
pnpm add broccoli-spelunk
yarn add broccoli-spelunk
bun add broccoli-spelunk
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2014-07-17 |
| First published | 2014-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Rich-Harris |
| Maintainers | rich_harris |
| Keywords | broccoli, spelunk, flatten |

## Links

- npm: https://www.npmjs.com/package/broccoli-spelunk
- Repository: https://github.com/Rich-Harris/broccoli-spelunk
- Issues: https://github.com/Rich-Harris/broccoli-spelunk/issues
- npm.io page: https://npm.io/package/broccoli-spelunk

## Dependencies (6)

- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.0
- [spelunk](https://npm.io/package/spelunk.md) ^0.1.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^0.9.1
- [tosource](https://npm.io/package/tosource.md) ^0.1.2
- [es6-promise](https://npm.io/package/es6-promise.md) ^1.0.0
- [broccoli-writer](https://npm.io/package/broccoli-writer.md) ^0.1.1

## Recent versions

- 0.1.2 (latest) — 2014-07-17
- 0.1.1 — 2014-05-23
- 0.1.0 — 2014-05-23

## README

# broccoli-spelunk

Flatten a folder to a .js/.json representation of its contents, a la [spelunk](http://github.com/Rich-Harris/spelunk).


Installation
------------

```
$ npm install broccoli-spelunk
```


Usage
-----

In your brocfile.js (or, if you're using [grunt-broccoli](https://github.com/quandl/grunt-broccoli) for example, in your target's `config` property), add something like the following:

```js
var flattenFolder = require( 'broccoli-spelunk' );

var json = flattenFolder( 'data', {
	outputFile: 'data.json'
});

module.exports = json;
```

This will recursively read all the files and folders inside the `data` folder, flattening them to a JavaScript object representation. This data can be output as **JSON**, **AMD**, **Common JS**, or as an **ES6 module**.


Example
-------

First, you will need to have `broccoli-cli` installed:

```
$ npm i -g broccoli-cli
```

Clone this repo, run `npm i` to install dependencies, then run `broccoli serve`. This will flatten the contents of the `example` folder.

Browse to [localhost:4200/data.json](http://localhost:4200/data.json) to see the result. As you add, edit and remove files inside the `example` folder, keep refreshing this URL (or install [LiveReload](https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en) for Chrome so you don't have to) to see the JSON file updated.


Options
-------

Here are some example options. They are all blank by default except `mode`, which defaults to 'json'.

```js
tree = flattenFolder( inputTree, {
	// This is the only required option. If you're using a mode other
	// than 'json', be sure to change the file extension to '.js'
	outputFile: 'data.json',

	// To exclude files, pass in a string or array of patterns to ignore.
	// You can use minimatch glob patterns
	exclude: '**/README.md'

	// Supported options are 'json', 'amd', 'cjs' and 'es6'.
	// The default is 'json'
	mode: 'json',

	// These options only apply to 'json' mode, and are treated as the
	// second and third arguments to `JSON.stringify`

	// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_native_JSON#The_replacer_parameter
	replacer: null,
	space: '  '
});
```


Credits
-------

* [Jo Liss](https://twitter.com/jo_liss) created [broccoli](https://github.com/broccolijs/broccoli) and the [broccoli-writer](https://github.com/broccolijs/broccoli-writer) utility which this plugin uses
* [Marcello Bastéa-Forte](https://twitter.com/marcello3d) wrote [node-tosource](https://github.com/marcello3d/node-tosource) which this plugin uses to serialize objects
* [Substack](https://twitter.com/substack) wrote [node-mkdirp](https://github.com/substack/node-mkdirp), which makes dealing with the filesystem bearable
* [Jake Archibald](https://twitter.com/jaffathecake) created the [es6-promise](https://github.com/jakearchibald/es6-promise) polyfill


Contributing & feedback
-----------------------

Issues and pull requests welcome. I'm [@Rich_Harris](http://twitter.com/Rich_Harris) on Twitter.


License
-------

MIT.

---
_Source: https://npm.io/package/broccoli-spelunk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
