Introduction
This library helps to mask the underlying folder structure and simluates that all the files are stored under a single folder.
For example:
For the consumer of the library it will look like all the folders are merged from left to right and now under same folder.
This library simulates the behaviour of the broccoli-merge-trees
Usage
Constructor can take inputs of the type string
, BroccoliNode
or FSMerger expected format of Object explained here
let FSMerge = require('fs-merger');
let fs = new FSMerge(['test-1', 'test-2', 'test-3']);
let contentB = fs.readFileSync('b.txt');
let contentSubDir = fs.readFileSync('sub-dir/x.txt');
let contentA = fs.readFileSync('a.txt');
FSMerger Special Object
This kind of input is supported only to help broccoli-persistent-filter to reduce the number of merges and funnels needed to be performed before it is passed down to
persistent filter's constructor is called.
This library will help in avoding unneccesary merge required before calling broccoli-persistent-filter plugin.
For example:
const Filter = require('broccoli-persistent-filter');
class TestFilter extends Filter {
constructor(nodes) {
super(nodes);
}
processString(content) {
return content.replace(/broccoli/gi, `filter`);
}
};
const Funnel = require('broccoli-funnel');
const MergeTree = require('broccoli-merge-trees');
let mergedTree = new MergeTree([
new Funnel('fixture/docs', {
destDir: 'documents'
}),
new Funnel('fixture/example', {
getDestinationPath: function (relativePath) {
if (relativePath.includes('map.js')) {
return 'metal.js';
}
return relativePath;
}
}),
]);
module.exports = new TestFilter(mergedTree);
broccoli build dist
With this new library we can write the same above as following once PR is merged into broccoli-persistent-filter
.
let FSMergerObjectWithPrefix = {
root: 'fixture/docs',
prefix: 'documents'
}
let FSMergerObjectWithFileDest = {
root: 'fixture/example',
getFileDestiation: function (relativePath) {
if (relativePath.includes('map.js')) {
return 'metal.js';
}
return relativePath;
}
}
module.exports = new TestFilter([FSMergerObjectWithPrefix, FSMergerObjectWithFileDest]);
This new library helped in removing two funnels which where used only for the sake of renaming at the output of persitent filter and mergeTree was performed because persitent filter was restricted to accept only one inputNode.