No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests
.eslintrc.js
.gitignore
README.md
index.js
package.json
yarn.lock

README.md

broccoli-assembler

A build utility to allow for more flexible builds and better composition. It makes no assumptions about how to "package" an input tree and leaves it up to the user.

Flexibility is achieved through custom strategies. The idea behind a strategy is to encapsulate a custom piece of logic that user wants to perform on an input tree.

It works as follows:

inputTree => RemoveUnusedJSModulesStrategy(inputTree) => onlyUsedModulesTree

Usage

/**

  Let's assume that `inputTree` exists in this context and let's say it
  has the following structure:

  d3/
    event.js
    format.js
    geo.js
    projection.js
    select.js
    selectAll.js
  the-best-app-ever/
    component.js
    config.js
    helper.js

  And let's say, we want to produce two files as result of the
  broccoli build: `app.js` and `vendor.js`.
*/

  const concat = require('broccoli-concat');
  const Funnel = require('broccoli-funnel');

  class ConcatStrategy {
    constructor(options) {
      this.options = options || {};
    }

    toTree(assembler, inputTree) {
      return concat(inputTree, this.options);
    }
  }

  const d3Concat = new ConcatStrategy({
    inputFiles: ['d3/*.js'],
    outputFile: 'vendor.js',
    annotation: 'Concat: Vendor',
  });

  const appConcat = new ConcatStrategy({
    inputFiles: ['the-best-app-ever/*.js'],
    outputFile: 'app.js',
    annotation: 'Concat: Vendor',
  });

  const assembler = new Assembler(inputTree, {
    strategies: [d3Concat, appConcat],
    annotation: 'Final Build',
  });

  // it will produce with `app.js` and `vendor.js` files.
  assembler.toTree();

API

interface Strategy {
  constructor();
  toTree(assembler: Assembler, inputTree: BroccoliTree): BroccoliTree;
}

interface AssemblerOptions {
  /**
    A list of custom strategies to run on the input broccoli tree.

    Defaults to an empty list.
  */
  strategies: Strategy[],

  /**
    The label to use to mark the resulting tree.

    Defaults to an empty string.
  */
  annotation: string
}

class Assembler {
  constructor(inputTree: BroccoliTree, options: AssemblerOptions);
  toTree(): BroccoliTree;
}

Development

Installation

  • git clone git@github.com:twokul/broccoli-assembler.git
  • cd broccoli-assembler
  • yarn install

Testing

  • To run tests, yarn test.
  • To debug tests, yarn test:debug.