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

node-packager

v0.0.7

Published

Use `node-packager` to generate the built package for your library or application.

Downloads

145

Readme

Why node-packager?

Use node-packager to generate the built package for your library or application.

It's ideal for applications that builds packages on the fly using Node.js.

Usage

package.js:

function Package() {}

extend( Package.prototype, {

  // Shallow copy
  "LICENSE.txt": "LICENSE.txt",

  // Sync processing
  "app.css": function() {

    // Return a String or Buffer with the file data.
    return buildCss();
  },

  // Async processing
  "app.js": function( callback ) {

    // Call `callback( error, data )`, where data is a String with the file data.
    buildJs( callback );
  },

  "images/": function() {
    var files, imagesFiles;

    // this.files and this.runtime are available.
    if ( this.runtime.includeImages ) {
      files = this.files;
      imagesFiles = {};
      Object.keys( this.files ).filter(function( filepath ) {
        return minimatch( filepath, "src/images/*" );
      }).forEach(function( filepath ) {
        imagesFiles[ path.basename( filepath ) ] = files[ filepath ];
      });
      return imagesFiles
    }

    // Skip "images/" by returning null.
    return null;
  }
});

module.exports = Package;

npm install node-packager

var fs = require( "js" );
var glob = require( "glob" );
var extend = require( "util" )._extend;
var Package = require( "./package" )
var Packager = require( "node-packager" );

var files = glob.sync( "+(LICENSE.txt|src/**)", { nodir: true } ).reduce(function( files, filepath ) {
  files[ filepath ] = fs.readFileSync( filepath );
  return files;
}, {} );

var pkg = Packager( files, Package, {
  includeImages: true
});
var stream = fs.createWriteStream( "myapp.zip" );
pkg.toZip( stream, function( error ) {
  if ( error ) {
    return console.error( error );
  }
  console.log( "Built myapp.zip (" + pkg.stats.toZip.size + " bytes) in " + ( pkg.stats.build.time + pkg.stats.toZip.time ) + " ms" );
  console.log( "- app.js took " + pkg.stats[ "app.js" ].time + " ms" );
});

API

  • Packager( files, Package [, runtimeVars] )

files Object containing (path, data) key-value pairs, e.g.,

{
   <path-of-file-1>: <data-of-file-1>,
   <path-of-file-2>: <data-of-file-2>,
   ...
}

Files will be available on Package via this.files attribute.

Package Function/Class The Package class.

runtimeVars Object Optional object including runtime variables.

Runtime variables will be available on Package via this.runtime attribute.

  • Packager.prototype.toJson( callback )

callback Function called with two arguments: null or an Error object and the built files object.

  • Packager.prototype.toZip( target [, options], callback )

target Stream/String The target stream, or the target filename (when string).

options Object

options.basedir String Set the ZIP base directory.

callback Function called when write is complete, with one argument: null or an Error object.

Test

npm test

License

MIT © Rafael Xavier de Souza