Comparing version 0.1.0 to 1.0.0
@@ -0,1 +1,7 @@ | ||
1.0.0 / 2017-02-20 | ||
================== | ||
* code improvement | ||
* dependencies upgrade | ||
* major version | ||
0.1.0 / 2016-04-06 | ||
@@ -2,0 +8,0 @@ ================== |
@@ -0,0 +0,0 @@ /** |
@@ -16,3 +16,2 @@ /** | ||
const nodePath = require("path"); | ||
const enFs = require("enfspatch"); | ||
@@ -56,3 +55,3 @@ const enfsmkdirp = require("enfsmkdirp"); | ||
if (options.mode) { | ||
options.fs.stat(path, (errStat, stat)=> { | ||
options.fs.stat(path, (errStat, stat) => { | ||
if (errStat) { | ||
@@ -62,3 +61,3 @@ return callback(errStat); | ||
if ((stat.mode & parseInt("0777", 8)) !== options.mode) { | ||
options.fs.chmod(path, options.mode, (errChmod)=> { | ||
options.fs.chmod(path, options.mode, (errChmod) => { | ||
return callback(errChmod || null, errChmod ? null : path); | ||
@@ -65,0 +64,0 @@ }); |
@@ -24,2 +24,43 @@ /** | ||
function ensureWriteStream(path, options, callback) { | ||
try { | ||
return callback(null, options.fs.createWriteStream(path, options.streamOptions)); | ||
} catch (err) { | ||
callback(err); | ||
} | ||
} | ||
function ensureWriteFile(file, options, callback) { | ||
options.fs.open(file, options.append ? "a+" : "wx", options.mode, (errOpen, fd) => { | ||
if (errOpen) { | ||
return callback(errOpen); | ||
} | ||
if ("data" in options) { | ||
options.fs.write(fd, options.data, options.encoding, (errWrite) => { | ||
if (errWrite) { | ||
return callback(errWrite); | ||
} | ||
options.fs.close(fd, callback); | ||
}); | ||
} else { | ||
options.fs.close(fd, callback); | ||
} | ||
}); | ||
} | ||
function createFile(file, options, callback) { | ||
ensureDir(nodePath.dirname(file), {fs: options.fs, mode: options.dirMode}, (err) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (options.stream) { | ||
ensureWriteStream(file, options, callback); | ||
} else { | ||
ensureWriteFile(file, options, callback); | ||
} | ||
}); | ||
} | ||
/** | ||
@@ -41,3 +82,2 @@ * ensure - ensures file existence on file system | ||
function ensure(path, opt, callback) { | ||
let options; | ||
@@ -52,3 +92,3 @@ if (ensureUtil.isFunction(opt)) { | ||
callback = callback || noop; | ||
options = opt || {}; | ||
let options = opt || {}; | ||
@@ -60,3 +100,3 @@ options.fs = options.fs || enFs; | ||
options.fs.stat(path, (err, stat)=> { | ||
options.fs.stat(path, (err, stat) => { | ||
if (err) { | ||
@@ -94,44 +134,2 @@ createFile(path, options, callback); | ||
function createFile(file, options, callback) { | ||
ensureDir(nodePath.dirname(file), {fs: options.fs, mode: options.dirMode}, (err)=> { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (options.stream) { | ||
ensureWriteStream(file, options, callback); | ||
} else { | ||
ensureWriteFile(file, options, callback); | ||
} | ||
}); | ||
} | ||
function ensureWriteStream(path, options, callback) { | ||
var stream; | ||
try { | ||
stream = options.fs.createWriteStream(path, options.streamOptions); | ||
return callback(null, stream); | ||
} catch (err) { | ||
callback(err); | ||
} | ||
} | ||
function ensureWriteFile(file, options, callback) { | ||
options.fs.open(file, options.append ? "a+" : "wx", options.mode, (errOpen, fd) => { | ||
if (errOpen) { | ||
return callback(errOpen); | ||
} | ||
if (options.hasOwnProperty("data")) { | ||
options.fs.write(fd, options.data, options.encoding, (errWrite) => { | ||
if (errWrite) { | ||
return callback(errWrite); | ||
} | ||
options.fs.close(fd, callback); | ||
}); | ||
} else { | ||
options.fs.close(fd, callback); | ||
} | ||
}); | ||
} | ||
module.exports = ensure; |
@@ -23,2 +23,14 @@ /** | ||
function createLink(srcPath, dstPath, options, callback) { | ||
ensureDir(nodePath.dirname(dstPath), (err) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
options.fs.link(srcPath, dstPath, (errLink) => { | ||
callback(errLink, errLink ? null : dstPath); | ||
}); | ||
}); | ||
} | ||
/** | ||
@@ -38,3 +50,3 @@ * ensure - ensures link existence on file system | ||
callback = opt; | ||
opt= {}; | ||
opt = {}; | ||
} | ||
@@ -45,3 +57,3 @@ callback = callback || noop; | ||
options.fs.lstat(dstPath, (errDstStat)=> { | ||
options.fs.lstat(dstPath, (errDstStat) => { | ||
if (errDstStat) { | ||
@@ -61,14 +73,3 @@ options.fs.lstat(srcPath, (errSrcStat) => { | ||
function createLink(srcPath, dstPath, options, callback) { | ||
ensureDir(nodePath.dirname(dstPath), (err) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
options.fs.link(srcPath, dstPath, (errLink) => { | ||
callback(errLink, errLink ? null : dstPath); | ||
}); | ||
}); | ||
} | ||
module.exports = ensure; |
@@ -64,3 +64,3 @@ /** | ||
} | ||
ensureDir(nodePath.dirname(dstPath), (errDir)=> { | ||
ensureDir(nodePath.dirname(dstPath), (errDir) => { | ||
if (errDir) { | ||
@@ -67,0 +67,0 @@ return callback(errDir); |
@@ -42,3 +42,2 @@ /** | ||
function symlinkPaths(srcPath, dstPath, callback) { | ||
var dstDir, relativeToDst; | ||
if (nodePath.isAbsolute(srcPath)) { | ||
@@ -53,4 +52,4 @@ return enFs.lstat(srcPath, (errSrcStat) => { | ||
} else { | ||
dstDir = nodePath.dirname(dstPath); | ||
relativeToDst = nodePath.join(dstDir, srcPath); | ||
const dstDir = nodePath.dirname(dstPath); | ||
const relativeToDst = nodePath.join(dstDir, srcPath); | ||
return enFs.lstat(relativeToDst, (errRelative) => { | ||
@@ -57,0 +56,0 @@ if (errRelative) { |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -15,3 +15,2 @@ /** | ||
const nodePath = require("path"); | ||
const enFs = require("enfspatch"); | ||
@@ -18,0 +17,0 @@ const enfsmkdirp = require("enfsmkdirp"); |
@@ -21,2 +21,25 @@ /** | ||
function ensureWriteStream(path, options) { | ||
return options.fs.createWriteStream(path, options.streamOptions); | ||
} | ||
function ensureWriteFile(file, options) { | ||
const fd = options.fs.openSync(file, options.append ? "a+" : "wx", options.mode); | ||
if (options.hasOwnProperty("data")) { | ||
options.fs.writeSync(fd, options.data, options.encoding); | ||
} | ||
options.fs.closeSync(fd); | ||
} | ||
function createFileSync(file, options) { | ||
ensureDirSync(nodePath.dirname(file), {fs: options.fs, mode: options.dirMode}); | ||
if (options.stream) { | ||
return ensureWriteStream(file, options); | ||
} else { | ||
ensureWriteFile(file, options); | ||
} | ||
} | ||
/** | ||
@@ -70,24 +93,2 @@ * ensure - ensures file existence on file system | ||
function createFileSync(file, options) { | ||
ensureDirSync(nodePath.dirname(file), {fs: options.fs, mode: options.dirMode}); | ||
if (options.stream) { | ||
return ensureWriteStream(file, options); | ||
} else { | ||
ensureWriteFile(file, options); | ||
} | ||
} | ||
function ensureWriteStream(path, options) { | ||
return options.fs.createWriteStream(path, options.streamOptions); | ||
} | ||
function ensureWriteFile(file, options) { | ||
const fd = options.fs.openSync(file, options.append ? "a+" : "wx", options.mode); | ||
if (options.hasOwnProperty("data")) { | ||
options.fs.writeSync(fd, options.data, options.encoding); | ||
} | ||
options.fs.closeSync(fd); | ||
} | ||
module.exports = ensure; |
@@ -16,3 +16,2 @@ /** | ||
const nodePath = require("path"); | ||
const ensureUtil = require("../util"); | ||
const enFs = require("enfspatch"); | ||
@@ -19,0 +18,0 @@ const ensureDir = require("./dir"); |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -16,8 +16,8 @@ /** | ||
let util = {}; | ||
util.kindOf = (arg) => arg === null ? "null" : arg === undefined ? "undefined" : /^\[object (.*)\]$/.exec(Object.prototype.toString.call(arg))[1]; | ||
util.kindOf = (arg) => arg === null ? "null" : typeof arg === "undefined" ? "undefined" : /^\[object (.*)\]$/.exec(Object.prototype.toString.call(arg))[1]; | ||
util.isKind = (arg, kind) => util.kindOf(arg).toLowerCase() === kind.toLowerCase(); | ||
util.isFunction = (arg) => util.isKind(arg, "function"); | ||
util.isObject = (arg) => arg !== null && arg !== undefined && util.isKind(arg, "object"); | ||
util.isObject = (arg) => arg !== null && typeof arg !== "undefined" && util.isKind(arg, "object"); | ||
util.isString = (arg) => util.isKind(arg, "string"); | ||
module.exports = util; |
{ | ||
"name": "enfsensure", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "Ensure file, folder, link or symlink existence in file system for node fs module", | ||
@@ -30,11 +30,11 @@ "license": "CC-BY-4.0", | ||
"dependencies": { | ||
"enfsmkdirp": "0.1", | ||
"enfspatch": "0.1" | ||
"enfsmkdirp": "^1.0", | ||
"enfspatch": "^1.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "2.7.0", | ||
"eslint-plugin-mocha": "2.1.0", | ||
"mocha": "2.4.5", | ||
"should": "8.3.0", | ||
"rimraf": "2.5.2" | ||
"eslint": "^3.18.0", | ||
"eslint-plugin-mocha": "^4.9.0", | ||
"mocha": "^3.2.0", | ||
"should": "^11.2.1", | ||
"rimraf": "^2.6.1" | ||
}, | ||
@@ -41,0 +41,0 @@ "keywords": [ |
@@ -0,0 +0,0 @@ [![Build Status](https://travis-ci.org/n3okill/enfsensure.svg)](https://travis-ci.org/n3okill/enfsensure) |
Sorry, the diff of this file is not supported yet
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 v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
36669
1
753
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedclone@2.1.2(transitive)
+ Addedenfsaddins@1.0.1(transitive)
+ Addedenfsmkdirp@1.0.0(transitive)
+ Addedenfspatch@1.0.1(transitive)
- Removedbalanced-match@0.3.0(transitive)
- Removedbrace-expansion@1.1.3(transitive)
- Removedclone@1.0.2(transitive)
- Removedenfsaddins@0.1.0(transitive)
- Removedenfsmkdirp@0.1.0(transitive)
- Removedenfspatch@0.1.0(transitive)
Updatedenfsmkdirp@^1.0
Updatedenfspatch@^1.0