@qntm-code/asset-hasher
v2.0.1
Published
CLI and library for adding hashes to file names and creating TypeScript enum, sass variables, JavaScript const, and CSS variables with hashed asset paths
Downloads
8
Maintainers
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.
Installation
You can install via npm or yarn.
npm
npm install --save @qntm-code/asset-hasher
yarn
yarn add @qntm-code/asset-hasher
CLI Usage
Help
Run the following command to see the available options.
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
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
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,
});