Comparing version 0.2.3 to 0.2.4
# changelog | ||
## 0.2.4 | ||
* Add `appendFile` and `appendFileSync` methods ([#2](https://github.com/Rich-Harris/sander/issues/2)) | ||
## 0.2.2-0.2.3 | ||
@@ -4,0 +8,0 @@ |
66
index.js
@@ -313,43 +313,43 @@ var path = require( 'path' ), | ||
// sander.writeFile and sander.writeFileSync | ||
[ true, false ].forEach( function ( isSync ) { | ||
var qualifiedMethodName, method; | ||
// sander.[write|append]File[Sync?] | ||
[ 'writeFile', 'appendFile' ].forEach( function ( methodName ) { | ||
[ true, false ].forEach( function ( isSync ) { | ||
var qualifiedMethodName = methodName + ( isSync ? 'Sync' : '' ); | ||
qualifiedMethodName = isSync ? 'writeFileSync' : 'writeFile'; | ||
function method () { | ||
var data, pathargs = [], i, dest; | ||
method = function () { | ||
var data, pathargs = [], i, dest; | ||
i = arguments.length; | ||
data = arguments[ --i ]; | ||
i = arguments.length; | ||
data = arguments[ --i ]; | ||
while ( i-- ) { | ||
pathargs[i] = arguments[i]; | ||
} | ||
while ( i-- ) { | ||
pathargs[i] = arguments[i]; | ||
} | ||
dest = resolve( pathargs ); | ||
dest = resolve( pathargs ); | ||
if ( isSync ) { | ||
mkdirp.sync( path.dirname( dest ) ); | ||
return fs[ qualifiedMethodName ]( dest, data ); | ||
} | ||
if ( isSync ) { | ||
mkdirp.sync( path.dirname( dest ) ); | ||
return fs.writeFileSync( dest, data ); | ||
} | ||
return new Promise( function ( fulfil, reject ) { | ||
mkdirp( path.dirname( dest ), function ( err ) { | ||
if ( err ) { | ||
reject( err ); | ||
} else { | ||
fs.writeFile( dest, data, function ( err ) { | ||
if ( err ) { | ||
reject( err ); | ||
} else { | ||
fulfil(); | ||
} | ||
}); | ||
} | ||
return new Promise( function ( fulfil, reject ) { | ||
mkdirp( path.dirname( dest ), function ( err ) { | ||
if ( err ) { | ||
reject( err ); | ||
} else { | ||
fs[ qualifiedMethodName ]( dest, data, function ( err ) { | ||
if ( err ) { | ||
reject( err ); | ||
} else { | ||
fulfil(); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
}; | ||
sander[ qualifiedMethodName ] = method; | ||
sander[ qualifiedMethodName ] = method; | ||
}); | ||
}); | ||
@@ -356,0 +356,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"author": "Rich Harris", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "repository": "https://github.com/rich-harris/sander", |
@@ -1,8 +0,11 @@ | ||
var fs = require( 'fs' ), | ||
path = require( 'path' ), | ||
crc32 = require( 'buffer-crc32' ), | ||
sander = require( '../' ); | ||
var fs = require( 'fs' ); | ||
var path = require( 'path' ); | ||
var assert = require( 'assert' ); | ||
var crc32 = require( 'buffer-crc32' ); | ||
var sander = require( '../' ); | ||
sander.rimrafSync( __dirname, 'output' ); | ||
process.chdir( __dirname ); | ||
sander.rimrafSync( 'output' ); | ||
tests = [ | ||
@@ -12,6 +15,23 @@ { | ||
test: function () { | ||
return sander.copydir( __dirname, 'input', 'dir' ).to( __dirname, 'output', '1' ).then( function () { | ||
checkEquality([ __dirname, 'input', 'dir' ], [ __dirname, 'output', '1' ]); | ||
return sander.copydir( 'input', 'dir' ).to( 'output', '1' ).then( function () { | ||
checkEquality([ 'input', 'dir' ], [ 'output', '1' ]); | ||
}); | ||
} | ||
}, | ||
{ | ||
name: 'appendFile', | ||
test: function () { | ||
return sander.writeFile( 'output/2/test.txt', 'first line' ) | ||
.then( function () { | ||
return sander.appendFile( 'output/2/test.txt', '\nsecond line' ) | ||
}) | ||
.then( function () { | ||
return sander.readFile( 'output/2/test.txt' ) | ||
.then( String ) | ||
.then( function ( combined ) { | ||
assert.equal( combined, 'first line\nsecond line' ); | ||
}); | ||
}); | ||
} | ||
} | ||
@@ -54,5 +74,3 @@ ]; | ||
if ( statsA.isDirectory() ) { | ||
if ( !statsB.isDirectory() ) { | ||
throw new Error( a + ' is a directory but ' + b + ' is not' ); | ||
} | ||
assert.ok( statsB.isDirectory(), a + ' is a directory but ' + b + ' is not' ); | ||
@@ -62,5 +80,3 @@ filesA = fs.readdirSync( a ); | ||
if ( !compareArrays( filesA, filesB ) ) { | ||
throw new Error( 'Directory contents differ: ' + a + ', ' + b ); | ||
} | ||
assert.ok( compareArrays( filesA, filesB ) ); | ||
@@ -77,5 +93,3 @@ i = filesA.length; | ||
if ( crcA.toString() !== crcB.toString() ) { | ||
throw new Error( 'File contents differ' ); | ||
} | ||
assert.equal( crcA.toString(), crcB.toString() ); | ||
} | ||
@@ -82,0 +96,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25735
641
8