UNPKG

@olegjs/on-change

Version:

CLI tool to run a command if file has changed since the last time that command was run

25 lines (19 loc) 620 B
const { basename, dirname, format: formatPath, join: joinPath, } = require('path') const { createHash } = require('crypto') const { algorithm: default_algorithm, fileExtension } = require('./defaults') const getChecksum = (s, algorithm = default_algorithm, format = 'hex') => createHash(algorithm) .update(s) .digest(format) const hashFromFileContent = s => s.trim().split(/\s+/)[0] const getChecksumFilePath = path => joinPath( dirname(path), formatPath({ name: `.${basename(path)}`, ext: fileExtension }), ) module.exports = { getChecksum, getChecksumFilePath, hashFromFileContent }