dir-tree-creator
Advanced tools
Comparing version 2.0.1 to 3.0.0
@@ -1,58 +0,51 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const archy = require('archy'); | ||
const glob = require('glob'); | ||
const async = require('async'); | ||
'use strict' | ||
const path = require('path') | ||
const archy = require('archy') | ||
const klaw = require('klaw') | ||
function add_node_to_tree(tree, parent_dir, node_to_add) { | ||
if (parent_dir === tree.label) { | ||
function addNode (tree, par, node) { | ||
if (par === tree.label) { | ||
tree.nodes.push({ | ||
label: node_to_add, | ||
label: node, | ||
nodes: [] | ||
}); | ||
}) | ||
} else { | ||
tree.nodes.forEach((t_node) => { | ||
if (typeof t_node === 'object' && t_node.label === parent_dir) { | ||
t_node.nodes.push({ | ||
label: node_to_add, | ||
tree.nodes.forEach(n => { | ||
if (typeof n === 'object' && n.label === par) { | ||
n.nodes.push({ | ||
label: node, | ||
nodes: [] | ||
}); | ||
} else if (typeof t_node === 'object' && t_node.label !== parent_dir) { | ||
add_node_to_tree(t_node, parent_dir, node_to_add); | ||
}) | ||
} else if (typeof n === 'object' && n.label !== par) { | ||
addNode(n, par, node) | ||
} | ||
}); | ||
}) | ||
} | ||
} | ||
function dir_tree_creator(opts, cb) { | ||
if (typeof opts !== 'object') { | ||
return cb(new TypeError(`'options' parameter must be of type object.`)); | ||
function dirTree (root, label, cb) { | ||
if (typeof label === 'function') { | ||
cb = label | ||
label = path.basename(root) | ||
} | ||
const def_ignore = ['{node_modules,.git}/**']; | ||
opts.label = opts.label ? opts.label : path.basename(opts.root); | ||
opts.ignore = (opts.ignore && Array.isArray(opts.ignore)) ? opts.ignore.concat(def_ignore) : def_ignore; | ||
glob('**/**', {absolute: true, ignore: opts.ignore}, (er, files) => { | ||
if (er) { | ||
return cb(er); | ||
} else { | ||
var tree = { | ||
label: opts.label, | ||
const paths = [] | ||
klaw(root).on('error', er => cb(er)).on('data', i => paths.push(i.path)) | ||
.on('end', () => { | ||
const tree = { | ||
label: label, | ||
nodes: [] | ||
}; | ||
async.each(files, (f, callback) => { | ||
var parent_dir = path.parse(f).dir; | ||
if (parent_dir === opts.root) { | ||
add_node_to_tree(tree, opts.label, path.basename(f)); | ||
} | ||
for (let i = 0; i < paths.length; i += 1) { | ||
const p = paths[i] | ||
const par = path.dirname(p) | ||
if (par === root) { | ||
addNode(tree, label, path.basename(p)) | ||
} else { | ||
add_node_to_tree(tree, path.basename(parent_dir), path.basename(f)); | ||
addNode(tree, path.basename(par), path.basename(p)) | ||
} | ||
return callback(); | ||
}, (er) => { | ||
if (er) return cb(er); | ||
return cb(null, archy(tree).trim()); | ||
}); | ||
} | ||
}); | ||
} | ||
return cb(null, archy(tree).trim()) | ||
}) | ||
} | ||
module.exports = dir_tree_creator; | ||
module.exports = dirTree |
{ | ||
"name": "dir-tree-creator", | ||
"version": "2.0.1", | ||
"description": "simple directory tree structure creator based on the given root path", | ||
"version": "3.0.0", | ||
"description": "npm like directory tree structure creator based on the given root path", | ||
"main": "dir-tree-creator.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/manidlou/dir-tree-nodejs.git" | ||
"url": "git+https://github.com/manidlou/dir-tree-creator.git" | ||
}, | ||
@@ -18,10 +18,24 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/manidlou/dir-tree-nodejs/issues" | ||
"url": "https://github.com/manidlou/dir-tree-creator/issues" | ||
}, | ||
"homepage": "https://github.com/manidlou/dir-tree-nodejs#readme", | ||
"homepage": "https://github.com/manidlou/dir-tree-creator#readme", | ||
"dependencies": { | ||
"archy": "^1.0.0", | ||
"async": "^2.1.2", | ||
"glob": "^7.1.1" | ||
"klaw": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"fs-extra": "^4.0.1", | ||
"mocha": "^3.5.0", | ||
"standard": "^10.0.3" | ||
}, | ||
"standard": { | ||
"env": [ | ||
"mocha" | ||
] | ||
}, | ||
"scripts": { | ||
"lint": "standard", | ||
"unit": "mocha", | ||
"test": "npm run lint && npm run unit" | ||
} | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2
63
0
4810
3
48
+ Addedklaw@^2.1.0
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedklaw@2.1.1(transitive)
- Removedasync@^2.1.2
- Removedglob@^7.1.1
- Removedasync@2.6.4(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedlodash@4.17.21(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedwrappy@1.0.2(transitive)