This repository is no longer active or maintained.
Please check out the replacement repositories
- Python (https://github.com/balain/fingerprinter-py) and
- Rust (https://github.com/balain/fingerprinter-rs)
Take a (recursive) snapshot of a folder & compare against earlier snapshots.
Minimal external dependencies - only md5-file
(to fingerprint individual files) & crypto
(to set the snapshot filename, based on the full directory pathname)
The simple intent is to identify what files need to be uploaded to a remote webserver after a local static site rebuild (e.g. using Hugo). git
could provide the same functionality, but brings a lot of baggage. This tool is very lightweight and simple to use with minimal dependencies.
- TypeScript installed (
tsc
) - Node modules
md5-file
: Capture MD5 for individual files https://github.com/kodie/md5-filecrypto
: For SHA256 hash of pathname (i.e. the snapshot filename)
- Pull
git pull https://github.com/balain/fingerprinter
- Install Node modules
npm install
- Compile
npm run build
(ortsc
ortsc --watch
)
takeSnapshot(pathname)
: Takes a snapshot of the path provided. Nothing is returned.isChanged(pathname, updateSnapshot=false)
: Compare the current contents with the previous snapshot, optionally updating the snapshot file to the current contents (default: do not update the snapshot file). (Promise)
- Returns an array - empty if no changes, otherwise, a list of filenames that have changed.
- Throws an error if the snapshot doesn't exist.
node fingerprinter.js add <pathname>
to take a snapshotnode fingerprinter.js check <pathname>
to calculate the delta
const fingerprinter = require('./fingerprinter.js')
// Take an explicit snapshot
// fingerprinter.takeSnapshot('.')
// Has anything has changed since the previous snapshot?
// ...do not update the snapshot file
fingerprinter.isChanged('.', false)
.then((changes: any[]) => {
console.log(`latestChanges: `, changes.length ? changes : 'no changes')
})
// Has anything has changed since the previous snapshot?
// ...update the snapshot file
fingerprinter.isChanged('.', true)
.then((changes: any[]) => {
console.log(`latestChanges: `, changes.length ? changes : 'no changes')
})
sha256(absolutePathname)
saved in the OS temp directory (per os.tmpdir()
)
[
{
"path": "...",
"processDate": "...",
"files": [
{ "name": "A",
"md5": "..." },
...
]
]
Distributed under the MIT license. See LICENSE
for more information.