Skip to content

Commit

Permalink
Adaptation of @tsing80’s node joining merge tree
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Apr 24, 2016
1 parent 5adc8a7 commit 6a355df
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ function unlinkOrRmrfSync(path) {
rimraf.sync(path);
}
}
var ASSIMILATION_SYMBOL = 'broccoli-merge-tree@1.0.0';

module.exports = BroccoliMergeTrees
BroccoliMergeTrees.prototype = Object.create(Plugin.prototype)
BroccoliMergeTrees.prototype.constructor = BroccoliMergeTrees

function BroccoliMergeTrees(inputNodes, options) {
if (!(this instanceof BroccoliMergeTrees)) return new BroccoliMergeTrees(inputNodes, options)
options = options || {}
var name = 'broccoli-merge-trees:' + (options.annotation || '')
if (!Array.isArray(inputNodes)) {
throw new TypeError(name + ': Expected array, got: [' + inputNodes +']')
}
Plugin.call(this, inputNodes, {
Plugin.call(this, joinNodes(this, options, inputNodes), {
persistentOutput: true,
annotation: options.annotation
})
});

this._debug = debug(name);

Expand All @@ -38,6 +40,28 @@ function BroccoliMergeTrees(inputNodes, options) {
this._currentTree = FSTree.fromPaths([]);
}

function joinNodes(host, options, inputNodes) {
var nodes = []
for (var i = 0 ; i < inputNodes.length ; i++ ) {
var node = inputNodes[i];
if (host[ASSIMILATION_SYMBOL](options, node)) {
for (var j = 0; j < inputNodes[i]._inputNodes.length; j++) {
nodes.push(inputNodes[i]._inputNodes[j]);
}
}
else {
nodes.push(inputNodes[i]);
}
}

return nodes;
}

BroccoliMergeTrees.prototype[ASSIMILATION_SYMBOL] = function(options, other) {
return typeof other[ASSIMILATION_SYMBOL] === 'function' &&
options.overwite === other.options.overwite;
};

BroccoliMergeTrees.prototype.debug = function(message, args) {
this._debug(message, args);
}
Expand Down

0 comments on commit 6a355df

Please sign in to comment.