Skip to content

Instantly share code, notes, and snippets.

@timmfin
Created December 1, 2015 18:56
Show Gist options
  • Select an option

  • Save timmfin/bb03df7d138827132f0c to your computer and use it in GitHub Desktop.

Select an option

Save timmfin/bb03df7d138827132f0c to your computer and use it in GitHub Desktop.

Revisions

  1. timmfin created this gist Dec 1, 2015.
    25 changes: 25 additions & 0 deletions before-build-spelled-out.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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;
    };