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

hash-and-manifest

v1.0.2

Published

Hash directory files a generate configurable manifest

Downloads

3

Readme

Hash and Manifest

Simple tool to take a directory of files, calculate their md5 hashes, rename them to [name].[hash].[ext] and generate a manifest at given path, whose contents are generated via templating function.


Install and use

Install

npm i -S hash-and-manifest

NPM scripts usage

{
	"scripts": {
		"manifest": "hash-and-manifest",
		"manifest:empty": "hash-and-manifest empty"
	}
}

Usage: detailed

Create the ham.config.js file in the root of your project, like so:

module.exports = {
	directory: 'path/to/assets',
	manifest: 'path/to/manifest.ext', 
	template: (files) => { return string }
}
  • directory: string, describes a path to your assets directory relative to current working directory
  • manifest: string, relative path with filename and desired extension. What you do with the manifest further is on you
  • template: function, which generates the content of manifest for you. It is given one argument: files object
    • files object: object in the format {original_name: hashed_name}

Add a hash-and-manifest call in your package.json in the desired step of your build chain.

Generate empty manifest

HAM also has a single argumented call to be used in npm scripts - hash-and-manifest empty, which generates empty manifest. This is to be used at the beginning of watch/build loops, so you can expect existing manifest at the desired place at all times.

Example configurations

These are the configuration I use for my specific usecases: in production environment, assets get built into "dist" folder, fingerprinted and deployed. In development, they are watched and continuously built into dev folder and not fingerprinted because cache is turned off locally. Both dev and dist folders are ignored in the repositories.

Note: I generate a function to be called in the end system which includes the list of files. Generating empty manifest and returning "development" version of the URL is how I deal with watch/build loop locally.

Eleventy

module.exports = {
	directory: 'site/assets/dist',
	manifest: 'data/assets.js',
	template: files => (`module.exports = _ => file => {
	const list = ['${Object.keys(files).join(`','`)}']
	const files = {
		${Object.keys(files).map(k => `'${k}': '${files[k]}'`).join(`,
		`)}
	}

	return Object.keys(files).includes(file) ? ${'`dist/${files[file]}`'} : ${'`dev/${file}`'}
}`)
}

Kirby CMS

module.exports = {
	directory: 'source-folder',
	manifest: 'site/snippets/_bundler.php',
	template: files => (`<?php
	if (! function_exists('bundle')) {
		function bundle($key = '') {
			$manifest = [
				${Object.keys(files).map(k => `'${k}' => '${files[k]}'`).join(`,
				`)}
			];
			return array_key_exists($key, $manifest) ? "dist/" . $manifest[$key] : "dev/" . $key;
		}
	}
	`)
}

license

ISC, since it's the NPM default. Adam Kiss 2021