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

@marknotton/versioniser

v1.1.0

Published

Cache bust filenames by automatically incrementing filenames with version numbers saved in your .env file.

Downloads

10

Readme

Versioniser

Made For NPM Made For Gulp

Cache bust filenames by automatically incrementing them with version numbers stored in your .env file.

Installation

npm i @marknotton/versioniser --save-dev
const versioniser = require('@marknotton/versioniser');

Versioner refers to your .env file when storing version numbers for filename manipulation. If your server doesn't support environmental variables in the form of a local .env file, then Versioniser is not for you.

There are a few options to manage variables that are suffixed with "_VERSION" y. The purpose for this (and the reason I built this plugin), is to increment a variable each time a certain gulp task is called. Allowing me to generate unique file names for concatenated files. Ultimately this helps avoid browsers from caching old files whilst avoiding the use of ugly and unreliable url parameters.

Get Version [int]

Get the version number of a variable

versioniser.getVersion(variable)


Update Version [int]

Update the version number of a variable by incrementing the number by one. | Parameter | Type | Description | | - | - | - | | name | string | The name of the variable that prefixes the _VERSION variable | | force | int | By default this function will increment by one. However, you can update a variable to a specific number.|

versioniser.updateVersion(variable)


Get Version Name

To modify the filename for your gulp task, you will need to generate a dynamic name to match your latest version. This gives you that new filename.

| Parameter | Type | Description | | - | - | - | | file | string | The original filename | | variable | string | To find the latest version number, define the variable name to look for in the .env file. You do not need to include the suffix '_VERSION' | | end | bool | Choose where the version number appears in the filename. This function looks for the FIRST full stop in the string, and prepends the version number to that. However there may be cases where there are multiple full stops in a string. Define true to explicitly prepend the version number to the LAST full stop in the string. This is true by default. |

versioniser.getVersionName('main.min.js', 'js', true)

This will look for the JS_VERSION=12 in your .env file and return a string that looks like this

main.v12.min.js

If you set the end boolean to false, this would be returned instead:

main.min.v12.js


Update Version Name

This essentially does the exact same thing as getVersionName, only it will increment the version in the .env file before returning the name filename.


Delete Versions

Versioned files may start to get overwhelming and unnecessary. This lets you keep a set amount of versioned files.

| Parameter | Type | Description | | - | - | - | | directory | string | Relative to your gulpfile.js, point to where your versioned files are stored. | | original | string | Pass the original filename so the comparison can match files after the version number has be verified | | keep | int | Define how many versions of your versioned files you want to keep. By default this is set to 5.|

versioniser.deleteVersions('assets/js/', 'main.min.js', 3)


Credit

Couldn't have built this without gulp-dotenv. Thank you!