rightclick
Advanced tools
Comparing version 0.4.2 to 0.4.3
# rightClick Changelog | ||
### 7 March 2013, 0.4.2 | ||
### 27 March 2014, 0.4.3 | ||
* Use path.resolve() | ||
### 7 March 2014, 0.4.2 | ||
* Arguments issue | ||
@@ -6,0 +10,0 @@ |
var fs = require('fs'), | ||
sep = require('path').sep; | ||
path = require('path'); | ||
module.exports = function (path) { | ||
module.exports = function (docPath) { | ||
@@ -10,14 +10,14 @@ // Clear clipboard. | ||
// Push single path into array object | ||
if (typeof path === 'string') { | ||
if (typeof docPath === 'string') { | ||
path = [path]; | ||
docPath = [docPath]; | ||
} | ||
path.forEach(function (path) { | ||
docPath.forEach(function (docPath) { | ||
var fullPath = this.clipboard.target + sep + path, | ||
var fullPath = path.resolve(this.clipboard.target, docPath), | ||
enc = this.enc; | ||
var copy = function (fullPath, path, clip) { | ||
var copy = function (fullPath, docPath, clip) { | ||
@@ -27,3 +27,3 @@ if (fs.statSync(fullPath).isDirectory()) { | ||
// Create folder object and update local reference to it. | ||
clip = clip[path] = {}; | ||
clip = clip[docPath] = {}; | ||
@@ -33,8 +33,8 @@ // Get source folder contents. | ||
paths.forEach(function (path) { | ||
paths.forEach(function (docPath) { | ||
var newPath = fullPath + sep + path; | ||
var newPath = path.resolve(fullPath, docPath); | ||
// Copy down into the next level. | ||
copy.call(this, newPath, path, clip); | ||
copy.call(this, newPath, docPath, clip); | ||
@@ -46,3 +46,3 @@ }, this); | ||
// Copy file content to clipboard. | ||
clip[path] = fs.readFileSync(fullPath, enc); | ||
clip[docPath] = fs.readFileSync(fullPath, enc); | ||
@@ -59,3 +59,3 @@ } | ||
// Begin deep copy. | ||
copy.call(this, fullPath, path, clip); | ||
copy.call(this, fullPath, docPath, clip); | ||
@@ -68,2 +68,2 @@ } | ||
}; | ||
}; |
@@ -1,7 +0,7 @@ | ||
module.exports = function (path) { | ||
module.exports = function (docPath) { | ||
this.copy(path).del(path); | ||
this.copy(docPath).del(docPath); | ||
return this; | ||
}; | ||
}; |
var fs = require('fs'), | ||
sep = require('path').sep; | ||
path = require('path'); | ||
module.exports = function (path) { | ||
module.exports = function (docPath) { | ||
// Push single path into array object | ||
if (typeof path === 'string') { | ||
if (typeof docPath === 'string') { | ||
path = [path]; | ||
docPath = [docPath]; | ||
} | ||
path.forEach(function (path) { | ||
docPath.forEach(function (docPath) { | ||
var fullPath = this.clipboard.target + sep + path; | ||
var fullPath = path.resolve(this.clipboard.target, docPath); | ||
@@ -24,5 +24,5 @@ var del = function (fullPath) { | ||
paths.forEach(function (path) { | ||
paths.forEach(function (docPath) { | ||
var newPath = fullPath + sep + path; | ||
var newPath = path.resolve(fullPath, docPath); | ||
@@ -54,2 +54,2 @@ del(newPath); | ||
}; | ||
}; |
var fs = require('fs'), | ||
sep = require('path').sep, | ||
path = require('path'), | ||
log = require('col'); | ||
@@ -29,3 +29,3 @@ | ||
var newTarget = target + sep + item; | ||
var newTarget = path.resolve(target, item); | ||
@@ -59,2 +59,2 @@ if (check(newTarget)) { | ||
}; | ||
}; |
module.exports = function (callback) { | ||
callback && callback.call(this); | ||
callback && callback.call(this); | ||
return this; | ||
return this; | ||
}; |
{ | ||
"name": "rightclick", | ||
"description": "Cut, copy, paste and delete for node.js", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"keywords": [ | ||
@@ -28,7 +28,11 @@ "cut", | ||
"devDependencies": { | ||
"nodeunit": "0.8.6" | ||
"nodeunit": "0.8.6", | ||
"jshint": "2.4.4" | ||
}, | ||
"scripts": { | ||
"test": "nodeunit test" | ||
"hooks": "chmod +x hooks/*; cd .git/hooks && ln -sf ../../hooks/* .", | ||
"lint": "./node_modules/jshint/bin/jshint ./", | ||
"unit": "nodeunit test", | ||
"test": "npm run lint && npm run unit" | ||
} | ||
} |
@@ -11,12 +11,12 @@ // It may seem perverse but the prep file shouldn't use any of the rightClick | ||
// TODO: throw an error if files already exist? | ||
module.exports = function(location, files) { | ||
if(fs.existsSync(location)) { | ||
module.exports = function (location, files) { | ||
if (fs.existsSync(location)) { | ||
// Itterate the files array and write out each member | ||
_.each(files, function(content, name) { | ||
if(!fs.existsSync(name)) { | ||
_.each(files, function (content, name) { | ||
if (!fs.existsSync(name)) { | ||
// It's a folder | ||
if(!content) { | ||
if (!content) { | ||
@@ -23,0 +23,0 @@ fs.mkdirSync(name); |
var fs = require('fs'); | ||
module.exports = function(files) { | ||
files.forEach(function(file) { | ||
module.exports = function (files) { | ||
if(fs.existsSync(file)) { | ||
files.forEach(function (file) { | ||
if(fs.statSync(file).isDirectory()) { | ||
if (fs.existsSync(file)) { | ||
if (fs.statSync(file).isDirectory()) { | ||
fs.rmdirSync(file); | ||
@@ -12,0 +12,0 @@ |
@@ -6,7 +6,7 @@ // Helper modules | ||
setUp: function(callback) { | ||
setUp: function (callback) { | ||
// For this test scenario the righClick method needs to be stubbed so that | ||
// the clipboard can be accessed by the test assertions. | ||
this.rightClick = function() { | ||
this.rightClick = function () { | ||
@@ -32,3 +32,3 @@ this.clipboard = { | ||
tearDown: function(callback) { | ||
tearDown: function (callback) { | ||
@@ -39,3 +39,3 @@ callback(); | ||
'copy file': function(test) { | ||
'copy file': function (test) { | ||
@@ -56,3 +56,3 @@ test.expect(2); | ||
'copy file array': function(test) { | ||
'copy file array': function (test) { | ||
@@ -78,3 +78,3 @@ test.expect(4); | ||
'copy folder': function(test) { | ||
'copy folder': function (test) { | ||
@@ -81,0 +81,0 @@ test.expect(6); |
@@ -27,3 +27,3 @@ // Helper modules | ||
setUp: function(callback) { | ||
setUp: function (callback) { | ||
@@ -37,3 +37,3 @@ // Create some files to cut. | ||
tearDown: function(callback) { | ||
tearDown: function (callback) { | ||
@@ -47,3 +47,3 @@ // Files should be deleted but in case something went wrong... | ||
'cut file': function(test) { | ||
'cut file': function (test) { | ||
@@ -65,3 +65,3 @@ test.expect(2); | ||
'cut folder': function(test) { | ||
'cut folder': function (test) { | ||
@@ -68,0 +68,0 @@ test.expect(5); |
@@ -11,3 +11,3 @@ // Tested module | ||
setUp: function(callback) { | ||
setUp: function (callback) { | ||
@@ -30,3 +30,3 @@ // A set of files and folders to create with prep. | ||
tearDown: function(callback) { | ||
tearDown: function (callback) { | ||
@@ -37,3 +37,3 @@ callback(); | ||
'delete file': function(test) { | ||
'delete file': function (test) { | ||
@@ -52,3 +52,3 @@ test.expect(1); | ||
'delete folder': function(test) { | ||
'delete folder': function (test) { | ||
@@ -55,0 +55,0 @@ test.expect(4); |
@@ -17,7 +17,7 @@ // Helper modules | ||
setUp: function(callback) { | ||
setUp: function (callback) { | ||
// For this test scenario the righClick method needs to be stubbed so that | ||
// the clipboard can be preloaded and paste() tested in isolation. | ||
this.rightClick = function() { | ||
this.rightClick = function () { | ||
@@ -54,3 +54,3 @@ this.clipboard = { | ||
tearDown: function(callback) { | ||
tearDown: function (callback) { | ||
@@ -64,3 +64,3 @@ // Clean up pasted files | ||
paste: function(test) { | ||
paste: function (test) { | ||
test.expect(8); | ||
@@ -67,0 +67,0 @@ |
module.exports = { | ||
setUp: function(callback) { | ||
setUp: function (callback) { | ||
this.rightClick = function () { | ||
this.clipboard = { | ||
this.clipboard = { | ||
target: '', | ||
target: '', | ||
files: { | ||
'thing': false | ||
} | ||
}; | ||
files: { | ||
'thing': false | ||
} | ||
}; | ||
this.tap = require('../lib/tap'); | ||
this.tap = require('../lib/tap'); | ||
return this; | ||
} | ||
return this; | ||
}; | ||
@@ -26,3 +26,3 @@ callback(); | ||
tearDown: function(callback) { | ||
tearDown: function (callback) { | ||
@@ -34,10 +34,9 @@ callback(); | ||
tap: function (test) { | ||
var thing = false; | ||
this.rightClick().tap(function () { | ||
this.clipboard.thing = true; | ||
this.clipboard.thing = true; | ||
}); | ||
test.ok(this.clipboard.thing, | ||
'thing set to true'); | ||
'thing set to true'); | ||
@@ -44,0 +43,0 @@ test.done(); |
@@ -6,3 +6,3 @@ // Tested module | ||
setUp: function(callback) { | ||
setUp: function (callback) { | ||
@@ -13,3 +13,3 @@ callback(); | ||
tearDown: function(callback) { | ||
tearDown: function (callback) { | ||
@@ -20,3 +20,3 @@ callback(); | ||
rightClick: function(test) { | ||
rightClick: function (test) { | ||
@@ -45,3 +45,3 @@ test.expect(7); | ||
test.ok(function() {rightClick('./test/notFolder');}, | ||
test.ok(function () {rightClick('./test/notFolder'); }, | ||
'Returns false when passed a non existant path'); | ||
@@ -48,0 +48,0 @@ |
21861
22
452
2