2.0.1 • Published 1 year ago

@qntm-code/asset-hasher v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@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 Quality Gate Status codecov

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

OptionAliasDescriptionTypeRequired
--from-fGlob pattern of the assets to hashGlob pattern of the assets to hashstringtrue
--to-tThe path to the directory where the hashed assets will be writtenstringtrue
--removePaths-rComma or space separated partial paths to remove from the hashed asset enum/const/variables pathsstringfalse
--watch-wWhether to watch the assets directory for changesbooleanfalse
--ignoreInitial-iIgnores the files that already exists when starting with watch enabledbooleanfalse
--tsEnumPath-tsThe path to create the TypeScript enum containing the paths of the hashed assets. If not specified, the enum will not be createdstringfalse
--jsConstPath-jsThe path to create the JavaScript const containing the paths of the hashed assets. If not specified, the const will not be createdstringfalse
--sassVariablesPath-sassThe path to create the sass variables containing the paths of the hashed assets. If not specified, the variables will not be createdstringfalse
--cssVariablesPath-cssThe path to create the CSS variables containing the paths of the hashed assets. If not specified, the variables will not be createdstringfalse
--silent-sWhether to suppress all loggingbooleanfalse
--help-hShow helpbooleanfalse

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,
});