# tree-sync

> A module for repeated efficient synchronizing two directories.

Latest version **2.1.0** (published 2020-06-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install tree-sync
pnpm add tree-sync
yarn add tree-sync
bun add tree-sync
```

## 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 | 2020-06-23 |
| First published | 2016-01-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 5 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Stefan Penner |
| Maintainers | hjdivad, rwjblue, stefanpenner |

## Links

- npm: https://www.npmjs.com/package/tree-sync
- Repository: https://github.com/stefanpenner/tree-sync
- Homepage: https://github.com/stefanpenner/tree-sync#readme
- Issues: https://github.com/stefanpenner/tree-sync/issues
- npm.io page: https://npm.io/package/tree-sync

## Dependencies (5)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.5
- [walk-sync](https://npm.io/package/walk-sync.md) ^0.3.3
- [quick-temp](https://npm.io/package/quick-temp.md) ^0.1.5
- [fs-tree-diff](https://npm.io/package/fs-tree-diff.md) ^2.0.1

## Recent versions

- 2.1.0 (latest) — 2020-06-23
- 2.0.0 — 2019-01-28
- 1.4.0 — 2018-12-05
- 1.3.0 — 2018-11-30
- 1.2.2 — 2017-01-12
- 1.2.1 — 2016-12-09
- 1.2.0 — 2016-12-09
- 1.1.5 — 2016-11-24
- 1.1.4 — 2016-08-09
- 1.1.3 — 2016-08-05
- 1.1.2 — 2016-07-11
- 1.1.1 — 2016-03-28
- 1.1.0 — 2016-03-03
- 1.0.2 — 2016-02-15
- 1.0.1 — 2016-01-25
- … 1 more at https://npm.io/package/tree-sync/versions

## README

# TreeSync ![CI](https://github.com/stefanpenner/tree-sync/workflows/CI/badge.svg)

A module for repeated efficient synchronizing two directories.

```js
// input/a/{a.js,b.js}
// output/

const tree = new TreeSync('input', 'output');
tree.sync();
// output is now contains copies of everything that is in input

fs.unlink('/input/a/b.js');

// input / output have diverged

tree.sync();

// difference is calculated and efficient patch to update `output` is created and applied
```

Under the hood, this library uses [walk-sync](https://github.com/joliss/node-walk-sync) to traverse files and folders. You may optionally pass in options to selectively include or ignore files and directories. These whitelisted properties (`ignore` and `globs`) will be passed to walk-sync.

```js
// Assume the following folder structure...
// input/
//   foo/
//     foo.js
//     bar.js
//   bar/
//     foo-bar.js

const tree = new TreeSync('input', 'output', {
  ignore: ['**/b']
});
tree.sync();

// We now expect output to contain foo/, but not bar/.
// Any changes made to bar/ won't be synced to output, and the contents of bar/ won't be traversed.
```

```js
// Assume the following folder structure...
// input/
//   foo/
//     foo.js
//     bar.js
//   bar/
//     foo-bar.js

const tree = new TreeSync('input', 'output', {
  globs: ['foo', 'foo/bar.js']
});
tree.sync();

// We now expect output to contain foo/bar.js, but nothing else.
// Be careful when using this property! You'll need to make sure that if you're including a file, it's parent
// path is also included, or you'll get an error when tree-sync tries to copy the file over.
```

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