not-sync
TypeScript icon, indicating that this package has built-in type declarations

1.4.1 • Public • Published

not-sync

Disable synchronization for files in cloud storage such as Dropbox, iCloudDrive or OneDrive. Detects cloud storage provider.

Synopsis

import { notSync, resync } from "not-sync";
// Disable synchronization for following directories.
await notSync(["node_modules", "coverage", "dist"]);
// Provide cwd for a project located in `${os.homedir()}/Dropbox/project`.
await notSync(["node_modules", "coverage", "dist"], { cwd: `${os.homedir()}/Dropbox/project` });
// If new new files are added to project directory (e.g. iCloudDrive .nosync files) add new files
// to closest ".gitignore". (Here "node_modules.nosync", "coverage.nosync", "dist.nosync")
await notSync(["node_modules", "coverage", "dist"], { ignoreConfigs: [".gitignore"] });
// Enable synchronization for following directories.
await resync(["node_modules", "coverage", "dist"]);
await notSync(["node_modules", "coverage", "dist"], {
  cwd: "path/to/cwd",
  ignoreConfigs: [".gitignore", ".prettierignore"],
  dry: false;
  ci: false,
  on: {
    found: (service, files) => { },
    notFound: (files) => { },
    move: (service, from, to) => { },
    moveFail: (service, errorCode, from, to) => { },
    symlink: (service, target, path) => { },
    delete: (service, path, type) => { },
    addEntry: (service, ignoreFile, entries) => { },
    deleteEntry: (service, ignoreFile, entries) => { },
  },
  verbose: false,
  roots: {
    iCloudDrive: os.platform() === "darwin"
      ? `${os.homedir()}/Library/Mobile Documents/com~apple~CloudDocs/`
      : `${os.homedir()}/iCloudDrive`,
    dropBox: `${os.homedir()}/Dropbox`,
    oneDrive: `${os.homedir()}/OneDrive`
  }
  targetRoots: {
    iCloudDrive: `${iCloudDriveRoot}/../iCloudDrive Linked Files`
    dropBox: `${dropboxRoot}/../Dropbox Linked Files`,
    oneDrive: `${oneDriveRoot}/../OneDrive Linked Files`,
  }
  linkSameDir: true, // Add ".nosync" files to near of original files for "iCloudDrive".
})

Minimal CLI

For more advanced options, please use not-sync-cli

$ not-sync node_modules,dist,coverage
$ resync node_modules,dist,coverage

Details

This module disables and enables synchronization of given files and directories from cloud storage. Possibly could be used to save space, time and sometimes prevent headache, especially for heavy by size and number of files directories such as node_modules.

notSync function moves files/directories to another non-synchronized path (see table below) and creates a symbolic link in place of original files. resync function deletes symbolic links and moves files back to original place.

Features

  • Does not execute commands on a CI (Continous Integration) environment. To enable set options.ci to true.
  • Could be used more than one cloud storage services.
  • Provides resync method for undoing changes.
  • Auto detect cloud storage service from file path.
  • Could use .nosync extension for iCloudDrive.
  • Minimal CLI. For more advanced options, please use not-sync-cli

Below are examples for node_modules directory located in a project:

Service Option Source Target
iCloudDrive ${iCloudDrive}/project/node_modules ${iCloudDrive}/project/node_modules.nosync
iCloudDrive linkSameDir: false ${iCloudDrive}/project/node_modules ${os.homedir()}/iCloudDrive Linked Files/project/node_modules
Dropbox ${Dropbox}/project/node_modules ${os.homedir()}/Dropbox Linked Files/project/node_modules
OneDrive ${OneDrive}/project/node_modules ${os.homedir()}/OneDrive Linked Files/project/node_modules

Target directory can be changed using targetRoots option.

API

not-sync

not-sync

Table of contents

Interfaces

Type aliases

Functions

Type aliases

MoveErrorCode

Ƭ MoveErrorCode: NOSRC | LINKEXIST | NOTALINK | NOTFOUND | NOTARGET

Defined in: index.ts:6


OnAddEntry

Ƭ OnAddEntry: (service: ServiceKey, ignoreFile: string, entries: string[]) => any | Promise<any>

Defined in: index.ts:13


OnDelete

Ƭ OnDelete: (service: ServiceKey, path: string, type: symlink | parent) => any | Promise<any>

Defined in: index.ts:12


OnDeleteEntry

Ƭ OnDeleteEntry: (service: ServiceKey, ignoreFile: string, entries: string[]) => any | Promise<any>

Defined in: index.ts:14


OnFound

Ƭ OnFound: (service: ServiceKey, files: string[]) => any | Promise<any>

Defined in: index.ts:7


OnMove

Ƭ OnMove: (service: ServiceKey, from: string, to: string) => any | Promise<any>

Defined in: index.ts:9


OnMoveFail

Ƭ OnMoveFail: (service: ServiceKey, errorCode: MoveErrorCode, from?: string, to?: string) => any | Promise<any>

Defined in: index.ts:10


OnNotFound

Ƭ OnNotFound: (files: string[]) => any | Promise<any>

Defined in: index.ts:8


OnSymlink

Ƭ OnSymlink: (service: ServiceKey, target: string, path: string) => any | Promise<any>

Defined in: index.ts:11


ServiceKey

Ƭ ServiceKey: iCloudDrive | dropbox | oneDrive

Defined in: cloud-service/cloud-service.ts:21

Functions

notSync

notSync(paths: string[], options?: Options): Promise<void>

Parameters:

Name Type Default value
paths string[] -
options Options ...

Returns: Promise<void>

Defined in: main.ts:34


resync

resync(paths: string[], options?: Options): Promise<void>

Parameters:

Name Type Default value
paths string[] -
options Options ...

Returns: Promise<void>

Defined in: main.ts:30

Interfaces

not-sync / Events

Interface: Events

Hierarchy

  • Events

Table of contents

Properties

Properties

addEntry

Optional addEntry: undefined | OnAddEntry

Defined in: index.ts:23


delete

Optional delete: undefined | OnDelete

Defined in: index.ts:22


deleteEntry

Optional deleteEntry: undefined | OnDeleteEntry

Defined in: index.ts:24


found

Optional found: undefined | OnFound

Defined in: index.ts:17


move

Optional move: undefined | OnMove

Defined in: index.ts:19


moveFail

Optional moveFail: undefined | OnMoveFail

Defined in: index.ts:20


notFound

Optional notFound: undefined | OnNotFound

Defined in: index.ts:18


symlink

Optional symlink: undefined | OnSymlink

Defined in: index.ts:21

not-sync / Options

Interface: Options

Options

Hierarchy

  • Options

Table of contents

Properties

Properties

ci

Optional ci: undefined | boolean

By default "not-sync" does not excute any command on a CI (continous integration) environment. Set this option to true to execute on the CI.

Defined in: index.ts:48


createDirs

Optional createDirs: undefined | boolean

Create directories for non existing paths. (If they are in a cloud path). This may be used to disable sync of directories to be created in future.

Defined in: index.ts:46


cwd

Optional cwd: undefined | string

Current working directory to be used for resolving relative paths.

Defined in: index.ts:30


dry

Optional dry: undefined | boolean

Prevents changes to be written to disk. Executes a dry run.

Defined in: index.ts:34


ignoreConfigs

Optional ignoreConfigs: undefined | string | string[]

Ignore configuration files (e.g. .gitignore, .prettierignore) to add new created files if any.

Defined in: index.ts:32


linkSameDir

Optional linkSameDir: undefined | boolean

Move files near original one for iCloudDrive. For example "node_modules" is moved "node_modules.nosync" in same directory.

Defined in: index.ts:40


on

Optional on: undefined | Events

Event handler functions to act on several events generated during operation.

Defined in: index.ts:36


roots

Optional roots: undefined | Partial<Record<ServiceKey, string>>

Roots of cloud services. If default roots has to be changed for same reson.

Defined in: index.ts:44


targetRoots

Optional targetRoots: undefined | Partial<Record<ServiceKey, string>>

Custom roots for each cloud service to move files.

Defined in: index.ts:42


verbose

Optional verbose: undefined | boolean

Adds extra information to event handlers.

Defined in: index.ts:38

Related

not-sync-cli: CLI for this API.

Package Sidebar

Install

npm i not-sync

Weekly Downloads

59

Version

1.4.1

License

MIT

Unpacked Size

209 kB

Total Files

64

Last publish

Collaborators

  • ozum