Comparing version 0.2.1 to 0.2.2
@@ -17,3 +17,3 @@ var path = require('path'); | ||
var dirs = _path.split("/"); | ||
var dirs = _path.split(path.sep); | ||
var walker = [dirs.shift()]; | ||
@@ -31,3 +31,3 @@ | ||
acc.push(d); | ||
var dir = acc.join("/"); | ||
var dir = acc.join(path.sep); | ||
@@ -78,7 +78,7 @@ // look for dir on the fs, if it doesn't exist then create it, and | ||
exports.mkdirsSync = function (_path, mode) { | ||
if (_path[0] !== "/") { | ||
if (_path[0] !== path.sep) { | ||
_path = path.join(process.cwd(), _path) | ||
} | ||
var dirs = _path.split("/"); | ||
var dirs = _path.split(path.sep); | ||
var walker = [dirs.shift()]; | ||
@@ -88,3 +88,3 @@ | ||
acc.push(d); | ||
var dir = acc.join("/"); | ||
var dir = acc.join(path.sep); | ||
@@ -192,3 +192,3 @@ try { | ||
case "~": from = process.env.HOME; to = to.substr(1); break | ||
case "/": from = ""; break | ||
case path.sep: from = ""; break | ||
default : from = process.cwd(); break | ||
@@ -200,4 +200,4 @@ } | ||
exports.path.relativePath = function (base, compare) { | ||
base = base.split("/"); | ||
compare = compare.split("/"); | ||
base = base.split(path.sep); | ||
compare = compare.split(path.sep); | ||
@@ -216,3 +216,3 @@ if (base[0] == "") { | ||
if (!base[i] || (base[i] != compare[i])) { | ||
return compare.slice(i).join("/"); | ||
return compare.slice(i).join(path.sep); | ||
} | ||
@@ -219,0 +219,0 @@ } |
{ "name" : "file" | ||
, "description" : "Higher level path and file manipulation functions." | ||
, "tags" : ["file", "path", "fs", "walk"] | ||
, "version" : "0.2.1" | ||
, "version" : "0.2.2" | ||
, "author" : "Anders Conbere <aconbere@gmail.com>" | ||
@@ -15,2 +15,4 @@ , "directories" : | ||
, "main" : "./lib/file" | ||
, "license": "MIT" | ||
, "devDependencies": { "mocha": "1.9.x" } | ||
} |
@@ -22,3 +22,3 @@ # File - Common higher level file and path operations | ||
Like file.walk but synchronous. | ||
Synchronus version of file.walk, calling callback for each directory, passing in (dirPath, dirs, files). | ||
@@ -41,3 +41,3 @@ | ||
### file.path.relpath(root, fullPath) | ||
### file.path.relativePath(root, fullPath) | ||
@@ -44,0 +44,0 @@ Given a root path, and a fullPath attempts to diff between the two to give us an acurate path relative to root. |
var assert = require("assert"); | ||
var util = require("util"); | ||
var minitest = require("../vendor/minitest.js/minitest"); | ||
var file = require("../lib/main"); | ||
var mocha = require("mocha"); | ||
var file = require("../lib/file"); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
minitest.setupListeners(); | ||
var madeDirs = []; | ||
@@ -20,11 +18,13 @@ fs.mkdir = function (dir, mode, callback) { | ||
GLOBAL.fs = fs; | ||
global.fs = fs; | ||
minitest.context("file#mkdirs", function () { | ||
this.setup(function () { | ||
describe("file#mkdirs", function () { | ||
beforeEach(function (done) { | ||
madeDirs = []; | ||
done(); | ||
}); | ||
this.assertion("it should make all the directories in the tree", function (test) { | ||
it("should make all the directories in the tree", function (done) { | ||
file.mkdirs("/test/test/test/test", 0755, function(err) { | ||
if (err) throw new Error(err); | ||
assert.equal(madeDirs[0], "/test"); | ||
@@ -34,3 +34,3 @@ assert.equal(madeDirs[1], "/test/test"); | ||
assert.equal(madeDirs[3], "/test/test/test/test"); | ||
test.finished(); | ||
done(); | ||
}); | ||
@@ -40,9 +40,12 @@ }); | ||
minitest.context("file#mkdirsSync", function () { | ||
this.setup(function () { | ||
describe("file#mkdirsSync", function () { | ||
beforeEach(function (done) { | ||
madeDirs = []; | ||
done(); | ||
}); | ||
this.assertion("it should make all the directories in the tree", function (test) { | ||
file.mkdirsSync("/test/test/test/test", 0755, function(err) {}); | ||
it("should make all the directories in the tree", function (done) { | ||
file.mkdirsSync("/test/test/test/test", 0755, function(err) { | ||
if (err) throw new Error(err); | ||
}); | ||
assert.equal(madeDirs[0], "/test"); | ||
@@ -52,44 +55,43 @@ assert.equal(madeDirs[1], "/test/test"); | ||
assert.equal(madeDirs[3], "/test/test/test/test"); | ||
test.finished(); | ||
done(); | ||
}); | ||
}); | ||
minitest.context("file#walk", function () { | ||
this.assertion("it should call \"callback\" for ever file in the tree", function (test) { | ||
file.walk("/test", function(start, dirs, names) {}); | ||
test.finished(); | ||
// TODO: File walk tests are obviously not really working | ||
describe("file#walk", function () { | ||
it("should call \"callback\" for ever file in the tree", function (done) { | ||
file.walk("./tests", function(start, dirs, names) {}); | ||
done(); | ||
}); | ||
}); | ||
minitest.context("file#walkSync", function () { | ||
this.assertion("it should call \"callback\" for ever file in the tree", function (test) { | ||
file.walkSync("/test", function(start, dirs, names) {}); | ||
test.finished(); | ||
describe("file#walkSync", function () { | ||
it("should call \"callback\" for ever file in the tree", function (done) { | ||
file.walkSync("./tests", function(start, dirs, names) {}); | ||
done(); | ||
}); | ||
}); | ||
minitest.context("file.path#abspath", function () { | ||
this.setup(function () {}); | ||
this.assertion("it should convert . to the current directory", function (test) { | ||
describe("file.path#abspath", function () { | ||
it("should convert . to the current directory", function (done) { | ||
assert.equal(file.path.abspath("."), process.cwd()); | ||
assert.equal(file.path.abspath("./test/dir"), file.path.join(process.cwd(), "test/dir")); | ||
test.finished(); | ||
done(); | ||
}); | ||
this.assertion("it should convert .. to the parrent directory", function (test) { | ||
it("should convert .. to the parrent directory", function (done) { | ||
assert.equal(file.path.abspath(".."), path.dirname(process.cwd())); | ||
assert.equal(file.path.abspath("../test/dir"), file.path.join(path.dirname(process.cwd()), "test/dir")); | ||
test.finished(); | ||
done(); | ||
}); | ||
this.assertion("it should convert ~ to the home directory", function (test) { | ||
it("should convert ~ to the home directory", function (done) { | ||
assert.equal(file.path.abspath("~"), file.path.join(process.env.HOME, "")); | ||
assert.equal(file.path.abspath("~/test/dir"), file.path.join(process.env.HOME, "test/dir")); | ||
test.finished(); | ||
done(); | ||
}); | ||
this.assertion("it should not convert paths begining with /", function (test) { | ||
it("should not convert paths begining with /", function (done) { | ||
assert.equal(file.path.abspath("/x/y/z"), "/x/y/z"); | ||
test.finished(); | ||
done(); | ||
}); | ||
@@ -99,6 +101,4 @@ }); | ||
minitest.context("file.path#relativePath", function () { | ||
this.setup(function () {}); | ||
this.assertion("it should return the relative path", function (test) { | ||
describe("file.path#relativePath", function () { | ||
it("should return the relative path", function (done) { | ||
var rel = file.path.relativePath("/", "/test.js"); | ||
@@ -110,10 +110,10 @@ assert.equal(rel, "test.js"); | ||
test.finished(); | ||
done(); | ||
}); | ||
this.assertion("it should take two equal paths and return \"\"", function (test) { | ||
it("should take two equal paths and return \"\"", function (done) { | ||
var rel = file.path.relativePath("/test.js", "/test.js"); | ||
assert.equal(rel, ""); | ||
test.finished(); | ||
done(); | ||
}); | ||
}); |
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
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
11826
6
0
287
1