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

rename-pipeline

v1.2.5

Published

Apply transforms to rename files.

Downloads

8

Readme

rename-pipeline

Build Status NPM version

Apply transforms to rename files.

Usage: rename-pipeline [source files] {OPTIONS}

Examples:
  rename-pipeline ./src/*.js -t contenthash
  rename-pipeline ./src/**/*.jpg -t gitshorthash -t [ cssimgrename -s ./src/**/*.css ]

Options:
  -t, --transform  Apply a transform to the file [required]
  -d, --dryrun     Print the result of the rename transforms to stdout, without
                   actually renaming the files
  -h, --help       Show this message

Passing arguments to transforms:

  For -t, you can use subarg syntax to pass options to the
  transforms as the second parameter. For example:

    -t [ foo -x 3 -y ]

  will call the `foo` transform with the following options:

    { x: 3, y: true }

Installation

$ npm install -g rename-pipeline

Examples

Globs can be used to denote source files:

$ rename-pipeline ./src/*.js -t contenthash

To perform multiple transforms on a set of files:

$ rename-pipeline ./src/*.js -t contenthash -t timestamp

To pass options to individual transforms, you can use subarg syntax:

$ rename-pipeline ./src/*.jpg -t gitshorthash -t [ cssimgrename -s ./src/*.css ]

API

var renamePipeline = require('rename-pipeline');

var r = renamePipeline()

Initialise a new RenamePipeline.

r.files(files:String)

Set the files to be transformed as a glob.

r.transform(transform:Object|Function)

Add a transform to the pipeline.

A transform can be either an object denoting which transform to use, plus any options:

r.transform({ name: 'contenthash' });
r.transform({ name: 'cssimgrename', options: { s: './src/*.css' } });

Or it can be a function that returns a transform stream:

r.transform(function(){
  return through(function(chunk, enc, cb){
    this.push('foo');
    cb();
  });
});

r.dryRun(dryRun:Boolean)

If true, the result of the rename transforms will be printed to stdout, but no actual renaming will occur.

r.run(done:Function)

Run the transform pipeline, executing the optional done callback when complete.

Transforms

There are a few built-in transforms, but the intention is for these to become separate modules that aren't included in this repo.

contenthash

Append a hash of the file contents:

/lib/normalise.js -> /lib/normalise.f93e7a76.js

The hash algorithm defaults to md5. The hash encoding defaults to hex. These can be changed via the command-line:

$ rename-pipeline ./src/*.js -t [ contenthash -a sha1 -e hex ]

Or via the API:

r.transform({
  name: 'contenthash',
  options: {
    algorithm: 'sha1',
    encoding: 'hex'
  }
});

gitshorthash

Append the git short version hash of HEAD:

/lib/normalise.js -> /lib/normalise.61949eb.js

timestamp

Append the timestamp (uses moment and defaults to YYYYMMDD-HHmm):

/lib/normalise.js -> /lib/normalise.20150126-1214.js

The date format can be changed via the command-line:

$ rename-pipeline ./src/*.js -t [ timestamp -f YYYY ]

Or via the API:

r.transform({
  name: 'timestamp',
  options: {
    format: 'YYYY'
  }
});

cssimgrename

Rename images within css files, based on the current file's new basename.

For a file that is being renamed to pic.12345.jpg, the following CSS:

body {
  background: url("./pic.jpg");
  color: green;
}

Will be transformed to:

body {
  background: url("./pic.12345.jpg");
  color: green;
}

Tests

$ npm test