Comparing version 2.1.0 to 3.0.0
var util = require('./util') | ||
var node_path = require('path') | ||
var path = require('path') | ||
var xml2js = require('xml2js') | ||
@@ -14,4 +14,7 @@ var parseXmlString = xml2js.parseString | ||
// extras | ||
exports.remove = require('rimraf') | ||
exports.mkdirp = require('mkdirp') | ||
exports.prependFile = require('prepend-file') | ||
@@ -24,3 +27,3 @@ | ||
exports.readFile = function (path, options, cb) { | ||
exports.readFile = function (pth, options, cb) { | ||
if (!cb) { | ||
@@ -31,5 +34,5 @@ cb = options | ||
options = util.defaults(options) | ||
;(options.url !== false && util.url(path)) | ||
? util.readHttp(path, options, cb) | ||
: readFile(path, options, cb) | ||
;(options.url !== false && util.url(pth)) | ||
? util.readHttp(pth, options, cb) | ||
: readFile(pth, options, cb) | ||
} | ||
@@ -40,3 +43,3 @@ | ||
exports.writeFile = function (path, data, options, cb) { | ||
exports.writeFile = function (pth, data, options, cb) { | ||
if (!cb) { | ||
@@ -48,3 +51,3 @@ cb = options | ||
if (options.mkdirp) { | ||
var dirPath = path.slice(0, path.lastIndexOf('/')) | ||
var dirPath = pth.slice(0, pth.lastIndexOf('/')) | ||
exports.mkdirp(dirPath, function (err) { | ||
@@ -63,5 +66,5 @@ if (err) { | ||
if (options.url !== false && util.url(data)) { | ||
exports.writeHttp(path, data, options, cb) | ||
exports.writeHttp(pth, data, options, cb) | ||
} else { | ||
writeFile(path, data, options, cb) | ||
writeFile(pth, data, options, cb) | ||
} | ||
@@ -71,3 +74,3 @@ } | ||
exports.writeHttp = function (path, url, options, cb) { | ||
exports.writeHttp = function (pth, url, options, cb) { | ||
util.getRetry(url, options, function (err, throughStream) { | ||
@@ -78,3 +81,3 @@ var file | ||
} else { | ||
file = exports.createWriteStream(path) | ||
file = exports.createWriteStream(pth) | ||
throughStream.pipe(file) | ||
@@ -92,19 +95,27 @@ file.on('error', function (err) { | ||
cb = options // TODO js.nodeify | ||
options = {} | ||
} | ||
exports.mkdirp(dest.substring(0, dest.lastIndexOf('/')), function (err) { | ||
if (err) { | ||
cb(err) | ||
} else { | ||
exports.readFile(src, function (err, data) { | ||
if (err) { | ||
cb(err) | ||
} else { | ||
exports.writeFile(dest, data, cb) | ||
} | ||
}) | ||
} | ||
}) | ||
if (options.mkdirp) { | ||
var dirPath = dest.slice(0, dest.lastIndexOf('/')) | ||
exports.mkdirp(dirPath, function (err) { | ||
if (err) { | ||
cb(err) | ||
} else { | ||
finish() | ||
} | ||
}) | ||
} else { | ||
finish() | ||
} | ||
function finish () { | ||
var rs = exports.createReadStream(src) | ||
var ws = exports.createWriteStream(dest) | ||
rs.pipe(ws) | ||
rs.on('error', cb) | ||
ws.on('error', cb) | ||
ws.on('finish', cb) | ||
} | ||
} | ||
exports.readJSON = function (path, options, cb) { | ||
exports.readJSON = function (pth, options, cb) { | ||
if (!cb) { | ||
@@ -115,3 +126,3 @@ cb = options | ||
options = util.defaults(options) | ||
exports.readFile(path, options, function (err, data) { | ||
exports.readFile(pth, options, function (err, data) { | ||
if (err) { | ||
@@ -131,3 +142,3 @@ cb(err) | ||
exports.writeJSON = function (path, obj, options, cb) { | ||
exports.writeJSON = function (pth, obj, options, cb) { | ||
var str | ||
@@ -148,6 +159,6 @@ if (!cb) { | ||
} | ||
exports.writeFile(path, str, options, cb) | ||
exports.writeFile(pth, str, options, cb) | ||
} | ||
exports.editJSON = function (path, fn, options, cb) { | ||
exports.editJSON = function (pth, fn, options, cb) { | ||
if (!cb) { | ||
@@ -158,3 +169,3 @@ cb = options | ||
options = util.defaults(options) | ||
if (options.url !== false && util.url(path)) { | ||
if (options.url !== false && util.url(pth)) { | ||
var error = new TypeError("editJSON doesn't support urls") | ||
@@ -164,3 +175,3 @@ error.code = 'TypeError' | ||
} | ||
exports.readJSON(path, options, function (err, obj) { | ||
exports.readJSON(pth, options, function (err, obj) { | ||
var newObj | ||
@@ -173,6 +184,6 @@ if (err) { | ||
newObj.then(function (val) { | ||
exports.writeJSON(path, val, options, cb) | ||
exports.writeJSON(pth, val, options, cb) | ||
}) | ||
} else { | ||
exports.writeJSON(path, newObj, options, cb) | ||
exports.writeJSON(pth, newObj, options, cb) | ||
} | ||
@@ -183,3 +194,3 @@ } | ||
exports.readXML = function (path, options, cb) { | ||
exports.readXML = function (pth, options, cb) { | ||
if (!cb) { | ||
@@ -190,3 +201,3 @@ cb = options | ||
options = util.defaults(options) | ||
exports.readFile(path, options, function (err, data) { | ||
exports.readFile(pth, options, function (err, data) { | ||
if (err) { | ||
@@ -200,3 +211,3 @@ cb(err) | ||
exports.writeXML = function (path, obj, options, cb) { | ||
exports.writeXML = function (pth, obj, options, cb) { | ||
var str | ||
@@ -217,6 +228,6 @@ if (!cb) { | ||
} | ||
exports.writeFile(path, str, options, cb) | ||
exports.writeFile(pth, str, options, cb) | ||
} | ||
exports.editXML = function (path, fn, options, cb) { | ||
exports.editXML = function (pth, fn, options, cb) { | ||
if (!cb) { | ||
@@ -227,3 +238,3 @@ cb = options | ||
options = util.defaults(options) | ||
if (options.url !== false && util.url(path)) { | ||
if (options.url !== false && util.url(pth)) { | ||
var error = new TypeError("editXML doesn't support urls") | ||
@@ -233,3 +244,3 @@ error.code = 'TypeError' | ||
} | ||
exports.readXML(path, options, function (err, obj) { | ||
exports.readXML(pth, options, function (err, obj) { | ||
var newObj | ||
@@ -242,6 +253,6 @@ if (err) { | ||
newObj.then(function (val) { | ||
exports.writeXML(path, val, options, cb) | ||
exports.writeXML(pth, val, options, cb) | ||
}) | ||
} else { | ||
exports.writeXML(path, newObj, options, cb) | ||
exports.writeXML(pth, newObj, options, cb) | ||
} | ||
@@ -259,3 +270,3 @@ } | ||
exclude: [] *optional | ||
method:function(path, field, isDir, obj) // if return true current dir | ||
method:function(pth, field, isDir, obj) // if return true current dir | ||
} | ||
@@ -281,3 +292,3 @@ */ | ||
exports.walk = function (path, options, cb, obj, current, field, errs) { | ||
exports.walk = function (pth, options, cb, obj, current, field, errs) { | ||
var method | ||
@@ -292,5 +303,5 @@ if (!cb) { | ||
rdy: 1, | ||
top: path | ||
top: pth | ||
} | ||
field = path | ||
field = pth | ||
current = obj.val | ||
@@ -314,3 +325,3 @@ } | ||
exports.exists(path, function (exists) { | ||
exports.exists(pth, function (exists) { | ||
if (!exists) { | ||
@@ -320,6 +331,6 @@ if (!errs) { | ||
} | ||
errs.push('file does not exist ' + path) | ||
errs.push('file does not exist ' + pth) | ||
if (--obj.rdy === 0) cb(errs, obj.top ? obj.val[obj.top] : obj.val) | ||
} else { | ||
exports.stat(path, function (err, stats) { | ||
exports.stat(pth, function (err, stats) { | ||
if (err) { | ||
@@ -335,3 +346,3 @@ if (!errs) { | ||
if (stats.isDirectory()) { | ||
exports.readdir(path, function (err, files) { | ||
exports.readdir(pth, function (err, files) { | ||
if (err) { | ||
@@ -344,3 +355,3 @@ if (!errs) errs = [] | ||
} else { | ||
if (method && method(path, field, files, obj, current)) { | ||
if (method && method(pth, field, files, obj, current)) { | ||
if (--obj.rdy === 0) { | ||
@@ -354,3 +365,3 @@ cb(errs, obj.top ? obj.val[obj.top] : obj.val) | ||
obj.rdy++ | ||
exports.walk((path + '/' + val), options, cb, obj, current[field], val, errs) | ||
exports.walk((pth + '/' + val), options, cb, obj, current[field], val, errs) | ||
}) | ||
@@ -364,3 +375,3 @@ } | ||
current[field] = true | ||
;(method && method(path, field, false, obj, current)) | ||
;(method && method(pth, field, false, obj, current)) | ||
if (--obj.rdy === 0) { | ||
@@ -389,3 +400,3 @@ cb(errs, obj.top ? obj.val[obj.top] : obj.val) | ||
nbPending += 1 | ||
expand(obj, key, node_path.join(rootPath, acc.join('/')), expandDone) | ||
expand(obj, key, path.join(rootPath, acc.join('/')), expandDone) | ||
} | ||
@@ -435,3 +446,3 @@ acc.pop() | ||
exports.exists = function (path, _cb) { | ||
exports.exists = function (pth, _cb) { | ||
var cb = _cb | ||
@@ -443,3 +454,3 @@ if (_cb.length === 2) { | ||
} | ||
return exists(path, cb) | ||
return exists(pth, cb) | ||
} |
{ | ||
"name": "vigour-fs", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "node's `fs` module with sugar on top + native support.", | ||
@@ -41,2 +41,3 @@ "main": "index.js", | ||
"concat-stream": "^1.4.6", | ||
"cpr": "^0.4.2", | ||
"eventemitter3": "^0.1.2", | ||
@@ -43,0 +44,0 @@ "graceful-fs": "~3.0.2", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7779729
61
2904
3
9
+ Addedcpr@^0.4.2
+ Addedcpr@0.4.3(transitive)
+ Addedglob@6.0.4(transitive)
+ Addedgraceful-fs@4.1.15(transitive)
+ Addedrimraf@2.4.5(transitive)