Giter Club home page Giter Club logo

grunt-sync's Introduction

Grunt-sync

A grunt task to keep directories in sync. It is very similar to grunt-contrib-copy but tries to copy only those files that has actually changed.

Usage

npm install grunt-sync --save

Within your grunt file:

grunt.initConfig({

sync: {
main: {
files: [{
  cwd: 'src',
  src: [
    '**', /* Include everything */
    '!**/*.txt' /* but exclude txt files */
  ],
  dest: 'bin',
}],
pretend: true, // Don't do any IO. Before you run the task with `updateAndDelete` PLEASE MAKE SURE it doesn't remove too much.
verbose: true // Display log messages when copying files
}
}

});

grunt.loadNpmTasks('grunt-sync');
grunt.registerTask('default', 'sync');

More examples

sync: {
  main: {
    files: [
      {src: ['path/**'], dest: 'dest/'}, // includes files in path and its subdirs
      {cwd: 'path/', src: ['**/*.js', '**/*.css'], dest: 'dest/'}, // makes all src relative to cwd
    ],
    verbose: true, // Default: false
    pretend: true, // Don't do any disk operations - just write log. Default: false
    failOnError: true, // Fail the task when copying is not possible. Default: false
    ignoreInDest: "**/*.js", // Never remove js files from destination. Default: none
    updateAndDelete: true, // Remove all files from dest that are not found in src. Default: false
    compareUsing: "md5" // compares via md5 hash of file contents, instead of file modification time. Default: "mtime"

  }
}

Installation

npm install grunt-sync --save

How it works?

In the first phase the plugin compares modification times of files in src and dest. It only copies files with newer modification time. Second phase deletes files that exists in dest but have not been found in src.

Details:

  1. [1st phase] Read modification time of all files in src.
  2. [1] Overwrite destination if modification time is newer or destination is directory not file.
  3. [2nd phase]* Get a list of the files in dest and calculate difference between destination and source.
  4. [2]* Delete all files (and directories) that have been found in dest but are not found src excluding ignored files.

*second phase only occurs if updateAndDelete is set to true (whitch is set to false by default)

Changelog

  • 0.5.0 - Synchronous removal of directories (to avoid race conditions)
  • 0.4.0 - Adding better patterns support for ignoreInDest
  • 0.3.0 - Comparison using md5 hash of file contents or modification time
  • 0.2.4 - failOnError option
  • 0.2.3 - Fixed issue with files defined as array when using updateAndDelete.
  • 0.2.2 - Fixed issue with updateAndDelete when source patterns matches only files.
  • 0.2.1 - Fixed grunt Compact Format.
  • 0.2.0 - Default configuration will not remove any files any more. You have to specify updateAndDelete option to remove any files from destination.
  • 0.1.2 - Deleting all files in destination on Windows solved.
  • 0.1.1 - Fixed issue with trailing slash in destination.
  • 0.1.0 - Files missing that are not in src are deleted from dest (unless you specify updateOnly)

Migration 0.1.x -> 0.2.x

In version 0.2 you have to explicitly specify that you want the plugin to remove files from destination. See updateAndDelete option and run with pretend:true first to make sure that it doesn't remove any crucial files. You can tune what files should be left untouched with ignoreInDest property.

If you have updateOnly:true in your 0.1 config you can remove this option. For those who used updateOnly:false you have to include updateAndDelete:true in 0.2 config to keep the same behavior.

Contributors

TODO

  • Research if it's possible to have better integration with grunt-contrib-watch - update only changed files instead of scanning everything.
  • Some tests for common problems
  • Some tests to assure performance
  • Rewrite updateAndDelete in more elegant way (maybe use patterns from source?)

grunt-sync's People

Contributors

betalb avatar erwanjegouzo avatar majidfn avatar neogenet1c avatar tomusdrw avatar xzyfer avatar yousfisaad avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.