Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dir-tree-creator

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dir-tree-creator - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

README.md

79

dir-tree-creator.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc