Browse files

Add the ability to set the source directory

  • Loading branch information...
1 parent 842f3c9 commit 97357fd4e63811ac2ee47190adda15d699fdf6a6 @ZECTBynmo committed Jan 23, 2013
Showing with 21 additions and 12 deletions.
  1. +4 −3 README.md
  2. +16 −9 mover.js
  3. +1 −0 test.js
View
7 README.md
@@ -14,7 +14,7 @@ var plan = {
files: [
"LICENSE",
],
-
+
"folder3" : {
files: [
"package.json",
@@ -38,11 +38,12 @@ var plan = require("./movingPlan").plan,
// Setup our mover
mover.setPlan( plan, false ); // Use absolute paths
-mover.setDest( process.cwd() ); // Set our destination folder
+mover.setSrc( process.cwd() ); // Set our source folder (defaults to process.cwd())
+mover.setDest( process.cwd() ); // Set our destination folder (defaults to process.cwd())
mover.move( function() {
console.log( "All moved in" );
});
```
-Try running "node test.js" inside the project directory to test things out :)
+Try running "node test.js" inside the project directory. It will create some folders and copy some stuff around.
View
25 mover.js
@@ -12,8 +12,8 @@
*/
//////////////////////////////////////////////////////////////////////////
// Node.js Exports
-exports.createMover = function( plan, isRelativePaths, dest ) {
- return new Mover( plan, isRelativePaths, dest );
+exports.createMover = function( plan, isRelativePaths, src, dest ) {
+ return new Mover( plan, isRelativePaths, src, dest );
}
//////////////////////////////////////////////////////////////////////////
@@ -38,10 +38,10 @@ var async = require("async"),
//////////////////////////////////////////////////////////////////////////
// Constructor
-function Mover( plan, isRelativePaths, dest ) {
+function Mover( plan, isRelativePaths, src, dest ) {
this.plan = plan || {};
this.dest = dest || process.cwd();
-
+ this.src = src || process.cwd();
this.isRelativePaths = isRelativePaths || false; // True when our input
// paths are relative
} // end Mover()
@@ -56,24 +56,31 @@ Mover.prototype.setPlan = function( plan, isRelativePaths ) {
//////////////////////////////////////////////////////////////////////////
-// Sets a new plan for this mover
+// Sets the location that we'll move our output files to
Mover.prototype.setDest = function( dest ) {
this.dest = dest;
} // end setPlan()
//////////////////////////////////////////////////////////////////////////
+// Sets the place we're getting out input files
+Mover.prototype.setSrc = function( src ) {
+ this.src = src;
+} // end setPlan()
+
+
+//////////////////////////////////////////////////////////////////////////
// Move all the things
Mover.prototype.move = function( callback ) {
var outputMap = this.getOutputMap(),
- strPrepend = this.isRelativePaths ? process.cwd() + "/" : this.dest + "/",
+ destPath = this.isRelativePaths ? process.cwd() + "/" : this.dest + "/",
outputArray = [];
// We need to create an array of the output files, so that we can
// use async to iterate through it
for( var iFile in outputMap ) {
- var input = strPrepend + iFile,
- output = strPrepend + outputMap[iFile];
+ var input = this.src + "/" + iFile,
+ output = destPath + outputMap[iFile];
var fileMapping = {
input : input,
@@ -91,7 +98,7 @@ Mover.prototype.move = function( callback ) {
log( "Moving " + outputArray.length + " Files", true );
- async.mapSeries( outputArray, fnIterator, callback);
+ async.forEach( outputArray, fnIterator, callback);
} // end move()
View
1 test.js
@@ -3,6 +3,7 @@ var plan = require("./testplan").plan,
// Setup our mover
mover.setPlan( plan, false ); // Use absolute paths
+mover.setSrc( process.cwd() ); // Set our source folder
mover.setDest( process.cwd() ); // Set our destination folder
mover.move( function() {

0 comments on commit 97357fd

Please sign in to comment.