# fx43

> Detecting changed files via caching file modification time

Latest version **2.1.0** (published 2018-04-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install fx43
pnpm add fx43
yarn add fx43
bun add fx43
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2018-04-18 |
| First published | 2017-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 6 |
| Unpacked size | 23.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mgen |
| Maintainers | mgenware |
| Keywords | file changes, file system |

## Links

- npm: https://www.npmjs.com/package/fx43
- Repository: https://github.com/mgenware/fx43-node
- Issues: https://github.com/mgenware/fx43-node/issues
- npm.io page: https://npm.io/package/fx43

## Dependencies (6)

- [jest](https://npm.io/package/jest.md) ^22.4.3
- [write](https://npm.io/package/write.md) ^1.0.3
- [fx58-node](https://npm.io/package/fx58-node.md) ^1.0.5
- [@types/jest](https://npm.io/package/@types/jest.md) ^22.2.3
- [ignore-walk](https://npm.io/package/ignore-walk.md) ^3.0.1
- [mkdirp-promise](https://npm.io/package/mkdirp-promise.md) ^5.0.1

## Recent versions

- 2.1.0 (latest) — 2018-04-18
- 2.0.3 — 2018-02-10
- 2.0.2 — 2018-01-17
- 2.0.1 — 2018-01-17
- 2.0.0 — 2018-01-17
- 1.0.1 — 2018-01-14
- 0.0.11 — 2017-10-20
- 0.0.10 — 2017-10-20
- 0.0.9 — 2017-10-18
- 0.0.8 — 2017-10-15
- 0.0.7 — 2017-10-14
- 0.0.6 — 2017-10-14
- 0.0.5 — 2017-10-13
- 0.0.4 — 2017-10-12
- 0.0.3 — 2017-10-12
- … 2 more at https://npm.io/package/fx43/versions

## README

# fx43-node

[![MEAN Module](https://img.shields.io/badge/MEAN%20Module-TypeScript-blue.svg)](https://github.com/mgenware/MEAN-Module)
[![Build Status](https://travis-ci.org/mgenware/fx43-node.svg?branch=master)](http://travis-ci.org/mgenware/fx43-node)
[![npm version](https://badge.fury.io/js/fx43.svg)](https://badge.fury.io/js/fx43)
[![Node.js Version](http://img.shields.io/node/v/fx43.svg)](https://nodejs.org/en/)

Detecting changed files via caching file modification time.

## Installation
```sh
# npm
npm install --save fx43

# yarn
yarn add fx43
```

Run tests:
```sh
# npm
npm test

# yarn
yarn test
```

# Usage
Fx43 offers 3 ways to track files:
* All files mode: all files are tracked.
* Ignore file mode: like `.gitignore`, tracks files in respect to nested ignore files.
* Custom mode: tracks files filtered by custom JavaScript functions.

### All files mode
```js
import { startAllFilesModeAsync } from 'fx43';
// ES5: const startAllFilesModeAsync = require('fx43').startAllFilesModeAsync;

startAllFilesModeAsync(
  rootDirectory: string,
  cacheDirectory: string,
  ignoreCache: boolean = false,
): Promise<string[]>;
```

### Ignore file mode
```js
import { startIgnoreFileModeAsync } from 'fx43';
// ES5: const startIgnoreFileModeAsync = require('fx43').startIgnoreFileModeAsync;

startIgnoreFileModeAsync(
  rootDirectory: string,
  ignoreFiles: string[],   // e.g. ['.myignore', '.gitignore']
  cacheDirectory: string,
  ignoreCache: boolean = false,
): Promise<string[]>;
```

### Custom mode
```js
import { startCustomModeAsync } from 'fx43';
// ES5: const startCustomModeAsync = require('fx43').startCustomModeAsync;

startCustomModeAsync(
  rootDirectory: string,
  cacheDirectory: string,
  ignoreCache: boolean = false,
  // use this to filter files
  fileFilter: ((fileName: string) => boolean) | null = null,
  // use this to filter directories
  dirFilter: ((dirName: string) => boolean) | null = null,
): Promise<string[]>;
```

## Example
Suppose you have some files in a directory named `data`:
```
- data/
  index.html
  main.js
  style.css
  lib/
    lib.js
```

You need to track all changed `.js` files. In this case, you can use ignore file mode. Define an ignore file like `.gitignore`, for example, `.myignore` with the following contents:
```
# .myignore
# put this file to the root folder of the project

# ignore html and css files
*.html
*.css
```

Then call fx43 APIs like this:
```javascript
import { startIgnoreFileModeAsync } from 'fx43';

async function printChangedFiles() {
  const files = await startIgnoreFileModeAsync('./data', ['.myignore'], './.cache');
  console.log(`${files.length} file(s) changed.\n${files}`);
}

(async () => {
  await printChangedFiles();
})();
```

```sh
# run the program
node example.js
# output
2 file(s) changed.
main.js
lib/lib.js

# run the program
node example.js
# output
0 file(s) changed.

# modify and create some files
touch ./data/lib/lib.js
touch ./data/new.js
# run the program
node example.js
# output
2 file(s) changed.
lib/lib.js
new.js

# modify an irrelevant file
touch ./data/style.css
# run the program
node example.js
# output
0 file(s) changed.
```

For more examples, see [examples](https://github.com/mgenware/fx43-node/tree/master/examples).

---
_Source: https://npm.io/package/fx43 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
