https://github.com/thlorenz/mutiny
Recursively mutates files in a given directory.
https://github.com/thlorenz/mutiny
Last synced: 5 months ago
JSON representation
Recursively mutates files in a given directory.
- Host: GitHub
- URL: https://github.com/thlorenz/mutiny
- Owner: thlorenz
- License: mit
- Created: 2013-12-07T02:49:18.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-03-30T03:52:52.000Z (over 11 years ago)
- Last Synced: 2025-05-27T08:53:04.234Z (6 months ago)
- Language: JavaScript
- Homepage: https://github.com/thlorenz/mutiny
- Size: 332 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mutiny [](http://travis-ci.org/thlorenz/mutiny)
Recursively mutates files in a given directory.
```js
var through = require('through2');
var mutiny = require('mutiny');
function toUpper(file, content) {
return through(
function (chunk, enc, cb) {
this.push(chunk.toUpperCase());
cb();
}
)
}
var readdirpOpts = { root: __dirname + '/root' };
mutiny({ outdir: __dirname + '/out', transform: [ toUpper ]}, readdirpOpts)
.on('error', console.error)
.on('data', function (d) { console.log('\nProcessed:\n', d); })
```
[transform example](https://github.com/thlorenz/mutiny/tree/master/examples/transform-only.js)
```sh
# assuming trim-leading is a transform installed as a node_module
mutiny ./root -t ./local-transform/toUpper.js -t trim-leading -o ./out
```
[bin example](https://github.com/thlorenz/mutiny/tree/master/examples/bin)
## Installation
npm install mutiny
## API
-
mutiny(mutinyopts, readopts) → {ReadStream}
-
Mutates the files of a directory recursively applying specified transform and/or a rename function.
The transformed files are saved into the outdir and directory structure is maintained.
Parameters:
Name
Type
Description
mutinyopts
Object
Properties
Name
Type
Description
outdir:
String
the root of the directory to which to write the transformed/renamed files
transform:
Array.<(function()|String)>
that transform each file's content
transform function signature: function(String):TransformStream
Note: each transform can be a function or a name of an installed transform or a path to a local module
rename:
function
renames each file
signature: function ({String} outfile, {String} outdir, {String} relativeOutfile) : {String} outfile
getOutStream:
function
allows overriding the defaultOutStream in case rename is not sufficient
signature: function ({String} outfile, {String} outdir, {String} relativeOutfile) : {WriteStream}
readopts
Object
options passed through to readdirp
Properties
Name
Type
Description
root
String
the root of the source directory that needs to be specified
Returns:
which emits 'error' and or 'data' to update mutiny's progress
-
Type
-
ReadStream
-
transformContent(progress, transforms)
-
Runs all transforms on the content of all files that are piped into its file stream.
Reports progress by pushing into the @see progress stream.
Parameters:
Name
Type
Description
progress
Stream
into which progress data is pushed
transforms
Array.<function(String): Stream>
functions that return a transform stream when invoked with a path to a file
- signature of each transform: function ({String} file) : {TransformStream}
- Source:
*generated with [docme](https://github.com/thlorenz/docme)*
## More Examples
Please find more examples in the [examples directory](https://github.com/thlorenz/mutiny/tree/master/examples) and consult the [tests](https://github.com/thlorenz/mutiny/tree/master/tests)
## License
MIT