CLI and library for adding hashes to file names and creating TypeScript enum, sass variables, JavaScript const, and CSS variables with hashed asset paths.
You can install via npm or yarn.
npm install --save @qntm-code/asset-hasher
yarn add @qntm-code/asset-hasher
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.
asset-hasher --from src/assets --output src/assets-hashed --tsEnum src/enums/assets.ts
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 |
The library can be used to generate a TypeScript enum, sass variables, JavaScript const, or CSS variables with hashed asset paths.
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,
});