$ cnpm install 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.
This package is not actively developed any more.
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');
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"
}
}
npm install grunt-sync --save
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:
src.dest and calculate difference between destination and source.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)
ignoreInDestfailOnError optionupdateAndDelete.updateAndDelete when source patterns matches only files.updateAndDelete option to remove any files from destination.src are deleted from dest (unless you specify updateOnly)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.
grunt-contrib-watch - update only changed files instead of scanning everything.updateAndDelete in more elegant way (maybe use patterns from source?)Copyright 2013 - present © cnpmjs.org | Home |