dir-snap
v0.3.0
Published
This compares the contents of a directory against a previous snapshot.
Downloads
13
Maintainers
Readme
dir-snap - A snappy directory snapshot tool
This module makes it easy to compare before and after snapshots of your project's filesystem. Simply use dirsnap
to create a reference point (dirsnap reference
), then make as many changes as you want. When you want to see what has changed, run a compare (dirsnap compare
) and the files that have been altered will be displayed.
Installation
Install globally via npm:
$ npm install -g dir-snap
Or globally via yarn:
$ yarn global add dir-snap
Usage
Please note that the command to use in the CLI is
dirsnap
with no hypen.
Reference
reference
is a very simple function that creates a snapshot of the current folder structure. Pass in a folder to begin searching through and an extension for the filetype you care about (dirsnap reference -f ./myProject -e js
).
$ dirsnap reference -f [folder] -e <ext>
When the scanning has completed, a reference JSON file will be written in the .dirsnap
folder of the project to be used later during a compare. This library currently uses the MD5 checksum of a file for comparison purposes.
NOTE: The filename will be
${extension}FileReference.json
.
An example of the JSON structure looks like this:
{
"cwd": "/Users/FakeUser/Git/dir-snap/test/testParent",
"date": "2017-09-03T03:06:23.079Z",
"ext": "js",
"files": {
"/Users/FakeUser/Git/dir-snap/test/testParent": {
"javascript.js": "496dd81dea39fb0b0c07be50c2fc67a3",
"javascript.min.js": "1d6a42d2095f51127215e64c5f67da11"
},
"/Users/FakeUser/Git/dir-snap/test/testParent/models": {}
},
"folder": "./",
"store": "./"
}
Compare
compare
scans through the folder passed in and produces an updated snapshot to compare with the latest reference file. Once the compare happens, a colorized diff will be logged for all files that have changed since the reference was made.
$ dirsnap compare -f [folder] -e <ext>
$ dirsnap compare -f ./my-project -e js
List
list
will output all reference files that are for a specific folder. This makes it easy to check what reference files have been created and can be compared against.
$ dirsnap list -f [folder]
// Example output:
// EXT DATE FILE
// js 2017-09-03T03:07:24.079Z jsFileReference.json
// css 2017-09-03T03:06:23.079Z cssFileReference.json
Reset
reset
will delete one or all reference files for a specific folder. Use if you need to start over or have made significant changes to the folder structure.
$ dirsnap reset -f [folder] -e [ext]
NOTE: If a folder is not passed in, this command will delete all reference files tied to the current working directory.
Specifying a reference directory
Sometimes the folder being examined is not the best location for the .dirsnap
directory (e.g. running a test that deletes and then recreates a folder). In these cases, the store
option can be utilized for the compare
and reference
commands to indicate which folder to store the reference files in.
$ dirsnap reference -f [folder] -e [ext] -s [referenceFolder]
$ dirsnap reference -f ./my-project -e js -s ./references
License
Copyright Lance Turri. Released under the terms of the MIT license.