Skip to content

Instantly share code, notes, and snippets.

@timmfin
Created December 1, 2015 18:56
Show Gist options
  • Save timmfin/bb03df7d138827132f0c to your computer and use it in GitHub Desktop.
Save timmfin/bb03df7d138827132f0c to your computer and use it in GitHub Desktop.
function beforeBuild(node, cb, options) {
// Get the last "child node" from our passed node's array of "children" inputNodes
// (see https://github.com/broccolijs/broccoli-plugin/blob/master/index.js for
// more context)
var lastChildNode = node._inputNodes.pop();
// Take that child node and wrap it with our own, new plugin. Using
// timmfin/broccoli-quick-plugin as a shortcut we don't have to create a new
// contructor with all the broilerplate to extend broccoli-plugin inline.
var wrappedChildNode = QuickPlugin([lastChildNode], {
build: function() {
cb();
},
name: "beforeBuild",
annotation: (options || {}).annotation
});
// Next we add our wrapped child node back to the end of the "children" list
node._inputNodes.push(wrappedChildNode);
// Lastly return the modified node. When the builder builds its sorted array
// of the whole build graph, we will now have a "hook" that is run before the
// build method of the original node passed to this function.
return node;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment