Skip to content

Instantly share code, notes, and snippets.

@DylanLukes
Created July 22, 2014 17:37
Show Gist options
  • Save DylanLukes/82f070c7287261c95d5a to your computer and use it in GitHub Desktop.
Save DylanLukes/82f070c7287261c95d5a to your computer and use it in GitHub Desktop.
noflo = require 'noflo'
browserify = require 'browserify'
evil = require 'notevil'
class Bundler extends noflo.Component
icon: 'gift'
description: 'Bundles input files using Browserify'
constructor: ->
@inPorts = new noflo.InPorts
bundle:
datatype: 'bang'
description: 'Triggers bundling.'
extensions:
datatype: 'array'
description: 'List of extensions for browserify to accept.'
exclude:
datatype: 'array'
description: 'List of modules for browserify to exclude.'
ignore:
datatype: 'array'
description: 'List of paths for browserify to ignore.'
transforms:
datatype: 'array'
description: 'List of transforms to apply.'
entries:
datatype: 'array'
description: 'List of files/lists of files to add as entries.'
requires:
datatype: 'array'
description: 'List of {file: opts} pairs to make available.'
options:
datatype: 'object'
description: 'Options to pass to browserify#bundle.'
@outPorts = new noflo.OutPorts
out:
datatype: 'buffer'
description: 'Browserified output bundle.'
deps:
datatype: 'string'
description: 'Stream of dependencies added, for convenience and logging.'
error:
datatype: 'object'
description: 'Errors, if any occured.'
noflo.helpers.WirePattern @,
in: ['bundle']
out: 'out'
params: [
'extensions',
'exclude',
'ignore',
'transforms',
'entries',
'requires',
'options'
]
async: true,
(data, groups, out, done) =>
bundler = new browserify
extensions: @params.extensions
bundler.exclude module for module in evil(@params.exclude)
bundler.ignore file for file in evil(@params.ignore)
bundler.transform transform for transform in evil(@params.transforms)
bundler.add file for file in evil(@params.entries)
bundler.require file, options for own file, options of evil(@params.requires)
seen = []
bundler.deps().on 'data', (dep) ->
return if seen.indexOf dep.id isnt -1
@outPorts.deps.send dep.id
seen.push dep.id
bundler.bundle (evil @params.options), (err, output) =>
@outPorts.error.send err if err
out.send output if output
done()
exports.getComponent = -> new Bundler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment