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

catw

v1.0.1

Published

concatenate file globs, watching for changes

Downloads

782

Readme

catw

concatenate file globs, watching for changes

This module is just like the cat command, but with watching!

build status

example

#!/usr/bin/env node

var catw = require('catw');
var fs = require('fs');

catw('*.txt', function (stream) {
    var w = stream.pipe(fs.createWriteStream('/tmp/bundle.txt'));
    w.on('close', function () { console.log('wrote to /tmp/bundle.txt') });
});

If we run the program in a directory with files a.txt and b.txt, the bundle.txt output will be both files concatenated together (in string-order by filename):

beep
boop

If we edit a.txt to be "BEEP" instead of "beep", the bundle.txt is now:

BEEP
boop

and then if we add a third file c.txt with the contents "!!!", the output is now:

BEEP
boop
!!!

We can even delete files. If we delete b.txt, the output is now:

BEEP
!!!

If we add a new file called bloop.txt with contents "BLOOP", the bundle.txt output is now:

BEEP
BLOOP
!!!

because the glob expansions of directories are sorted before concatenating.

usage

There is a command-line catw command that ships with this package.

usage: catw {OPTIONS} [FILES...] -o OUTFILE

  If FILES is "-", read from stdin.
  If there is no OUTFILE, write to stdout and exit without watching.

  OPTIONS:

    -w, --watch      Watch for changes.
                     Default: true except when writing to stdout.
 
    -c, --command    Execute a transform command for file before concatenating.
                     The env var $FILE will be set for each file path.
 
    -t, --transform  Transform each file using a module.

    -v, --verbose    Print the number of bytes written whenever a file changes.

    -h, --help       Print this help message.

Make sure to escape the globs that you want `catw` to watch so your shell won't
expand them.

methods

var catw = require('catw')

var cat = catw(patterns, opts={}, cb)

Create a new cat to concatenate patterns, an array of strings or a single string and watch each of the patterns for changes: new files, deleted files, and file updates.

It opts.watch is false, don't watch for changes, only concatenate once.

You can pass in a opts.transform(file) function that returns a transform stream to modify file contents before the contents are written to the bundle.

If specified, cb(stream) sets up a listener on the 'stream' event.

cat.close()

Stop listening for updates to the patterns.

events

cat.on('stream', function (stream) {})

Each time a file matched by a pattern changes or there is a new or deleted file matched by a pattern, this event fires with a stream that will output the concatenated file contents.

install

To get the module, with npm do:

npm install catw

and to get the catw command do:

npm install -g catw

test

With npm do:

npm test

license

MIT