first commit

This commit is contained in:
armansansd
2023-07-12 16:31:19 +01:00
commit 3424b1927b
23306 changed files with 2217776 additions and 0 deletions
Generated Vendored Executable
+3
View File
@@ -0,0 +1,3 @@
*.swp
node_modules
npm-debug.log
Generated Vendored Executable
+9
View File
@@ -0,0 +1,9 @@
(The MIT License)
Copyright (c) 2012 Anders Conbere
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Generated Vendored Executable
+47
View File
@@ -0,0 +1,47 @@
# File - Common higher level file and path operations
## Install
<pre>
npm install file
</pre>
<pre>
var file = require("file");
</pre>
## API
### file.walk(start, callback)
Navigates a file tree, calling callback for each directory, passing in (null, dirPath, dirs, files).
### file.walkSync(start, callback)
Synchronus version of file.walk, calling callback for each directory, passing in (dirPath, dirs, files).
### file.mkdirs(path, mode, callback)
Makes all the directories in a path. (analgous to mkdir -P) For example given a path like "test/this/path" in an empty directory, mkdirs would make the directories "test", "this" and "path".
### file.mkdirsSync(path, mode)
Like file.mkdirs but synchronous.
### file.path.abspath(path)
Expands ".", "..", "~" and non root paths to their full absolute path. Relative paths default to being children of the current working directory.
### file.path.relativePath(root, fullPath)
Given a root path, and a fullPath attempts to diff between the two to give us an acurate path relative to root.
### file.path.join(head, tail)
Just like path.join but haves a little more sanely when give a head equal to "". file.path.join("", "tail") returns "tail", path.join("", "tail") returns "/tail"
Generated Vendored Executable
+224
View File
@@ -0,0 +1,224 @@
var path = require('path');
var fs = require('fs');
var assert = require("assert");
// file.mkdirs
//
// Given a path to a directory, create it, and all the intermediate directories
// as well
//
// @path: the path to create
// @mode: the file mode to create the directory with:
// ex: file.mkdirs("/tmp/dir", 755, function () {})
// @callback: called when finished.
exports.mkdirs = function (_path, mode, callback) {
_path = exports.path.abspath(_path);
var dirs = _path.split(path.sep);
var walker = [dirs.shift()];
// walk
// @ds: A list of directory names
// @acc: An accumulator of walked dirs
// @m: The mode
// @cb: The callback
var walk = function (ds, acc, m, cb) {
if (ds.length > 0) {
var d = ds.shift();
acc.push(d);
var dir = acc.join(path.sep);
// look for dir on the fs, if it doesn't exist then create it, and
// continue our walk, otherwise if it's a file, we have a name
// collision, so exit.
fs.stat(dir, function (err, stat) {
// if the directory doesn't exist then create it
if (err) {
// 2 means it's wasn't there
if (err.errno == 2 || err.errno == 34) {
fs.mkdir(dir, m, function (erro) {
if (erro && erro.errno != 17 && erro.errno != 34) {
return cb(erro);
} else {
return walk(ds, acc, m, cb);
}
});
} else {
return cb(err);
}
} else {
if (stat.isDirectory()) {
return walk(ds, acc, m, cb);
} else {
return cb(new Error("Failed to mkdir " + dir + ": File exists\n"));
}
}
});
} else {
return cb();
}
};
return walk(dirs, walker, mode, callback);
};
// file.mkdirsSync
//
// Synchronus version of file.mkdirs
//
// Given a path to a directory, create it, and all the intermediate directories
// as well
//
// @path: the path to create
// @mode: the file mode to create the directory with:
// ex: file.mkdirs("/tmp/dir", 755, function () {})
exports.mkdirsSync = function (_path, mode) {
if (_path[0] !== path.sep) {
_path = path.join(process.cwd(), _path)
}
var dirs = _path.split(path.sep);
var walker = [dirs.shift()];
dirs.reduce(function (acc, d) {
acc.push(d);
var dir = acc.join(path.sep);
try {
var stat = fs.statSync(dir);
if (!stat.isDirectory()) {
throw "Failed to mkdir " + dir + ": File exists";
}
} catch (err) {
fs.mkdirSync(dir, mode);
}
return acc;
}, walker);
};
// file.walk
//
// Given a path to a directory, walk the fs below that directory
//
// @start: the path to startat
// @callback: called for each new directory we enter
// ex: file.walk("/tmp", function(error, path, dirs, name) {})
//
// path is the current directory we're in
// dirs is the list of directories below it
// names is the list of files in it
//
exports.walk = function (start, callback) {
fs.lstat(start, function (err, stat) {
if (err) { return callback(err) }
if (stat.isDirectory()) {
fs.readdir(start, function (err, files) {
var coll = files.reduce(function (acc, i) {
var abspath = path.join(start, i);
if (fs.statSync(abspath).isDirectory()) {
exports.walk(abspath, callback);
acc.dirs.push(abspath);
} else {
acc.names.push(abspath);
}
return acc;
}, {"names": [], "dirs": []});
return callback(null, start, coll.dirs, coll.names);
});
} else {
return callback(new Error("path: " + start + " is not a directory"));
}
});
};
// file.walkSync
//
// Synchronus version of file.walk
//
// Given a path to a directory, walk the fs below that directory
//
// @start: the path to startat
// @callback: called for each new directory we enter
// ex: file.walk("/tmp", function(error, path, dirs, name) {})
//
// path is the current directory we're in
// dirs is the list of directories below it
// names is the list of files in it
//
exports.walkSync = function (start, callback) {
var stat = fs.statSync(start);
if (stat.isDirectory()) {
var filenames = fs.readdirSync(start);
var coll = filenames.reduce(function (acc, name) {
var abspath = path.join(start, name);
if (fs.statSync(abspath).isDirectory()) {
acc.dirs.push(name);
} else {
acc.names.push(name);
}
return acc;
}, {"names": [], "dirs": []});
callback(start, coll.dirs, coll.names);
coll.dirs.forEach(function (d) {
var abspath = path.join(start, d);
exports.walkSync(abspath, callback);
});
} else {
throw new Error("path: " + start + " is not a directory");
}
};
exports.path = {};
exports.path.abspath = function (to) {
var from;
switch (to.charAt(0)) {
case "~": from = process.env.HOME; to = to.substr(1); break
case path.sep: from = ""; break
default : from = process.cwd(); break
}
return path.join(from, to);
}
exports.path.relativePath = function (base, compare) {
base = base.split(path.sep);
compare = compare.split(path.sep);
if (base[0] == "") {
base.shift();
}
if (compare[0] == "") {
compare.shift();
}
var l = compare.length;
for (var i = 0; i < l; i++) {
if (!base[i] || (base[i] != compare[i])) {
return compare.slice(i).join(path.sep);
}
}
return ""
};
exports.path.join = function (head, tail) {
if (head == "") {
return tail;
} else {
return path.join(head, tail);
}
};
Generated Vendored Executable
+56
View File
@@ -0,0 +1,56 @@
{
"_from": "file@^0.2.2",
"_id": "file@0.2.2",
"_inBundle": false,
"_integrity": "sha1-w9/Y+M81Na5FXCtCPC5SY112tNM=",
"_location": "/file",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "file@^0.2.2",
"name": "file",
"escapedName": "file",
"rawSpec": "^0.2.2",
"saveSpec": null,
"fetchSpec": "^0.2.2"
},
"_requiredBy": [
"/modernizr"
],
"_resolved": "https://registry.npmjs.org/file/-/file-0.2.2.tgz",
"_shasum": "c3dfd8f8cf3535ae455c2b423c2e52635d76b4d3",
"_spec": "file@^0.2.2",
"_where": "/srv/http/mmap_sarrebourg/user/themes/basic/node_modules/modernizr",
"author": {
"name": "Anders Conbere",
"email": "aconbere@gmail.com"
},
"bugs": {
"url": "http://github.com/aconbere/node-file-utils"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Higher level path and file manipulation functions.",
"devDependencies": {
"mocha": "1.9.x"
},
"directories": {
"lib": "lib"
},
"homepage": "https://github.com/aconbere/node-file-utils#readme",
"license": "MIT",
"main": "./lib/file",
"name": "file",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/aconbere/node-file-utils.git"
},
"tags": [
"file",
"path",
"fs",
"walk"
],
"version": "0.2.2"
}
+113
View File
@@ -0,0 +1,113 @@
var assert = require("assert");
var util = require("util");
var mocha = require("mocha");
var file = require("../lib/file");
var fs = require("fs");
var path = require("path");
var madeDirs = [];
fs.mkdir = function (dir, mode, callback) {
madeDirs.push(dir);
callback();
};
fs.mkdirSync = function (dir, mode) {
madeDirs.push(dir);
};
global.fs = fs;
describe("file#mkdirs", function () {
beforeEach(function (done) {
madeDirs = [];
done();
});
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");
assert.equal(madeDirs[1], "/test/test");
assert.equal(madeDirs[2], "/test/test/test");
assert.equal(madeDirs[3], "/test/test/test/test");
done();
});
});
});
describe("file#mkdirsSync", function () {
beforeEach(function (done) {
madeDirs = [];
done();
});
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");
assert.equal(madeDirs[1], "/test/test");
assert.equal(madeDirs[2], "/test/test/test");
assert.equal(madeDirs[3], "/test/test/test/test");
done();
});
});
// 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();
});
});
describe("file#walkSync", function () {
it("should call \"callback\" for ever file in the tree", function (done) {
file.walkSync("./tests", function(start, dirs, names) {});
done();
});
});
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"));
done();
});
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"));
done();
});
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"));
done();
});
it("should not convert paths begining with /", function (done) {
assert.equal(file.path.abspath("/x/y/z"), "/x/y/z");
done();
});
});
describe("file.path#relativePath", function () {
it("should return the relative path", function (done) {
var rel = file.path.relativePath("/", "/test.js");
assert.equal(rel, "test.js");
var rel = file.path.relativePath("/test/loc", "/test/loc/test.js");
assert.equal(rel, "test.js");
done();
});
it("should take two equal paths and return \"\"", function (done) {
var rel = file.path.relativePath("/test.js", "/test.js");
assert.equal(rel, "");
done();
});
});