# hash-and-manifest

> Hash directory files a generate configurable manifest

Latest version **2.0.0** (published 2025-01-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install hash-and-manifest
pnpm add hash-and-manifest
yarn add hash-and-manifest
bun add hash-and-manifest
```

Provides the command `hash-and-manifest`.

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-01-20 |
| First published | 2021-04-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Adam Kiss |
| Maintainers | adamkiss |
| Keywords | hash, manifest, asset, fingerprint |

## Links

- npm: https://www.npmjs.com/package/hash-and-manifest
- Repository: https://github.com/adamkiss/hash-and-manifest
- Homepage: https://github.com/adamkiss/hash-and-manifest#readme
- Issues: https://github.com/adamkiss/hash-and-manifest/issues
- npm.io page: https://npm.io/package/hash-and-manifest

## Dependencies (1)

- [hasha](https://npm.io/package/hasha.md) ^6.0.0

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2025-01-20
- 1.0.2 — 2021-04-18
- 1.0.1 — 2021-04-18
- 1.0.0 — 2021-04-18

## 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

``` bash
pnpm i -S hash-and-manifest
```

### NPM scripts usage

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

### Usage: detailed

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

``` js
export default {
	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.

### Silence the little "generating…" notification

Both `hash-and-manifest` and `hash-and-manifest empty` can be silenced like so:
- `hash-and-manifest -s`
- `hash-and-manifest empty -s`

## 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](https://www.11ty.dev)

``` js
export default {
	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](https://getkirby.com)

``` js
export default {
	directory: 'source-folder',
	manifest: 'site/snippets/_assets.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 2025

---
_Source: https://npm.io/package/hash-and-manifest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
