Comparing version 2.1.0 to 2.1.1
32
index.js
@@ -5,2 +5,3 @@ 'use strict'; | ||
var path = require('path'); | ||
var Debug = require('debug'); | ||
var readline = require('readline'); | ||
@@ -29,2 +30,3 @@ | ||
// fs | ||
const debug = Debug('qiao-file'); | ||
@@ -39,5 +41,14 @@ /** | ||
try { | ||
const srcExists = await fsExtra.pathExists(src); | ||
if (!srcExists) { | ||
debug('/ cp / src not exists'); | ||
return; | ||
} | ||
await fsExtra.copy(src, dest); | ||
debug('/ cp / success'); | ||
return true; | ||
} catch (e) { | ||
debug('/ cp / fail'); | ||
console.log(e); | ||
@@ -54,5 +65,14 @@ } | ||
try { | ||
await fsExtra.move(oldPath, newPath); | ||
const srcExists = await fsExtra.pathExists(oldPath); | ||
if (!srcExists) { | ||
debug('/ mv / src not exists'); | ||
return; | ||
} | ||
await fsExtra.move(oldPath, newPath, { overwrite: true }); | ||
debug('/ mv / success'); | ||
return true; | ||
} catch (e) { | ||
debug('/ mv / fail'); | ||
console.log(e); | ||
@@ -126,5 +146,3 @@ } | ||
fsExtra.readdir(dirPath, (err, files) => { | ||
if (err) return resolve(); | ||
return resolve(files); | ||
resolve(err ? false : files); | ||
}); | ||
@@ -157,6 +175,6 @@ }); | ||
// read | ||
const realPath = path.resolve(fpath); | ||
for (let i = 0; i < dirs.length; i++) { | ||
const dir = dirs[i]; | ||
const isDirRes = await isDir(dir); | ||
const realPath = path.resolve(fpath, dir); | ||
const isDirRes = await isDir(realPath); | ||
if (isDirRes) { | ||
@@ -168,3 +186,3 @@ folders.push({ | ||
await getFoldersAndFiles(path.resolve(realPath, `./${dir}`), folders, files); | ||
await getFoldersAndFiles(realPath, folders, files); | ||
} else { | ||
@@ -171,0 +189,0 @@ files.push({ |
{ | ||
"name": "qiao-file", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "nodejs file tool", | ||
@@ -32,2 +32,5 @@ "keywords": [ | ||
}, | ||
"devDependencies": { | ||
"debug": "^4.3.4" | ||
}, | ||
"nx": { | ||
@@ -50,3 +53,3 @@ "namedInputs": { | ||
}, | ||
"gitHead": "834909866d35d20693871e90b07dfebe744a75ef" | ||
"gitHead": "e3a210c00dd4b2fd1642542ffa6656ee622b1f3c" | ||
} |
@@ -39,2 +39,13 @@ ## qiao-file | ||
- src | ||
- 类型: string | ||
- 说明: 文件或文件夹地址 | ||
- dest | ||
- 类型: string | ||
- 说明: 目标文件或文件夹地址,如果 dest 存在,默认会覆盖 | ||
- return | ||
- 类型: boolean | ||
- 说明: 结果 | ||
- true: 成功 | ||
```javascript | ||
@@ -48,2 +59,13 @@ const res = await cp(src, dest); | ||
- src | ||
- 类型: string | ||
- 说明: 文件或文件夹地址 | ||
- dest | ||
- 类型: string | ||
- 说明: 目标文件或文件夹地址,如果 dest 存在,默认会覆盖 | ||
- return | ||
- 类型: boolean | ||
- 说明: 结果 | ||
- true: 成功 | ||
```javascript | ||
@@ -57,2 +79,10 @@ const res = await mv(src, dest); | ||
- path | ||
- 类型: string | ||
- 说明: 文件或文件夹地址 | ||
- return | ||
- 类型: boolean | ||
- 说明: 结果 | ||
- true: 成功 | ||
```javascript | ||
@@ -70,2 +100,10 @@ const res = await rm(path); | ||
- dirpath | ||
- 类型: string | ||
- 说明: 文件夹地址 | ||
- return | ||
- 类型: boolean | ||
- 说明: 结果 | ||
- true: 成功 | ||
```javascript | ||
@@ -79,2 +117,12 @@ const res = await mkdir(dirpath); | ||
- dirpath | ||
- 类型: string | ||
- 说明: 文件夹地址 | ||
- return | ||
- 类型: string[] | ||
- 说明: dirpath 下的文件或文件夹路径 | ||
- ```javascript | ||
['path', ...] | ||
``` | ||
```javascript | ||
@@ -88,2 +136,27 @@ const res = await readdir(dirpath); | ||
- dirpath | ||
- 类型: string | ||
- 说明: 文件夹地址 | ||
- return | ||
- 类型: object | ||
- 说明: dirpath 下的文件或文件夹路径 | ||
- ```javascript | ||
{ | ||
files: [ | ||
{ | ||
name: 'index.js', | ||
path: '/path/to/index.js', | ||
}, | ||
... | ||
], | ||
folders: [ | ||
{ | ||
name: '1', | ||
path: '/path/to/1', | ||
}, | ||
... | ||
], | ||
} | ||
``` | ||
```javascript | ||
@@ -90,0 +163,0 @@ const res = await lsdir(dirpath); |
// fs | ||
import { copy, move, remove } from 'fs-extra'; | ||
import { pathExists, copy, move, remove } from 'fs-extra'; | ||
// debug | ||
import Debug from 'debug'; | ||
const debug = Debug('qiao-file'); | ||
/** | ||
@@ -12,5 +16,14 @@ * cp | ||
try { | ||
const srcExists = await pathExists(src); | ||
if (!srcExists) { | ||
debug('/ cp / src not exists'); | ||
return; | ||
} | ||
await copy(src, dest); | ||
debug('/ cp / success'); | ||
return true; | ||
} catch (e) { | ||
debug('/ cp / fail'); | ||
console.log(e); | ||
@@ -27,5 +40,14 @@ } | ||
try { | ||
await move(oldPath, newPath); | ||
const srcExists = await pathExists(oldPath); | ||
if (!srcExists) { | ||
debug('/ mv / src not exists'); | ||
return; | ||
} | ||
await move(oldPath, newPath, { overwrite: true }); | ||
debug('/ mv / success'); | ||
return true; | ||
} catch (e) { | ||
debug('/ mv / fail'); | ||
console.log(e); | ||
@@ -32,0 +54,0 @@ } |
@@ -32,5 +32,3 @@ // path | ||
fsReadDir(dirPath, (err, files) => { | ||
if (err) return resolve(); | ||
return resolve(files); | ||
resolve(err ? false : files); | ||
}); | ||
@@ -63,6 +61,6 @@ }); | ||
// read | ||
const realPath = path.resolve(fpath); | ||
for (let i = 0; i < dirs.length; i++) { | ||
const dir = dirs[i]; | ||
const isDirRes = await isDir(dir); | ||
const realPath = path.resolve(fpath, dir); | ||
const isDirRes = await isDir(realPath); | ||
if (isDirRes) { | ||
@@ -74,3 +72,3 @@ folders.push({ | ||
await getFoldersAndFiles(path.resolve(realPath, `./${dir}`), folders, files); | ||
await getFoldersAndFiles(realPath, folders, files); | ||
} else { | ||
@@ -77,0 +75,0 @@ files.push({ |
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
18903
574
309
1