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

mirror-glob

v1.0.0

Published

Process a group of files into another folder and watch them for changes

Downloads

9

Readme

mirror-glob

Process a group of files into another folder and watch them for changes

Installation

npm install mirror-glob

Usage

mirrorGlob(patterns, base, outputDir, [options], handler, [callbacks], [updateCallback], [removeCallback])

processGlob receives a handler which is called for each files which matches a pattern. It can then watch that pattern, calling the handler whenever a file is changed or a new file is added, and deleting the processed file if the original one is removed.

  • patterns - a glob pattern or array of glob patterns to process
  • base - an options object to pass to glob() or the base folder in which to search for the patterns (equivalent to options.cwd)
  • outputDir - the directory in which to write the processed files
  • options
    • extension - (default: '') extension to add to the output files
    • watch - (default: false) whether the files should be watched for changes
    • extraFiles - an object describing extra file paths to be passed in the extraFiles argument. { type: { dir, extension } } (e.g { log: { dir: 'logs', extension: 'log' } })
    • sourceMapDir - a shorthand add a property to extraFiles: { sourceMap: { dir: sourceMapDir, extension: 'map' } }
  • handler - the function to process the files, which will be called with arguments (inputPath, outputPath, extraFiles, callback). The extraFiles argument contains the files defined in options.extraFiles
  • callbacks - function or object containing functions to be called after a file is processed
    • if object, should have the following properties:

      • initial- function to be called after the initial processing is finished, with (err, [ { processingResult, inputPath, outputPath, extraPaths }] )
      • update - function to be called after processing is finished due to a file being changed or added, with (err, { processingResult, inputPath, outputPath, extraPaths }). only called when options.watch is true
      • remove - function to be called after a file is removed, with ``(err, { inputPath, outputPath, extraPaths }). only called when options.watchistrue`
    • if function, is called after the initial processing and on update, with (err, [ { processingResult, inputPath, outputPath, extraPaths }] )

Example

function someHandler(inputFile, outputFile, extraFiles, callback) {
  // do something with inputFile and write outputFile
  // sample parameter values:
  //   * inputFile: 'src/foo.wutscript'
  //   * outputFile: 'build/foo.wutscript.js'
  //   * extraFiles.sourceMap: 'build/maps/foo.wutscript.js.map'
  //   * extraFiles.log: 'build/logging/foo.wutscript.js.log'
}

var options = {
  watch: true,
  extension: 'js',
  extraFiles: { log: { dir: 'logging', extension: 'log' }, sourceMap: { dir: 'maps', extension: 'map' }}
}
mirrorGlob('**/*.wutscript', 'src', 'build', options, someHandler, {
  initial: function(err, success) {
    console.log("Initial processing complete");
    // success is an array with information about the file processing
  },
  update: function(err, success) {
    console.log("File reprocessed");
    // success has information about the file processing
  },
  remove: function(err, success) {
    console.log("File removed");
    // err is not null if an error ocurred while unlinking the file
  }});