1.3.3 • Published 7 months ago

cache-changed v1.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

cache-changed

A simple library to monitor changes in a directory and cache the results. It allows you to compare the current state of a directory with its previous state, and return a list of added, updated, and deleted files. The library also provides a method to create a cache of the current state of the directory.

Npm package license Npm package dependents PRs Welcome

The library uses only asynchronous operations where possible. Due to this, better performance is expected. But no error stack, so the library pass all errors to call method and you should add to your log new Error().stack as shown below.

Installation

npm i cache-changed

Usage

Import CacheChanged class and get an instance of it:

import CacheChanged from 'cache-changed';

const cacheChanged = new CacheChanged({
  // Default /tmp-dir-of-your-os/cache-cached_[basename(CWD)].json
  cacheFilePath: './tmp/cache.json',
  // Default [CWD]
  targetDirPath: './',
  // Default ['.git'], if passed then concat with default
  exclude: ['node_modules', 'some-dir/node_modules'],
});

Creating a cache from the targetDirPath directory to the cacheFilePath file:

cacheChanged
  .create({
    noWrite: false,
  })
  .catch((err) => {
    // Log error with a stack
    console.error('Failed to create cache', err, new Error().stack);
  })
  .then((code) => {
    console.log('Created cache files count', code);
  });

Comparison of cache from file cacheFilePath and directory targetDirPath:

cacheChanged
  .compare()
  .catch((err) => {
    // Log error with a stack
    console.error('Failed to compare cache', err, new Error().stack);
  })
  .then((res) => {
    console.log('Compared cache result', res);
  });

Result of compare:

{
  "added": [],
  "updated": [
    {
      "pathAbs": "/home/user/projects/cache-changed/.gitignore",
      "pathRel": ".gitignore",
      "mtimeMs": 1705743775005.3252,
      "size": 16,
      "isDir": false
    }
  ],
  "deleted": [],
  "isChanged": true
}

Links

1.3.3

7 months ago

1.3.2

12 months ago

1.3.1

12 months ago

1.2.0

1 year ago

1.1.3

1 year ago

1.3.0

1 year ago

1.2.1

1 year ago

1.1.1

1 year ago

1.1.2

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.1.0

1 year ago

0.0.15

1 year ago

0.0.17

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago