# @qntm-code/asset-hasher

> CLI and library for adding hashes to file names and creating TypeScript enum, sass variables, JavaScript const, and CSS variables with hashed asset paths

Latest version **2.0.1** (published 2023-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @qntm-code/asset-hasher
pnpm add @qntm-code/asset-hasher
yarn add @qntm-code/asset-hasher
bun add @qntm-code/asset-hasher
```

Provides the command `asset-hasher`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2023-02-10 |
| First published | 2023-01-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 27.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ben Meyrick |
| Maintainers | bameyrick |
| Keywords | hasher, asset, asset hasher, enum, const, variables, cli |

## Links

- npm: https://www.npmjs.com/package/@qntm-code/asset-hasher
- Repository: https://github.com/bameyrick/asset-hasher
- Homepage: https://github.com/bameyrick/asset-hasher#readme
- Issues: https://github.com/bameyrick/asset-hasher/issues
- npm.io page: https://npm.io/package/@qntm-code/asset-hasher

## Dependencies (7)

- [glob](https://npm.io/package/glob.md) ^8.0.3
- [rxjs](https://npm.io/package/rxjs.md) ^7.8.0
- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [yargs](https://npm.io/package/yargs.md) ^17.6.2
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.3
- [@qntm-code/utils](https://npm.io/package/@qntm-code/utils.md) ^2.8.1

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2023-02-10
- 2.0.0 — 2023-02-08
- 1.0.3 — 2023-02-08
- 1.0.2 — 2023-01-09
- 1.0.1 — 2023-01-09
- 1.0.0 — 2023-01-09

## README

# @qntm-code/asset-hasher

CLI and library for adding hashes to file names and creating TypeScript enum, sass variables, JavaScript const, and CSS variables with hashed asset paths.

[![GitHub release](https://img.shields.io/github/release/bameyrick/asset-hasher.svg)](https://github.com/bameyrick/asset-hasher/releases)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=bameyrick_asset-hasher&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=bameyrick_asset-hasher)
[![codecov](https://codecov.io/gh/bameyrick/asset-hasher/branch/main/graph/badge.svg)](https://codecov.io/gh/bameyrick/asset-hasher)

- [@qntm-code/asset-hasher](#qntm-codeasset-hasher)
  - [Installation](#installation)
    - [npm](#npm)
    - [yarn](#yarn)
  - [CLI Usage](#cli-usage)
    - [Help](#help)
    - [CLI Example](#cli-example)
    - [Options](#options)
  - [Library Usage](#library-usage)
    - [Library Example](#library-example)

## Installation

You can install via npm or yarn.

### npm

```bash
npm install --save @qntm-code/asset-hasher
```

### yarn

```bash
yarn add @qntm-code/asset-hasher
```

## CLI Usage

### Help

Run the following command to see the available options.

```bash
asset-hasher --help
```

The CLI can be used to generate a TypeScript enum, sass variables, JavaScript const, or CSS variables with hashed asset paths.

### CLI Example

```bash
asset-hasher --from src/assets --output src/assets-hashed --tsEnum src/enums/assets.ts
```

### Options

| Option                | Alias   | Description                                                                                                                          | Type      | Required |
| --------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------ | --------- | -------- |
| `--from`              | `-f`    | Glob pattern of the assets to hashGlob pattern of the assets to hash                                                                 | `string`  | `true`   |
| `--to`                | `-t`    | The path to the directory where the hashed assets will be written                                                                    | `string`  | `true`   |
| `--removePaths`       | `-r`    | Comma or space separated partial paths to remove from the hashed asset enum/const/variables paths                                    | `string`  | `false`  |
| `--watch`             | `-w`    | Whether to watch the assets directory for changes                                                                                    | `boolean` | `false`  |
| `--ignoreInitial`     | `-i`    | Ignores the files that already exists when starting with watch enabled                                                               | `boolean` | `false`  |
| `--tsEnumPath`        | `-ts`   | The path to create the TypeScript enum containing the paths of the hashed assets. If not specified, the enum will not be created     | `string`  | `false`  |
| `--jsConstPath`       | `-js`   | The path to create the JavaScript const containing the paths of the hashed assets. If not specified, the const will not be created   | `string`  | `false`  |
| `--sassVariablesPath` | `-sass` | The path to create the sass variables containing the paths of the hashed assets. If not specified, the variables will not be created | `string`  | `false`  |
| `--cssVariablesPath`  | `-css`  | The path to create the CSS variables containing the paths of the hashed assets. If not specified, the variables will not be created  | `string`  | `false`  |
| `--silent`            | `-s`    | Whether to suppress all logging                                                                                                      | `boolean` | `false`  |
| `--help`              | `-h`    | Show help                                                                                                                            | `boolean` | `false`  |

## Library Usage

The library can be used to generate a TypeScript enum, sass variables, JavaScript const, or CSS variables with hashed asset paths.

### Library Example

```typescript
import { AssetHasher } from '@qntm-code/asset-hasher';

await hashAssets({
  from: 'src/assets',
  to: 'src/assets-hashed',
  tsEnum: 'src/enums/assets.ts',
  jsConst: 'src/constants/assets.js',
  sassVars: 'src/styles/assets.scss',
  cssVars: 'src/styles/assets.css',
  removePaths: ['src/assets', 'src/assets-hashed'],
  watch: false,
  silent: false,
});
```

---
_Source: https://npm.io/package/@qntm-code/asset-hasher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
