Deploy files and folders via WebDAV
npm install gulp-webdav-sync* Similar Projects
* Destinations
* URL as String
* URL as Object
* Subdirectories
* Continuous Deploying: Creates, Updates, Deletes
* With gulp.watch
* With gulp-watch
* API
* [webdav( [ href ] [, options ] )](#webdav--href---options--)
* [webdav( [ href ] [, options ] ).clean( [ cb ] )](#webdav--href---options--clean--cb--)
* [webdav( [ href ] [, options ] ).watch( event [, cb ] )](#webdav--href---options--watch-event--cb--)
* cb
* event
* href
* options
* options.base
* options.clean
* options.log
* options.logAuth
* options.uselastmodified
* Development
shell
curl -T "index.js" http://:@localhost:8000/
curl -X MKCOL http://:@localhost:8000/dir/
`Destinations
Pass a URL argument indicating a directory/collection on a WebDAV server. Include any HTTP authentication inline or in the options argument. HTTPS authentication must go in the options argument. Pipe to this module instead of gulp.dest().
$3
`js
var webdav = require( 'gulp-webdav-sync' )// put index.js to http://localhost:8000/js/index.js
gulp.task( 'deploy', function () {
return gulp.src( 'index.js' )
.pipe( webdav( 'http://:@localhost:8000/js/' ) )
} )
`
$3
Extend a request options object.
See request's documention for HTTP authentication, and TLS authentication/verification.
`js
var webdav = require( 'gulp-webdav-sync' )// put index.js to http://localhost:8000/js/index.js
gulp.task( 'deploy', function () {
var options = {
protocol: 'http:'
, auth: {
'user': ''
, 'pass': ''
, 'sendImmediately': false // use http digest authentication
}
, hostname: 'localhost'
, port: 8000
, pathname: '/js/'
, log: 'info' // show status codes
, logAuth: true // show credentials in urls
}
return gulp.src( 'index.js' )
.pipe( webdav( options ) )
} )
`
$3
Suppose the following directory tree,
* project/
* dist/
* css/
* images/
* js/and this destination,
* localhost:8000/
* css/
* images/
* js/
use the
'base' option to constrain the localpath mapping,
`js
var webdav = require( 'gulp-webdav-sync' )gulp.task( 'deploy', function () {
var options = {
'base': 'dist'
, 'log': 'info'
, 'port': 8000
}
return gulp.src( 'dist/**' )
.pipe( webdav( options ) )
} )
`
otherwise, the result is this.
* localhost:8000/
* _dist/_
* css/
* images/
* js/Continuous Deploying: Creates, Updates, Deletes
By combining methods, most cases can be satisfied, however deleting directories may be inconsistent.
If any file changes or there is a creation in the path, then gulp.watch will re-stream all files.
The uselastmodified option ( default ) compares the local time to the server time so as to only upload updates.
Deletes emit a different object; not in the stream, but with a change event.$3
browser-sync, npmconf, and .npmrc for a save-sync-reload solution.
`shell
npm set dav http://user:pass@localhost:8000/js/
`
`js
var browserSync = require( 'browser-sync' ).create()
var webdav = require( 'gulp-webdav-sync' )
var npmconf = require( 'npmconf' )
var paths = {
'js': [ '*.js', '!gulpfile.js' ]
}
var href
var options = {
'log': 'info'
}gulp.task( 'default', [ 'deploy' ], function () {
browserSync.init( { proxy: href } )
gulp.watch( paths.js, [ 'deploy' ] )
.on( 'change', webdav( href, options ).watch )
.on( 'change', browserSync.reload )
} )
gulp.task( 'deploy', [ 'load-npmrc' ], function () {
return gulp.src( paths.js )
.pipe( webdav( href, options ) )
} )
gulp.task( 'load-npmrc', function ( cb ) {
npmconf.load( null, function() {
if ( npmconf.loaded.sources.user ) {
href = npmconf.loaded.sources.user.data.dav
}
cb()
} )
} )
`$3
gulp-watch uses a different strategy of extending the file objects in stream.
It re-emits created, modified, and deleted files.
Delete/'unlink' type events are attempted on the server as well.
`js
var browserSync = require( 'browser-sync' ).create()
var watch = require( 'gulp-watch' )
var webdav = require( 'gulp-webdav-sync' )
var paths = {
'js': [ '*.js', '!gulpfile.js' ]
}
var href = 'http://localhost'gulp.task( 'deploy', function () {
browserSync.init( { proxy: href } )
return gulp.src( paths.js )
.pipe( watch( paths.js ) )
.pipe( webdav( href, { log: 'info' } ) )
.pipe( browserSync.stream() )
} )
`API
$3
Target is a URL-type parameter whereto files are uploaded. It must specify a directory ( also known as a "collection" ). At a minimum this must be DAV root, but subdirectories may be included ( e.g. project name ). Part-wise definition across multiple arguments is undefined. Use the http: or https: scheme, not dav:.$3
Deletes all resources under href.$3
Callback adapter for 'change' events from gulp.watch. Only handles type: 'deleted' events. gulp.src does not push deleted files; use this or gulp-watch instead. Calls back regardless of event.type.#### cb
Optional, asynchronous, callback function.
Type:
Function
Default: undefined#### event
glob-watcher event.
`js
{
type: 'deleted'
, path: '/absolute/path.ext'
}
`Type:
Object
Default: undefined#### href
Type:
String
Default: undefined#### options
Superset of request options parameter. If any URL properties are defined, then
protocol, hostname, and pathname are assigned to http://localhost/.
If options.agent is undefined, then a http[s] agent will be created for the stream.Type:
Object
Default:
`js
{
'clean': false
, 'headers': { 'User-Agent': PLUGIN_NAME + '/' + VERSION }
, 'log': 'error'
, 'logAuth': false
, 'base': process.cwd()
, 'uselastmodified': 1000
}
`##### options.base
Relative or absolute path which halves the source path [
vinyl.path] for appending the subsequent to the DAV destination URI. Use with glob to prevent super-directories from being created on the destination. e.g. gulp.src( 'dist/' ).Type:
String
Default: process.cwd()##### options.clean
Deletes corresponding resources on server instead of uploading. Note, glob star-star will delete directories before contents are pushed.
Type:
Boolean
Default: false##### options.log
Logging threshold. Orthogonal to the
console methods. string | output
:-------: | --------------
'error' |
'warn' |
'info' | HTTP Responses
'log' | DebugType:
String
Default: 'error'##### options.logAuth
Display credentials in logged URLs.
Type:
Boolean
Default: false##### options.uselastmodified
Compare remote
getlastmodified versus local ( changed ) ctime.
Only PUT if ctime is newer than getlastmodified.
Numeric value in milliseconds is the tolerance interval for qualifying client-server synchronization.
Set to false to disable.Type:
Number
Default: 1000 msDevelopment
OpenSSL is required to generate certificates for unit testing.`shell
cd gulp-webdav-sync
npm install
npm test
npm set dav http://:@localhost:8000/
gulp
``