rollback
Rollback a directory to a prior snapshot
Last updated 3 months ago by justinlivi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install rollback 
SYNC missed versions from official npm registry.

Rollback

Gitlab pipeline status Coverage Status David NPM node npm Greenkeeper badge 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:

property type description
path string the path of the temporary directory
cleanup () => void manually cleans up the temporary directory
rollback (options?: RollbackOptions) => Promise<void> asynchronously rolls back any changes to the snapshot
rollbackSync (options?: RollbackOptions) => void synchronously 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

Current Tags

  • 0.2.9                                ...           latest (3 months ago)

12 Versions

  • 0.2.9                                ...           3 months ago
  • 0.2.8                                ...           3 months ago
  • 0.2.7                                ...           3 months ago
  • 0.2.6                                ...           3 months ago
  • 0.2.5                                ...           5 months ago
  • 0.2.4                                ...           6 months ago
  • 0.2.3                                ...           6 months ago
  • 0.2.2                                ...           6 months ago
  • 0.2.1                                ...           6 months ago
  • 0.2.0                                ...           7 months ago
  • 0.1.1                                ...           7 months ago
  • 0.1.0                                ...           7 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (6)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |