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

file-compress

v1.0.27

Published

This is a nodejs utility package. It archives project files into one or more zip files. It has very simple APIs and is highly configurable in an easy way.

Downloads

16

Readme

File Archiver

This is a nodejs utility package. It archives project files into one or more zip files. It has very simple APIs and is highly configurable in an easy way.


Getting started

  • Step 1:

    Run npm install file-compress --save in your project home, or add the package name file-compress to your package.json file.


  • Step 2:

    Create a config file "compress.conf.js" (can be anything) in your project home folder (or anywhere else).


  • Step 3:

    Setup the paths in your config file that you want to archive separately. The config file should look like this:

      const Path = require('path');
      module.exports = {
      	'/static/pages/.*':	{	dest_file: '/assets/{: this.NOW :}/{$0}.zip',
      							excludes: ['.test.js'],
      							archive_root: '.',
      							filenameMapper: function (path) {
      								return Path.resolve(Path.dirname(path), this.MD5(path) + Path.extname(path));
      							}},
      	'/static/common':	{	dest_file: '/assets/common.zip',
      							includes: ['.jpg', '.png', '.js'],
      							excludes: ['test.*'],
      							archive_root: '..'}
      };
    • As you can see, it is just a module object. The keys are the paths that are relative to your project home that you wish to archive as zip files separately. You can use regular expressions in the path names to reduce the number of entries in your config file to keep concise.

    • Please be cautious to write conflict path names such as /static/.* and /static/foo. It is a valid usage - the same directory can be archived into two or more zip files according to different config blocks.


  • Step 4:

    Setup some detailed values for each path config. Currently, all the available config entries are:

    • dest_file: string | the archive file path to save with. | Default: '/assets.zip'
    • includes: array | to filter in a set of filename (with pathnames) rules described in regular expressions. Default: ['.*'] // all files
    • excludes: array | to filter out the filenames (with pathnames) that matches the regular expression rules. Default: []
    • archive_root: string | cwd of the in-archive root path. Default: '.'
    • empty_folder: boolean | should empty the archive containing folder first? Default: false
    • filenameMapper: function | to transfer the real file path to its corresponding archived path. Default: (path) => path

  • Step 5:

    Congratulations! You are almost there. Create a test file in your project home, say test-compress.js and write the following code:

      require('file-compress').archive('/compress.conf.js');

    Again, the argument of archive function here is the configuration file path relative to your project home.


  • Step6:

    Run test-compress.js and enjoy!


Hints

  • to map the filename, you can take advantage of path module. For instance, to flare out the pathnames, you can do the following:

      filenameMapper: function (path) {
      	return require('path').basename(path);
      }
  • You can use regular expression grouping replacements in the path names. The syntax is {$matching_index}, e.g. {$0}, {$1}, etc.

  • You can write JS-expressions between {: :}. The script context is the current config block. Please refer to the list below to see some embedded variables and functions:

    • this.NOW: current timestamp in milliseconds. It is set to the start time of running the script.
    • this.RAND: a random decimal number, between 0 (including) to 1 (excluding).
    • this.MD5(msg): to generate md5 hash of given msg.
    • TBD.