Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-webdav-sync

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-webdav-sync - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

19

gulpfile.js

@@ -6,3 +6,3 @@ var debug = require( 'gulp-debug' )

var jshint = require( 'gulp-jshint' )
var npm = require( 'npm' )
var npmconf = require( 'npmconf' )
var runSequence = require( 'run-sequence' )

@@ -19,4 +19,4 @@ var stylish = require( 'jshint-stylish' )

gulp.task( 'npm.load', function ( callback ) {
if ( !npm.config.loaded ) {
npm.load( null, function () {
if ( !npmconf.loaded ) {
npmconf.load( null, function () {
callback()

@@ -28,11 +28,14 @@ } )

gulp.task( 'debug', function () {
if ( npm.config.sources.user ) {
uri = npm.config.sources.user.data.dav
if ( npmconf.loaded.sources.global ) {
uri = npmconf.loaded.sources.global.data.dav
}
if ( npm.config.sources.project ) {
uri = npm.config.sources.project.data.dav
if ( npmconf.loaded.sources.user ) {
uri = npmconf.loaded.sources.user.data.dav
}
if ( npmconf.loaded.sources.project ) {
uri = npmconf.loaded.sources.project.data.dav
}
return gulp.src( 'test/assets/*' )
.pipe( debug( { title: 'pre' } ) )
.pipe( dav( uri ) )
.pipe( dav() )
.pipe( debug( { title: 'post' } ) )

@@ -39,0 +42,0 @@ } )

var gutil = require( 'gulp-util' )
var http = require( 'http' )
var through2 = require( 'through2' )
var npmconf = require( 'npmconf' )
var path = require( 'path' )
var Stream = require( 'stream' )
var url = require( 'url' )

@@ -9,69 +11,83 @@

module.exports = function ( i ) {
return through2.obj( function ( vinyl, encoding, callback ) {
var uri = i + vinyl.relative
this.pause()
stream = new Stream.Transform( { objectMode: true } )
stream._transform = function ( vinyl, encoding, callback ) {
if ( !npmconf.loaded ) {
npmconf.load( null, init )
} else {
init()
}
function report( res ) {
gutil.log(
uri
, res.statusCode
, http.STATUS_CODES[res.statusCode]
)
function init() {
if ( i && typeof i == 'string' ) {
uri = i + vinyl.relative
} else {
uri = target() + vinyl.relative
}
if ( vinyl.isBuffer() ) {
_put( uri, vinyl, resume )
return
}
if ( vinyl.isNull() ) {
_mkdir( uri, resume )
return
}
if ( vinyl.isStream() ) {
_put( uri, vinyl, resume )
return
}
callback( null, vinyl )
}
if ( vinyl.isBuffer() ) {
put( uri, vinyl, function ( res ) {
report( res )
callback()
} )
this.resume()
return
function target() {
var href
if ( npmconf.loaded.sources.global ) {
href = npmconf.loaded.sources.global.data.dav
}
if ( npmconf.loaded.sources.user ) {
href = npmconf.loaded.sources.user.data.dav
}
if ( npmconf.loaded.sources.project ) {
href = npmconf.loaded.sources.project.data.dav
}
return href
}
if ( vinyl.isNull() ) {
mkdir( uri, function ( res ) {
function resume( res ) {
if ( res ) {
report( res )
callback()
} )
this.resume()
return
}
callback()
}
if ( vinyl.isStream() ) {
put( uri, vinyl, function ( res ) {
report( res )
callback()
} )
this.resume()
return
function report( res ) {
gutil.log(
uri
, res.statusCode
, http.STATUS_CODES[res.statusCode]
)
}
callback( null, vinyl )
this.resume()
} )
}
return stream
}
function mkdir( uri, callback ) {
function _mkdir( uri, callback ) {
var options, req
options = url.parse( uri )
options.method = 'MKCOL'
req = http.request( options, function ( res ) {
callback( res )
} )
req.on( 'error', function ( e ) {
throw new gutil.PluginError( PLUGIN_NAME, e.toString() )
} )
req = http.request( options, callback )
req.on( 'error', _on_error )
req.end()
}
function put( uri, vinyl, callback ) {
function _put( uri, vinyl, callback ) {
var options, req
options = url.parse( uri )
options.method = 'PUT'
req = http.request( options, function ( res ) {
callback( res )
} )
req = http.request( options, callback )
vinyl.pipe( req )
req.on( 'error', function ( e ) {
} )
req.on( 'error', _on_error )
}
function _on_error( error ) {
stream.emit( 'error', error )
}
{
"name": "gulp-webdav-sync",
"version": "0.0.2",
"version": "0.0.3",
"description": "Put files and folders on a WebDAV server. Deploy with gulp",

@@ -33,3 +33,2 @@ "repository": {

"mocha": "~2.2.5",
"npm": "~2.13.0",
"run-sequence": "~1.1.1"

@@ -39,4 +38,4 @@ },

"gulp-util": "~3.0.6",
"through2": "~2.0.0"
"npmconf": "~2.1.2"
}
}

@@ -5,2 +5,7 @@ # gulp-webdav-sync

## Usage
Target is loaded from npmrc - global, user, or project file, or may be passed as the first parameter.
```shell
npm set dav http://user:pass@localhost:8000/
```
```js

@@ -11,3 +16,3 @@ var dav = require( 'gulp-webdav-sync' )

return gulp.src( '*' )
.pipe( dav( url ) )
.pipe( dav() )
} )

@@ -14,0 +19,0 @@ ```

@@ -6,6 +6,6 @@ var assert = require( 'assert' )

var fs = require( 'fs' )
var npm = require( 'npm' )
var mod = require( '../index' )
var npmconf = require( 'npmconf' )
var os = require( 'os' )
var path = require( 'path' )
var unit = require( '../index' )
var url = require( 'url' )

@@ -21,4 +21,4 @@ var Vinyl = require( 'vinyl' )

before( function ( done ) {
npm.load( null, function () {
node = path.join( npm.config.prefix, TEMP )
npmconf.load( null, function () {
node = path.join( npmconf.loaded.prefix, TEMP )
if ( !fs.existsSync( node ) ) {

@@ -29,4 +29,4 @@ fs.mkdirSync( node )

var opt = { node: node }
var srv = dav.createServer( opt, uri.port, uri.hostname )
process.nextTick( function () {
var srv = dav.mount( opt )
srv.listen( uri.port, uri.hostname, function () {
done()

@@ -40,2 +40,3 @@ } )

after( function () {
del( path.join( node, '**' ) )
if ( fs.existsSync( node ) ) {

@@ -46,11 +47,22 @@ fs.rmdirSync( node )

describe( '#mkdir', function () {
it( 'Should create a file on the server when vinyl.isBuffer()'
describe( '#main', function () {
it( 'Should throw exception with "dav:" scheme'
, function ( done ) {
var expected_path = path.join( node, MOCK )
var mock = new Vinyl( { path: MOCK, contents: new Buffer( MOCK ) } )
assert( mock.isBuffer(), 'vinyl.isBuffer()' )
unit( HREF ).write( mock, null, validate )
var uri = url.parse( HREF )
uri.protocol = 'dav:'
assert.throws(
function () {
mod( uri.format() ).write( mock, null, validate )
}
, /not supported/
)
validate()
function validate() {
assert( fs.existsSync( expected_path ), 'file exists' )
assert.equal(
fs.existsSync( expected_path )
, false
, 'file does not exist'
)
done()

@@ -60,5 +72,43 @@ }

)
it( 'Should emit an "error" event on refused connection ( closed port )'
, function ( done ) {
var expected_path = path.join( node, MOCK )
var mock = new Vinyl( { path: MOCK, contents: new Buffer( MOCK ) } )
var uri = url.parse( HREF )
var mal = {
protocol: uri.protocol
, slashes: uri.slashes
, auth: uri.auth
, port: 65536
, hostname: uri.hostname
, hash: uri.hash
, search: uri.search
, query: uri.query
, pathname: uri.pathname
, path: uri.path
}
var expected= new Error( 'connect ECONNREFUSED' )
expected.code = 'ECONNREFUSED'
expected.errno = 'ECONNREFUSED'
expected.syscall = 'connect'
var unit = mod( url.format( mal ) )
unit.on( 'error', function ( actual ) {
assert.deepEqual( actual, expected, 'error is ECONNREFUSED' )
validate()
} )
unit.write( mock, null, null )
function validate() {
assert.equal(
fs.existsSync( expected_path )
, false
, 'file does not exist'
)
done()
}
}
)
} )
describe( '#mkdir', function () {
describe( '#_mkdir', function () {
it( 'Should create a directory on the server when vinyl.isNull()'

@@ -69,3 +119,4 @@ , function ( done ) {

assert( mock.isNull(), 'vinyl.isNull()' )
unit( HREF ).write( mock, null, validate )
var unit = mod( HREF )
unit.write( mock, null, validate )
function validate() {

@@ -79,3 +130,16 @@ assert( fs.existsSync( expected_path ), 'directory exists' )

describe( '#mkdir', function () {
describe( '#_put', function () {
it( 'Should create a file on the server when vinyl.isBuffer()'
, function ( done ) {
var expected_path = path.join( node, MOCK )
var mock = new Vinyl( { path: MOCK, contents: new Buffer( MOCK ) } )
assert( mock.isBuffer(), 'vinyl.isBuffer()' )
var unit = mod( HREF )
unit.write( mock, null, validate )
function validate() {
assert( fs.existsSync( expected_path ), 'file exists' )
done()
}
}
)
it( 'Should create a file on the server when vinyl.isStream()'

@@ -87,3 +151,4 @@ , function ( done ) {

assert( mock.isStream(), 'vinyl.isStream()' )
unit( HREF ).write( mock, null, validate )
var unit = mod( HREF )
unit.write( mock, null, validate )
function validate() {

@@ -90,0 +155,0 @@ assert( fs.existsSync( expected_path ), 'file exists' )

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc