Comparing version 0.4.4 to 1.0.0
138
index.js
@@ -30,18 +30,18 @@ 'use strict'; | ||
const getFoldersAndFiles = (fpath, folders, files) => { | ||
fs.readdirSync(fpath).forEach(function(name){ | ||
const stat = fs.statSync(fpath + name); | ||
if(stat.isDirectory()){ | ||
folders.push({ | ||
path : fpath, | ||
name : name | ||
}); | ||
fs.readdirSync(fpath).forEach(function(name){ | ||
const stat = fs.statSync(fpath + name); | ||
if(stat.isDirectory()){ | ||
folders.push({ | ||
path : fpath, | ||
name : name | ||
}); | ||
getFoldersAndFiles(fpath + name + '/', folders, files); | ||
}else { | ||
files.push({ | ||
path : fpath, | ||
name : name | ||
}); | ||
} | ||
}); | ||
getFoldersAndFiles(fpath + name + '/', folders, files); | ||
}else { | ||
files.push({ | ||
path : fpath, | ||
name : name | ||
}); | ||
} | ||
}); | ||
}; | ||
@@ -56,24 +56,24 @@ | ||
const getFileTree = (fpath, fileTree, ignores) => { | ||
fs.readdirSync(fpath).forEach(function(name){ | ||
const rpath = fpath + name; | ||
if(isFileTreeIgnore(rpath, ignores)) return; | ||
fs.readdirSync(fpath).forEach(function(name){ | ||
const rpath = fpath + name; | ||
if(isFileTreeIgnore(rpath, ignores)) return; | ||
const stat = fs.statSync(rpath); | ||
if(stat.isDirectory()){ | ||
let info = {}; | ||
info.path = fpath; | ||
info.name = name; | ||
info.children = []; | ||
const stat = fs.statSync(rpath); | ||
if(stat.isDirectory()){ | ||
let info = {}; | ||
info.path = fpath; | ||
info.name = name; | ||
info.children = []; | ||
fileTree.push(info); | ||
fileTree.push(info); | ||
getFileTree(rpath + '/', info.children, ignores); | ||
}else { | ||
let info = {}; | ||
info.path = fpath; | ||
info.name = name; | ||
getFileTree(rpath + '/', info.children, ignores); | ||
}else { | ||
let info = {}; | ||
info.path = fpath; | ||
info.name = name; | ||
fileTree.push(info); | ||
} | ||
}); | ||
fileTree.push(info); | ||
} | ||
}); | ||
}; | ||
@@ -87,8 +87,8 @@ | ||
const checkDir = (dir, list) => { | ||
const pdir = path.dirname(dir); | ||
const pdir = path.dirname(dir); | ||
if(!isExists(pdir)){ | ||
list.push(pdir); | ||
checkDir(pdir, list); | ||
} | ||
if(!isExists(pdir)){ | ||
list.push(pdir); | ||
checkDir(pdir, list); | ||
} | ||
}; | ||
@@ -98,10 +98,10 @@ | ||
const isFileTreeIgnore = (rpath, ignores) => { | ||
if(!rpath || !ignores || !ignores.length) return; | ||
if(!rpath || !ignores || !ignores.length) return; | ||
let ignore = false; | ||
for(let i=0; i<ignores.length; i++){ | ||
if(rpath.indexOf(ignores[i]) > -1) ignore = true; | ||
} | ||
let ignore = false; | ||
for(let i=0; i<ignores.length; i++){ | ||
if(rpath.indexOf(ignores[i]) > -1) ignore = true; | ||
} | ||
return ignore; | ||
return ignore; | ||
}; | ||
@@ -140,6 +140,6 @@ | ||
return true; | ||
return true; | ||
}catch(e){ | ||
console.log(e); | ||
return false; | ||
return false; | ||
} | ||
@@ -153,28 +153,28 @@ }; | ||
const rm = (fpath) => { | ||
try{ | ||
// rm file | ||
const pathStat = fs.statSync(fpath); | ||
if(!pathStat.isDirectory()){ | ||
fs.unlinkSync(fpath); | ||
try{ | ||
// rm file | ||
const pathStat = fs.statSync(fpath); | ||
if(!pathStat.isDirectory()){ | ||
fs.unlinkSync(fpath); | ||
return true; | ||
} | ||
return true; | ||
} | ||
// ls dir | ||
let folders = []; | ||
let files = []; | ||
getFoldersAndFiles(fpath, folders, files); | ||
folders.reverse(); | ||
// ls dir | ||
let folders = []; | ||
let files = []; | ||
getFoldersAndFiles(fpath, folders, files); | ||
folders.reverse(); | ||
// rm folder | ||
for(let i=0; i<files.length; i++) fs.unlinkSync(files[i].path + files[i].name); | ||
for(let i=0; i<folders.length; i++) fs.rmdirSync(folders[i].path + folders[i].name); | ||
fs.rmdirSync(fpath); | ||
// rm folder | ||
for(let i=0; i<files.length; i++) fs.unlinkSync(files[i].path + files[i].name); | ||
for(let i=0; i<folders.length; i++) fs.rmdirSync(folders[i].path + folders[i].name); | ||
fs.rmdirSync(fpath); | ||
// return | ||
return true; | ||
}catch(e){ | ||
console.log(e); | ||
return false; | ||
} | ||
// return | ||
return true; | ||
}catch(e){ | ||
console.log(e); | ||
return false; | ||
} | ||
}; | ||
@@ -298,3 +298,3 @@ | ||
const readFileLineByLineSync = (filePath) => { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve) => { | ||
// lines | ||
@@ -301,0 +301,0 @@ let lines = []; |
{ | ||
"name": "qiao-file", | ||
"version": "0.4.4", | ||
"description": "nodejs file tool", | ||
"author": "uikoo9 <uikoo9@qq.com>", | ||
"homepage": "https://code.insistime.com/qiao-file", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/uikoo9/qiao-monorepo.git" | ||
}, | ||
"scripts": { | ||
"build": "rollup --config rollup.config.js", | ||
"prepublish": "npm run build" | ||
}, | ||
"gitHead": "965605aef5009d5114238b1a1517c0e4754be0c3" | ||
"name": "qiao-file", | ||
"version": "1.0.0", | ||
"description": "nodejs file tool", | ||
"author": "uikoo9 <uikoo9@qq.com>", | ||
"homepage": "https://code.insistime.com/qiao-file", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"module": "src/index.js", | ||
"sideEffets": false, | ||
"files": [ | ||
"src" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/uikoo9/qiao-monorepo.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/uikoo9/qiao-monorepo/issues" | ||
}, | ||
"scripts": { | ||
"build": "rollup --config _config.rollup.js", | ||
"eslint": "eslint . --ext .js -c _config.eslint.js", | ||
"eslintfix": "eslint . --ext .js --fix -c _config.eslint.js", | ||
"prepublish": "npm run build && npm run eslintfix" | ||
}, | ||
"gitHead": "ba5ac8072b2b7849564d5ba66ea22baec5ea5c54" | ||
} |
@@ -10,5 +10,5 @@ 'use strict'; | ||
// other | ||
export * from './lib/cmd.js' | ||
export * from './lib/dir.js' | ||
export * from './lib/file.js' | ||
export * from './lib/is.js' | ||
export * from './lib/cmd.js'; | ||
export * from './lib/dir.js'; | ||
export * from './lib/file.js'; | ||
export * from './lib/is.js'; |
@@ -40,6 +40,6 @@ 'use strict'; | ||
return true; | ||
return true; | ||
}catch(e){ | ||
console.log(e); | ||
return false; | ||
return false; | ||
} | ||
@@ -53,28 +53,28 @@ }; | ||
export const rm = (fpath) => { | ||
try{ | ||
// rm file | ||
const pathStat = fs.statSync(fpath); | ||
if(!pathStat.isDirectory()){ | ||
fs.unlinkSync(fpath); | ||
try{ | ||
// rm file | ||
const pathStat = fs.statSync(fpath); | ||
if(!pathStat.isDirectory()){ | ||
fs.unlinkSync(fpath); | ||
return true; | ||
} | ||
return true; | ||
} | ||
// ls dir | ||
let folders = []; | ||
let files = []; | ||
getFoldersAndFiles(fpath, folders, files); | ||
folders.reverse(); | ||
// ls dir | ||
let folders = []; | ||
let files = []; | ||
getFoldersAndFiles(fpath, folders, files); | ||
folders.reverse(); | ||
// rm folder | ||
for(let i=0; i<files.length; i++) fs.unlinkSync(files[i].path + files[i].name); | ||
for(let i=0; i<folders.length; i++) fs.rmdirSync(folders[i].path + folders[i].name); | ||
fs.rmdirSync(fpath); | ||
// rm folder | ||
for(let i=0; i<files.length; i++) fs.unlinkSync(files[i].path + files[i].name); | ||
for(let i=0; i<folders.length; i++) fs.rmdirSync(folders[i].path + folders[i].name); | ||
fs.rmdirSync(fpath); | ||
// return | ||
return true; | ||
}catch(e){ | ||
console.log(e); | ||
return false; | ||
} | ||
// return | ||
return true; | ||
}catch(e){ | ||
console.log(e); | ||
return false; | ||
} | ||
}; |
@@ -70,3 +70,3 @@ 'use strict'; | ||
export const readFileLineByLineSync = (filePath) => { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve) => { | ||
// lines | ||
@@ -73,0 +73,0 @@ let lines = []; |
@@ -19,18 +19,18 @@ 'use strict'; | ||
export const getFoldersAndFiles = (fpath, folders, files) => { | ||
fs.readdirSync(fpath).forEach(function(name){ | ||
const stat = fs.statSync(fpath + name); | ||
if(stat.isDirectory()){ | ||
folders.push({ | ||
path : fpath, | ||
name : name | ||
}); | ||
fs.readdirSync(fpath).forEach(function(name){ | ||
const stat = fs.statSync(fpath + name); | ||
if(stat.isDirectory()){ | ||
folders.push({ | ||
path : fpath, | ||
name : name | ||
}); | ||
getFoldersAndFiles(fpath + name + '/', folders, files); | ||
}else{ | ||
files.push({ | ||
path : fpath, | ||
name : name | ||
}); | ||
} | ||
}); | ||
getFoldersAndFiles(fpath + name + '/', folders, files); | ||
}else{ | ||
files.push({ | ||
path : fpath, | ||
name : name | ||
}); | ||
} | ||
}); | ||
}; | ||
@@ -45,24 +45,24 @@ | ||
export const getFileTree = (fpath, fileTree, ignores) => { | ||
fs.readdirSync(fpath).forEach(function(name){ | ||
const rpath = fpath + name; | ||
if(isFileTreeIgnore(rpath, ignores)) return; | ||
fs.readdirSync(fpath).forEach(function(name){ | ||
const rpath = fpath + name; | ||
if(isFileTreeIgnore(rpath, ignores)) return; | ||
const stat = fs.statSync(rpath); | ||
if(stat.isDirectory()){ | ||
let info = {}; | ||
info.path = fpath; | ||
info.name = name; | ||
info.children = []; | ||
const stat = fs.statSync(rpath); | ||
if(stat.isDirectory()){ | ||
let info = {}; | ||
info.path = fpath; | ||
info.name = name; | ||
info.children = []; | ||
fileTree.push(info); | ||
fileTree.push(info); | ||
getFileTree(rpath + '/', info.children, ignores); | ||
}else{ | ||
let info = {}; | ||
info.path = fpath; | ||
info.name = name; | ||
getFileTree(rpath + '/', info.children, ignores); | ||
}else{ | ||
let info = {}; | ||
info.path = fpath; | ||
info.name = name; | ||
fileTree.push(info); | ||
} | ||
}); | ||
fileTree.push(info); | ||
} | ||
}); | ||
}; | ||
@@ -76,8 +76,8 @@ | ||
export const checkDir = (dir, list) => { | ||
const pdir = path.dirname(dir); | ||
const pdir = path.dirname(dir); | ||
if(!isExists(pdir)){ | ||
list.push(pdir); | ||
checkDir(pdir, list); | ||
} | ||
if(!isExists(pdir)){ | ||
list.push(pdir); | ||
checkDir(pdir, list); | ||
} | ||
}; | ||
@@ -87,10 +87,10 @@ | ||
const isFileTreeIgnore = (rpath, ignores) => { | ||
if(!rpath || !ignores || !ignores.length) return; | ||
if(!rpath || !ignores || !ignores.length) return; | ||
let ignore = false; | ||
for(let i=0; i<ignores.length; i++){ | ||
if(rpath.indexOf(ignores[i]) > -1) ignore = true; | ||
} | ||
let ignore = false; | ||
for(let i=0; i<ignores.length; i++){ | ||
if(rpath.indexOf(ignores[i]) > -1) ignore = true; | ||
} | ||
return ignore; | ||
return ignore; | ||
}; |
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 bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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
0
1
20778
10
633