How to use broccoli-plugin - 10 common examples

To help you get started, we’ve selected a few broccoli-plugin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github broccolijs / broccoli-filter / index.js View on Github external
function Filter(inputTree, options) {
  if (!this || !(this instanceof Filter) ||
      Object.getPrototypeOf(this) === Filter.prototype) {
    throw new TypeError('Filter is an abstract class and must be sub-classed');
  }

  var name = 'broccoli-filter:' + (this.constructor.name);
  if (this.description) {
    name += ' > [' + this.description + ']';
  }

  this._debug = debugGenerator(name);

  Plugin.call(this, [inputTree]);

  if (options) {
    if (options.extensions != null)
      this.extensions = options.extensions;
    if (options.targetExtension != null)
      this.targetExtension = options.targetExtension;
    // For encodings, `null` (buffers) is distinct from the default (UTF-8)
    if (options.inputEncoding !== undefined)
      this.inputEncoding = options.inputEncoding;
    if (options.outputEncoding !== undefined)
      this.outputEncoding = options.outputEncoding;
  }

  this._cache = new Cache();
  this._canProcessCache = Object.create(null);
  this._destFilePathCache = Object.create(null);
github ember-cli / ember-cli / lib / broccoli / broccoli-config-replace.js View on Github external
function CustomReplace (inputNode, configNode, options) {
  options = options || {};
  Plugin.call(this, [inputNode, configNode], { annotation: options.annotation }); // this._super();

  this.options = options;
  this._cache = {};
}
CustomReplace.prototype = Object.create(Plugin.prototype);
github ember-cli / broccoli-uglify-sourcemap / index.js View on Github external
function UglifyWriter(inputNodes, options) {
  if (!(this instanceof UglifyWriter)) {
    return new UglifyWriter(inputNodes, options);
  }

  inputNodes = Array.isArray(inputNodes) ? inputNodes : [inputNodes];

  Plugin.call(this, inputNodes, options);

  this.options = defaults(options, {
    uglify: {
      sourceMap: {},
    },
  });

  // consumers of this plugin can opt-in to async and concurrent behavior
  this.async = (this.options.async === true);
  this.concurrency = Number(process.env.JOBS) || this.options.concurrency || Math.max(require('os').cpus().length - 1, 1);

  // create a worker pool using an external worker script
  this.pool = workerpool.pool(path.join(__dirname, 'lib', 'worker.js'), {
    maxWorkers: this.concurrency,
    nodeWorker: 'auto',
  });
github Shopify / js-buy-sdk / build-lib / util / lokka-builder.js View on Github external
}
    ]
  });
}

function LokkaBuilder(options) {
  const defaultedOptions = options || {};

  Plugin.call(this, [/* takes no input nodes */], {
    annotation: defaultedOptions.annotation
  });

  this.options = defaultedOptions;
}

LokkaBuilder.prototype = Object.create(Plugin.prototype);
LokkaBuilder.prototype.constructor = LokkaBuilder;

LokkaBuilder.prototype.build = function () {
  return Promise.all([
    bundleLokka(),
    bundleLokkaTransport()
  ]).then(bundles => {
    const lokka = bundles[0];
    const lokkaTransportHttp = bundles[1];

    return Promise.all([lokka.write({
      format: 'es',
      exports: 'named',
      dest: path.join(this.outputPath, 'lokka.js')
    }), lokkaTransportHttp.write({
      format: 'es',
github isleofcode / ember-cli-asset-sizes-shim / lib / plugins / tree-stats.js View on Github external
var Plugin = require("broccoli-plugin");
var path = require("path");
var fs = require("fs");
var Promise = require("rsvp").Promise; // jshint ignore:line
var makeDir = require("../helpers/make-dir");
var analyze = require('../helpers/analyze-path');
var chalk = require('chalk');

// Create a subclass from Plugin
TreeStats.prototype = Object.create(Plugin.prototype);
TreeStats.prototype.constructor = TreeStats;

function TreeStats(inputNodes, options) {
  options = options || {
      annotation: "Vendor Stats"
    };
  this.options = options;

  Plugin.call(this, inputNodes, {
    annotation: options.annotation
  });
}

TreeStats.prototype.build = function () {
  var _self = this;
  var builtAll = [];
github timmfin / broccoli-webpack-cached / index.js View on Github external
var PreventResolveSymlinkPlugin = require('./prevent-resolve-symlink-plugin');

function WebpackFilter(inputNode, options) {
  if (!(this instanceof WebpackFilter)) return new WebpackFilter(inputNode, options);

  if (Array.isArray(inputNode)) {
    throw new Error("WebpackFilter only accepts a single inputNode");
  }

  Plugin.call(this, [inputNode], {
    annotation: options.annotation
  });
  this.options = options;
}

WebpackFilter.prototype = Object.create(Plugin.prototype);
WebpackFilter.prototype.constructor = WebpackFilter;


// "private" helpers

function ensureArray(potentialArray) {
  if (typeof potentialArray === 'string') {
    return [potentialArray];
  } else {
    return potentialArray || [];
  }
}


WebpackFilter.prototype.initializeCompiler = function() {
  if (this.options.context) throw new Error("WebpackFilter will set the webpack context, you shouldn't set it.");
github glimmerjs / glimmer-application-pipeline / lib / broccoli / module-map-creator.js View on Github external
const Plugin = require('broccoli-plugin');
const fs = require('fs');
const path = require('path');
const walkSync = require('walk-sync');
const getModuleConfig = require('./get-module-config');

function ModuleMapCreator(src, config, options) {
  options = options || {};
  Plugin.call(this, [src, config], {
    annotation: options.annotation
  });
  this.options = options;
}

ModuleMapCreator.prototype = Object.create(Plugin.prototype);
ModuleMapCreator.prototype.constructor = ModuleMapCreator;
ModuleMapCreator.prototype.build = function() {
  function specifierFromModule(modulePrefix, moduleConfig, modulePath) {
    let path;
    let collectionPath;

    for (let i = 0, l = moduleConfig.collectionPaths.length; i < l; i++) {
      path = moduleConfig.collectionPaths[i];
      if (modulePath.indexOf(path) === 0) {
        collectionPath = path;
        break;
      }
    }

    if (collectionPath) {
      // trim group/collection from module path
github ebryn / ember-component-css / lib / include-all.js View on Github external
/* eslint-env node */
'use strict';

var Plugin = require('broccoli-plugin');
var walkSync = require('walk-sync');
var fs = require('fs');
var FSTree = require('fs-tree-diff');
var Promise = require('rsvp').Promise;
var path = require('path');
var os = require("os");

module.exports = IncludeAll;

IncludeAll.prototype = Object.create(Plugin.prototype);
IncludeAll.prototype.constructor = IncludeAll;
function IncludeAll(inputNode, options) {
  options = options || {};
  Plugin.call(this, [inputNode], {
    annotation: options.annotation,
    persistentOutput: true
  });

  this.currentTree = new FSTree();
  this.importedPods = {};
}

IncludeAll.prototype.build = function() {
  var srcDir = this.inputPaths[0];

  var entries = walkSync.entries(srcDir);
github ebryn / ember-component-css / lib / pod-names.js View on Github external
/* eslint-env node */
'use strict';

var Plugin = require('broccoli-plugin');
var walkSync = require('walk-sync');
var fs = require('fs');
var FSTree = require('fs-tree-diff');
var Promise = require('rsvp').Promise;
var path = require('path');
var componentNames = require('./component-names.js');

module.exports = PodNames;

PodNames.prototype = Object.create(Plugin.prototype);
PodNames.prototype.constructor = PodNames;
function PodNames(inputNode, options) {
  options = options || {};
  Plugin.call(this, [inputNode], {
    annotation: options.annotation,
    persistentOutput: true
  });

  this.currentTree = new FSTree();
  this.podNameJson = {};
  this.classicStyleDir = options.classicStyleDir;
  this.terseClassNames = options.terseClassNames;
}

PodNames.prototype.build = function() {
  var srcDir = this.inputPaths[0];
github ef4 / ember-browserify / lib / stub-generator.js View on Github external
if (Array.isArray(inputTree) || !inputTree) {
    throw new Error('Expects one inputTree');
  }

  Plugin.call(this, [inputTree], options);
  this._persistentOutput = true;

  // setup persistent state
  this._previousTree = new FSTree();
  this.stubs = new Stubs();

  this._fileToChecksumMap = {};
}

StubGenerator.prototype = Object.create(Plugin.prototype);
StubGenerator.prototype.constructor = StubGenerator;
StubGenerator.prototype.build = function() {
  var start = Date.now();
  var inputPath = this.inputPaths[0];
  var previous  = this._previousTree;

  // get patchset
  var input = walkSync.entries(inputPath, [ '**/*.js' ]);

  debug('input: %d', input.length);

  var next = this._previousTree = FSTree.fromEntries(input);
  var patchset = previous.calculatePatch(next);

  debug('patchset: %d', patchset.length);

broccoli-plugin

Base class for all Broccoli plugins

MIT
Latest version published 4 years ago

Package Health Score

62 / 100
Full package analysis

Popular broccoli-plugin functions