npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bfydir

v2.0.0

Published

http-server to browserify *.js in a dir

Downloads

10

Readme

bfydir

a http-server which watchify's all the files in a dir simultaneously uppon request. also it supports minifying js-files and inlining it into html-tags: <html><body><script>/* bundled source here */</script></body></html>.

cli

bfydir [<dir>] [-p,--port <port>] [-b,--bundles <bundles>] [-d,--debug]
       [--key <key>] [--cert <cert>] [--pfx <pfx>]
       [-a,--auth <user>:<pwd>[,<user>:<pwd>]]
       [-h,--help]

    <dir>     .. serve files from that directory (default: pwd)
    <port>    .. listen on that port (default: 8001)
    <bundles> .. write bundles into that directory (default: <dir>/.bfydir-bundles)
    debug     .. write infos about bundling/minifying to stdout
    <key>     .. path to ssl-key-file
    <cert>    .. path to cert-key-file
    <pfx>     .. path to pfx-file
    auth      .. basic auth (comma separated list of user:pwd
    help      .. only show this message, otherwise just start bfydir

querystring-parameters:

    bundle, b    .. bundles the requested file instead of serving it
    min, m       .. minifies the bundle (sets b automatically)
    inline, i    .. inlines the bundle into html (sets b)
    transform, t .. comma-separated list of transforms (sets b)
    ignore       .. comma-separated list of modules to ignore (sets b)

example:

    $ bfydir ~ -p 8080 -a user1:pwd1,user2:pwd2
    $ echo "module.exports = 'a'" > ~/a.js
    $ echo "module.exports = 'b'" > ~/b.js
    $ echo "console.log(require('./a'), require('./b'))" > ~/c.js
    $ node -e `curl "http://user1:pwd1@localhost:8005/c.js?b"`
    a b

usage

install bfydir and start the server:

$ npm i -g bfydir
$ bfydir ~ -p 8005

write code:

$ echo "module.exports = 'a'" > ~/a.js
$ echo "module.exports = 'b'" > ~/b.js
$ echo "console.log(require('./a'), require('./b'))" > ~/c.js

create a bundle:

$ node -e `curl http://localhost:8005/c.js?bundle`
a b

when you change the code it will update the bundles:

$ echo "module.exports = 'foo'" > ~/a.js
$ node -e `curl http://localhost:8005/c.js?bundle`
foo b

with the inline querystring-parameter it wrap the bundle with html-tags:

$ curl http://localhost:8005/c.js?inline
<html><body><script>/* bundled source */</script></body></html>

inline and minify:

$ curl http://localhost:8005/c.js?inline&min
<html><body><script>/* bundled source minified */</script></body></html>

use one or multiple transforms:

$ curl http://localhost:8005/some-file.js?transform=glslify,otherTransform
< transformed bundle >

without any querystring-parameters it will serve the source without bundling:

$ curl http://localhost:8005/a.js
module.exports = 'foo'

api

var bfydir = require('bfydir')([opts])

opts is optional

  • opts.dir - serve files from that directory (default: process.cwd())
  • opts.bundles - write bundled files into that directory (default: process.cwd()+'/.bfydir-bundles')

bfydir is an eventemitter which emits following events:

  • bundling
  • bundling:<path>
  • bundled
  • bundled:<path>
  • minifying
  • minifying:<path>
  • minified
  • minified:<path>

<path> is the url-pathname of the served bundle

all the events emit with a info-object:

bfydir.on('bundled', function(info){
  // info.urlPath
  // info.entryPath
  // info.bundlePath
  // info.bundlePathMin (only when minifying)
  // info.bundleSize
  // info.bundleSizeMin
})

var server = bfydir.createServer()

server is a http-server, its a shortcut for http.createServer(this.requestHandler())

var handler = bfydir.requestHandler()

this is a shortcut for var handler = bfydir.handleRequest.bind(bfydir)

bfydir.handleRequest(req, res[, next])

this will look at the query-string object require('url').parse(req.url) for various member attributes:

  • bundle or b - if set pipe a browserify-bundle-stream into res (or if the bundle exists on disk pipe it directly from disk)
  • inline or i - if set pipe the content through bfydir.inlineStream()
  • min or m - if set pipe the content through bfydir.minifyStream()
  • transform or t - (comma-separated list) if set use these transforms
  • ignore - (comma-separated list) if set tell browserify to ignore

var bStream = bfydir.bundleStream(opts)

  • bStream is a through-stream in which a browserify-bundle-stream gets piped into. the result gets piped to disk.
  • opts must be an object
    • opts.urlPath is used to identify the bundle-watcher
    • opts.entryPath
    • opts.bundlePath
    • opts.bundleOpts

var mStream = bfydir.minifyStream(opts)

  • mStream is a through-stream which buffers all content and then minifys it. then it writes the result to disk (so actually its just uglifyjs pretending to be streaming :D).
  • opts must be an object
    • opts.urlPath
    • opts.bundlePathMin
    • opts.entryPath

var iStream = require('bfydir').inlineStream([sourcePath])

  • if sourcePath is set, fs.createReadStream(bundlePath) gets piped through the stream
  • iStream is a through-stream which envelops the content into html-tags:
<html>
  <head>
    <meta content="width=device-width,
                   initial-scale=1.0,
                   maximum-scale=1.0,
                   user-scalable=0"
          name="viewport" />
    <meta charset=utf-8>
  </head>
  <body>
    <script>
      /* here is the content */
    </script>
  </body>
</html>

bfydir.close()

close all the watchify-bundle-watchers