0.2.16 • Published 4 years ago

rollback v0.2.16

Weekly downloads
17
License
MIT
Repository
github
Last release
4 years ago

Rollback

Gitlab pipeline status Coverage Status David NPM node npm

npm type definitions

Rollback the rock!

Alt text

Undo pesky file system mutations with ease.

Installation

npm i -s rollback

Both typescript and javascript support come out of the box.

Basic Usage

Asynchronous API

Take a snapshot of a directory.

import { snapshot } from 'rollback';
import { writeFileSync } from 'fs';

snapshot({
  path: '/some/directory'
}).then(snap => {
  // make some changes
  writeFileSync('/some/directory/myFile', 'some updates');
  // then rollback all the changes
  return snap.rollback();
});

Take a snapshot of a file.

import { snapshotFile } from 'rollback';
import { writeFileSync } from 'fs';

snapshotFile({
  path: '/some/file.txt'
}).then(snap => {
  // make some changes
  writeFileSync('/some/file.txt', 'some updates');
  // then rollback all the changes
  return snap.rollback();
});

Synchronous API

Take a snapshot of a directory.

import { snapshotSync } from 'rollback';
import { writeFileSync } from 'fs';

const snap = snapshotSync({
  path: '/some/directory'
});
writeFileSync('/some/directory/myFile', 'some updates');
snap.rollbackSync();

Take a snapshot of a file.

import { snapshotFileSync } from 'rollback';
import { writeFileSync } from 'fs';

const snap = snapshotFileSync({
  path: '/some/file.txt'
});
writeFileSync('/some/file.txt', 'some updates');
snap.rollbackSync();

Advanced Usage

Rollback exposes four base methods: snapshot, snapshotSync, snapshotFile, and snapshotFileSync.

All methods accept all configuration options exposed by tmp.

Additionally the following options from fs-extra's copy are supported:

preserveTimestamps, filter, recursive (recursive is only supported for snapshot and snapshotSync)

snapshot and snapshotFile return a Promise which resolves with a Snapshot object.

snapshotSync and snapshotFileSync return a Snapshot directly.

Snapshot

A Snapshot object has the following properties:

propertytypedescription
pathstringthe path of the temporary directory
cleanup() => voidmanually cleans up the temporary directory
rollback(options?: RollbackOptions) => Promise<void>asynchronously rolls back any changes to the snapshot
rollbackSync(options?: RollbackOptions) => voidsynchronously rolls back any changes to the snapshot

RollbackOptions takes the following form:

interface RollbackOptions {
  preserveTimestamps?: boolean;
  recursive?: boolean; // only supported if the snapshot is of a directory 
}

The default for rollback options is whatever was specified in the snapshot, snapshotSync, snapshotFile, or snapshotFileSync invocation that generated the Snapshot object.

API Documentation

API

License

Licensed under MIT

0.2.16

4 years ago

0.2.15

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago