0.0.12 • Published 4 years ago

rsyncjs v0.0.12

Weekly downloads
-
License
GPL-3.0-or-later
Repository
gitlab
Last release
4 years ago

Description

rsyncjs provides a similar API to rsync, but in pure js.

With some additional features, such as splitting large files and quota throttling support.

Todo: Convert to TS 4.5 and export ESM

Based on sync-directory by @gh:hoperyy

Releases

Examples

Node

import { async as rsync } from 'rsyncjs'

const sleep = (s) => new Promise((p) => setTimeout(p, s * 1000))

console.time('rsync')

const main = async () => {
  await rsync(srcDir, targetDir, {
    async afterEachSync({ type, relativePath }) {
      console.log(type, relativePath)
      await sleep(1.5) // delay 1.5s after one file was synced
    }
  })
  console.timeEnd('rsync')
}
main()

Shell

# yarn add global rsyncjs
# npx -y rsyncjs <from> <to> [options]
npm install -g rsyncjs
rsyncjs <from> <to> [options]

Synchronous use via deasync

var rsyncjsCJS = require('rsyncjs')
var deasync = require('deasync')
var rsync = deasync(rsyncjsCJS.async)

Browser use with FileSystem API

Not tested... but willing to support it.

API

importReturnsSyntaxBlocks thread?
asyncPromiseasync / await, promisesNo

Params

namedescriptiontypevaluesdefault
srcDirsrc directoryStringabsolute path-
targetDirtarget directoryStringabsolute path-
config.deleteOrphanedDelete other files in targetDirBoolean-true
config.afterEachSynccallback function when every file syncedFunction-blank function
config.excludefiles that should not sync to target directory.RegExp / String / Array (item is RegExp / String)-null
config.forceSyncsome files must be synced even though 'excluded'Function-(file) => { return false }
config.filterfunction to filter. Syncs file when trueFunction-filepath => true
config.onErrorcallback function when something wrongFunction-(err) => { throw new Error(err) }
  • afterEachSync

    await rsync(srcDir, targetDir, {
      async afterEachSync({ type, relativePath }) {
        // type: init:hardlink / init:copy / add / change / unlink / unlinkDir
        // - init type: "init:copy"
        // - watch type: "add" / "change" / "unlink" / "unlinkDir"
        // relativePath: relative file path
      }
    })
  • type

    • copy

      rsync(srcDir, targetDir, {
        type: 'copy'
      })
  • exclude

    exclude node_modules

    • String

      rsync(srcDir, targetDir, {
        exclude: 'node_modules'
      })
    • RegExp

      rsync(srcDir, targetDir, {
        exclude: /node\_modules/
      })
    • Array

      rsync(srcDir, targetDir, {
        exclude: [/node\_modules/]
      })
      rsync(srcDir, targetDir, {
        exclude: ['node_modules']
      })
  • forceSync

    rsync(srcDir, targetDir, {
      exclude: 'node_modules',
      forceSync(file) {
        // all files in "node_modules" will be synced event though "exclude" is configed
        return /node_modules/.test(file)
      }
    })

Cli

options:

  • --quiet

    Disable unnecessary logs.

  • -do, --deleteOrphaned

    Delete orphaned files/folders in target folder. false as default.

    Same as api deleteOrphaned.

Contributing

  • Keep dependencies to a minimum, devDependencies are less of an issue.
  • Make sure your tests pass on the latest official Node LTS image
    • This is what CodeSandbox runs
0.0.11

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago