gulp-file-sync
v2.1.0
Published
Sync file It keeps your files synced between two directory. In other words, any change of files in one directory will automatically take place in another one.
Downloads
1,308
Maintainers
Readme
gulp-file-sync
Sync file It keeps your files synced between two directory. In other words, any change of files in one directory will automatically take place in another one.
Migration from Version 1
If you were previously passing a function as an ignore option, you'll have to replace the old function signature dir
with stats
. We made this change in 2.0.0.
Installation
npm install --save-dev gulp-file-sync
Usage
var gulp = require('gulp'),
fileSync = require('gulp-file-sync');
gulp.task('sync', function() {
gulp.watch(['src/*.*'], function() {
fileSync('src', 'dest', {recursive: false});
});
});
API
fileSync('source directory', 'destination directory', options)
'source directory' and 'destination directory'
type: String
Any change of files in 'source directory' will automatically take place in 'destination directory'.
options.recursive
type: Boolean
default: true
Synchronize subdirectories recursively.
options.ignore
type: string
or array
or regex
or function
Either a string, array, regex, or function to exclude some specific files. For example:
// ignore all .log files
fileSync('source directory', 'destination directory', {
ignore: '.log'
})
fileSync('source directory', 'destination directory', {
ignore: [/^\.log$/i, '.cache'] // Exclude all .log and .cache files
})
fileSync('source directory', 'destination directory', {
ignore: /^\.log$/i
})
fileSync('source directory', 'destination directory', {
ignore: function(stats, file) {
if (stats.isFile()) {
return file === '.log';
}
return false;
}
})
options.addFileCallback
type: function(fullPathSrc, fullPathDest)
default:
var gutil = require('gulp-util');
function(fullPathSrc, fullPathDest) {
gutil.log('File addition synced ' + fullPathDest);
}
This function is called when file was added on source directory.
fullPathSrc
- is the path of file that was added on source directory.fullPathDest
- is the path of file that was copied to destination directory.
options.deleteFileCallback
type: function(fullPathSrc, fullPathDest)
default:
var gutil = require('gulp-util');
function(fullPathSrc, fullPathDest) {
gutil.log('File deletion synced ' + fullPathDest);
}
This function is called when file was deleted on source directory.
fullPathSrc
- is the path of file that was deleted on source directory.fullPathDest
- is the path of file that was deleted on destination directory.
options.updateFileCallback
type: function(fullPathSrc, fullPathDest)
default:
var gutil = require('gulp-util');
function(fullPathSrc, fullPathDest) {
gutil.log('File modification synced ' + fullPathDest);
}
This function is called when file was updated on source directory.
fullPathSrc
- is the path of file that was updated on source directory.fullPathDest
- is the path of file that was copied to destination directory.
options.beforeAddFileCallback
type: function(fullPathSrc)
This function is called before file is added on source directory.
fullPathSrc
- is the path of file that was added on source directory.
options.beforeDeleteFileCallback
type: function(fullPathSrc)
This function is called before file is deleted on source directory.
fullPathSrc
- is the path of file that was deleted on source directory.
options.beforeUpdateFileCallback
type: function(fullPathSrc)
This function is called before file is updated on source directory.
fullPathSrc
- is the path of file that was updated on source directory.
License
MIT (c) 2015 Kayo Lee ([email protected])