Skip to content

Instantly share code, notes, and snippets.

@yorickvP
Last active October 4, 2015 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorickvP/2714588 to your computer and use it in GitHub Desktop.
Save yorickvP/2714588 to your computer and use it in GitHub Desktop.
Browserify dependency listing
#!/usr/bin/env node
// works as a CLI similar to the browserify one, but prints a space-separated list of dependencies for the arguments you give.
// requires browserify (obviously), JSONStream and event-stream.
var JSONStream = require('JSONStream')
, child_process = require('child_process')
, path = require('path')
, es = require('event-stream')
var parser = JSONStream.parse([true])
var cwd = process.cwd()
var child = child_process.spawn('node_modules/.bin/browserify', ['--deps'].concat(process.argv.slice(1)))
child.stdout
.pipe(JSONStream.parse([true, 'id']))
.pipe(es.mapSync(path.relative.bind(path, cwd)))
.pipe(es.join(' '))
.pipe(process.stdout)
child.stderr
.pipe(process.stderr)
child.on('exit', function(code, signal) { process.exit(code) }
# one would use it for makefiles like so:
web/static/depend/js/browserify.bundle.js.d: web/src/js/browserify.entry.js
@echo Generate $@
echo -n "web/static/js/browserify.bundle.js: " > $@
./browserify-makedep.js $+ >> $@
-include web/static/depend/js/browserify.bundle.js.d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment