File system functions with a separated metadata system.
var pull = require('pull-stream')
var pug = require('pull-pug') // An example module
var fs = require('pull-fs-meta')() // Init pull-fs-meta
pull(
// Reading pulls the file's contents as a string
// and stashes the file's metadata on the `fs` object
fs.read('app/**/*.pug'),
// Use String -> String compiler
pug(),
// Change the file extensions before writing
fs.files({ ext: 'html' }),
// Write to an output folder.
fs.write('output')
)
Modules like pull-vinyl
or vinyl-fs
(used in gulp
) are based on top of the Vinyl
object, which centralizes the metadata and contents in one location in the stream. This isn't really appealing to things like compilers who only deal with data... So you end up needing to create wrapper libraries like gulp-pug
, gulp-sass
, etc.
This module separates file structure from contents:
- Contents are streamed as strings so you can compile them easily with
String -> String
tools. - Metadata is changed with
fs.files({ ...options })
, like extnames, clearing, etc.
$ npm install --save pull-fs-meta
Initialize the pull-fs-meta
module. This is the main export
options
(Object
): Options to initialize withmeta
(Array
): Optional meta to load beforehand
Easily done like this:
var fs = require('pull-fs-meta')({ meta: [] })
// Or
var fs = require('pull-fs-meta')()
Read files' contents from the file system as a String
. It works as a source pull stream.
pattern
: A glob pattern resolved bypull-glob
options
get passed tofs.files
(withclear: true
by default).
pull(
fs.read('foo/**/*.js'),
// ... transform contents
)
Write contents to the file system under a base directory, to their metadata paths.
directory
(String
): A path where you want to output the files.
pull(
fs.read('foo/**/*.js'),
// ... transform contents
// then write to `out` directory:
fs.write('out')
)
Change your files' metadata.
options
(Object
): Options to apply on your metadata.clear
(Boolean
): Clear the metadata.ext
(String
): Change the file's extnames.
pull(
fs.read('app/**/*.coffee'),
// ... transform contents
// update metadata:
fs.files({ ext: '.js' })
// write:
fs.write('out')
)
"Meta" is private array created from fms()
, it contains "metadata".
The "metedata" are also arrays. They contain info much like Vinyl
has; although, minus the content as that gets streamed.
MIT © Jamen Marz