@waiting/shared-core
Advanced tools
Comparing version 1.3.1 to 1.3.2
@@ -5,2 +5,6 @@ # Change Log | ||
## [1.3.2](https://github.com/waitingsong/node-shared-core/compare/v1.3.1...v1.3.2) (2019-02-24) | ||
<a name="1.3.1"></a> | ||
@@ -7,0 +11,0 @@ ## [1.3.1](https://github.com/waitingsong/node-shared-core/compare/v1.3.0...v1.3.1) (2019-02-22) |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 1.3.1 | ||
* @version 1.3.2 | ||
* @author waiting | ||
@@ -43,42 +43,42 @@ * @license MIT | ||
/** Return path if accessible, blank if not accessible */ | ||
function pathAccessible(path$$1) { | ||
return rxjs.defer(() => isPathAccessible(path$$1)).pipe(operators.map(exists => (exists ? path.normalize(path$$1) : ''))) | ||
function pathAccessible(path$1) { | ||
return rxjs.defer(() => isPathAccessible(path$1)).pipe(operators.map(exists => (exists ? path.normalize(path$1) : ''))) | ||
} | ||
// support relative file ('./foo') | ||
function isPathAccessible(path$$1) { | ||
return path$$1 | ||
? new Promise(resolve => fs.access(path$$1, err => resolve(err ? false : true))) | ||
function isPathAccessible(path) { | ||
return path | ||
? new Promise(resolve => fs.access(path, err => resolve(err ? false : true))) | ||
: Promise.resolve(false) | ||
} | ||
/** Check folder path exists, return path if exists, blank if not exists */ | ||
function dirExists(path$$1) { | ||
if (!path$$1) { | ||
function dirExists(path$1) { | ||
if (!path$1) { | ||
return rxjs.of('') | ||
} | ||
const dir = path.normalize(path$$1); | ||
const dir = path.normalize(path$1); | ||
return rxjs.defer(() => isDirExists(dir)).pipe(operators.map(exists => (exists ? dir : ''))) | ||
} | ||
function isDirExists(path$$1) { | ||
return path$$1 ? isDirFileExists(path$$1, 'DIR') : Promise.resolve(false) | ||
function isDirExists(path) { | ||
return path ? isDirFileExists(path, 'DIR') : Promise.resolve(false) | ||
} | ||
/** Check file exists, return path if exists, blank if not exists */ | ||
function fileExists(path$$1) { | ||
const file = path.normalize(path$$1); | ||
function fileExists(path$1) { | ||
const file = path.normalize(path$1); | ||
return rxjs.defer(() => isFileExists(file)).pipe(operators.map(exists => (exists ? file : ''))) | ||
} | ||
function isFileExists(path$$1) { | ||
return path$$1 ? isDirFileExists(path$$1, 'FILE') : Promise.resolve(false) | ||
function isFileExists(path) { | ||
return path ? isDirFileExists(path, 'FILE') : Promise.resolve(false) | ||
} | ||
function isDirFileExists(path$$1, type) { | ||
if (!path$$1) { | ||
function isDirFileExists(path, type) { | ||
if (!path) { | ||
return Promise.resolve(false) | ||
} | ||
else { | ||
return isPathAccessible(path$$1) | ||
return isPathAccessible(path) | ||
.then(accessible => { | ||
return !accessible | ||
? false | ||
: statAsync(path$$1).then(stats => { | ||
: statAsync(path).then(stats => { | ||
return type === 'DIR' ? stats.isDirectory() : stats.isFile() | ||
@@ -102,16 +102,16 @@ }) | ||
} | ||
function _createDirObb(path$$1, index) { | ||
return pathAccessible(path$$1).pipe(operators.mergeMap(str => { | ||
function _createDirObb(path, index) { | ||
return pathAccessible(path).pipe(operators.mergeMap(str => { | ||
return str | ||
? rxjs.of(str) | ||
: rxjs.defer(() => mkdirAsync(path$$1, 0o755)).pipe(operators.mapTo(path$$1)) | ||
: rxjs.defer(() => mkdirAsync(path, 0o755)).pipe(operators.mapTo(path)) | ||
})) | ||
} | ||
/** create directories recursively */ | ||
async function createDirAsync(path$$1) { | ||
if (!path$$1) { | ||
async function createDirAsync(path$1) { | ||
if (!path$1) { | ||
throw new Error('value of path param invalid') | ||
} | ||
else { | ||
const target = path.normalize(path$$1); // ! required for '.../.myca' under win32 | ||
const target = path.normalize(path$1); // ! required for '.../.myca' under win32 | ||
@@ -147,19 +147,19 @@ /* istanbul ignore else */ | ||
} | ||
const path$$1 = path.normalize(file); | ||
const path$1 = path.normalize(file); | ||
/* istanbul ignore else */ | ||
if (!await isFileExists(path$$1)) { | ||
if (!await isFileExists(path$1)) { | ||
const opts = options ? options : { mode: 0o640 }; | ||
if (Buffer.isBuffer(data)) { | ||
await writeFileAsync(path$$1, data, opts); | ||
await writeFileAsync(path$1, data, opts); | ||
} | ||
else if (typeof data === 'object') { | ||
await writeFileAsync(path$$1, JSON.stringify(data)); | ||
await writeFileAsync(path$1, JSON.stringify(data)); | ||
} | ||
else { | ||
await writeFileAsync(path$$1, data, opts); | ||
await writeFileAsync(path$1, data, opts); | ||
} | ||
} | ||
return path$$1 | ||
return path$1 | ||
} | ||
@@ -171,30 +171,30 @@ /* istanbul ignore next */ | ||
*/ | ||
async function rimraf(path$$1) { | ||
if (!path$$1) { | ||
async function rimraf(path) { | ||
if (!path) { | ||
return | ||
} | ||
await _rimraf(path$$1); | ||
if (await isDirExists(path$$1)) { | ||
await rmdirAsync(path$$1); | ||
await _rimraf(path); | ||
if (await isDirExists(path)) { | ||
await rmdirAsync(path); | ||
} | ||
} | ||
/* istanbul ignore next */ | ||
async function _rimraf(path$$1) { | ||
if (!path$$1) { | ||
async function _rimraf(path$1) { | ||
if (!path$1) { | ||
return | ||
} | ||
if (await isPathAccessible(path$$1)) { | ||
if (await isFileExists(path$$1)) { | ||
await unlinkAsync(path$$1); | ||
if (await isPathAccessible(path$1)) { | ||
if (await isFileExists(path$1)) { | ||
await unlinkAsync(path$1); | ||
return | ||
} | ||
const entries = await readDirAsync(path$$1); | ||
const entries = await readDirAsync(path$1); | ||
if (entries.length) { | ||
for (const entry of entries) { | ||
await _rimraf(path.join(path$$1, entry)); | ||
await _rimraf(path.join(path$1, entry)); | ||
} | ||
} | ||
else { | ||
await rmdirAsync(path$$1); | ||
await rmdirAsync(path$1); | ||
} | ||
@@ -219,8 +219,8 @@ } | ||
for (const dir of list) { | ||
const path$$1 = path.join(rootDir, dir.replace(/\.{2,}/, '/')); | ||
const path$1 = path.join(rootDir, dir.replace(/\.{2,}/, '/')); | ||
if (!await isPathAccessible(path$$1)) { | ||
if (!await isPathAccessible(path$1)) { | ||
continue | ||
} | ||
const files = await readDirAsync(path$$1); | ||
const files = await readDirAsync(path$1); | ||
@@ -231,5 +231,5 @@ for (const file of files) { | ||
} | ||
const source = path.join(path$$1, file); | ||
const source = path.join(path$1, file); | ||
const stripped = stripExampleSuffix(file); | ||
const target = path.join(path$$1, stripped); | ||
const target = path.join(path$1, stripped); | ||
@@ -280,8 +280,8 @@ if (!await isPathAccessible(target)) { | ||
const skipRule$ = rxjs.from(skipMsg).pipe(operators.defaultIfEmpty()); | ||
const content$ = pathAccessible(commitFile).pipe(operators.tap(path$$1 => { | ||
if (!path$$1) { | ||
const content$ = pathAccessible(commitFile).pipe(operators.tap(path => { | ||
if (!path) { | ||
console.info(`COMMIT_EDITMSG file not exists: "${commitFile}"`); | ||
process.exit(1); | ||
} | ||
}), operators.mergeMap(path$$1 => readFileAsync(path$$1, { encoding: 'utf8' })), operators.map(msg => { | ||
}), operators.mergeMap(path => readFileAsync(path, { encoding: 'utf8' })), operators.map(msg => { | ||
const head = msg.split(/\n|\r\n/)[0]; | ||
@@ -288,0 +288,0 @@ |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 1.3.1 | ||
* @version 1.3.2 | ||
* @author waiting | ||
@@ -47,3 +47,3 @@ * @license MIT | ||
return path | ||
? new Promise(resolve$$1 => access(path, err => resolve$$1(err ? false : true))) | ||
? new Promise(resolve => access(path, err => resolve(err ? false : true))) | ||
: Promise.resolve(false) | ||
@@ -50,0 +50,0 @@ } |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 1.3.1 | ||
* @version 1.3.2 | ||
* @author waiting | ||
@@ -8,0 +8,0 @@ * @license MIT |
{ | ||
"name": "@waiting/shared-core", | ||
"author": "waiting", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "node core function re export with Promise or Observable", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
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
59851
22
974