Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,50 @@ treeview --help

```json
{
"/Users/ved/projects/my-app": {
"public": {},
"src": {
"components": {},
"pages": {},
"utils": {}
"path": "/Users/ved/projects/my-app",
"name": "my-app",
"type": "directory",
"children": [
{
"path": "/Users/ved/projects/my-app/src",
"name": "src",
"type": "directory",
"children": [
{
"path": "/Users/ved/projects/my-app/src/components",
"name": "components",
"type": "directory",
"children": []
},
{
"path": "/Users/ved/projects/my-app/src/pages",
"name": "pages",
"type": "directory",
"children": []
},
{
"path": "/Users/ved/projects/my-app/src/utils",
"name": "utils",
"type": "directory",
"children": []
}
]
},
"tests": {}
}
{
"path": "/Users/ved/projects/my-app/public",
"name": "public",
"type": "directory",
"children": []
},
{
"path": "/Users/ved/projects/my-app/tests",
"name": "tests",
"type": "directory",
"children": []
}
]
}

```

---
Expand Down
36 changes: 25 additions & 11 deletions src/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ function printTree(
* Recursively stores the folder structure in nested json object, ignoring items based on ignoreConfig.
* If dirsOnly is true, files will be skipped.
*/
function printTreeAsJson(
function treeAsJson(
dirPath,
ignoreConfig = { exactMatches: [], globPatterns: [] },
dirsOnly = false,
jsonTree = {}

dirsOnly = false
) {
let items = fs
.readdirSync(dirPath)
Expand All @@ -116,16 +114,25 @@ function printTreeAsJson(
return fs.statSync(fullPath).isDirectory();
});
}

let currLevel=[]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Missing space after currLevel =

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/tree.js
Line: 117:117

Comment:
**style:** Missing space after `currLevel =`

How can I resolve this? If you propose a fix, please make it concise.

items.forEach((item, index) => {
const fullPath = path.join(dirPath, item);
if (fs.statSync(fullPath).isDirectory()) {
jsonTree[item]=printTreeAsJson(fullPath, ignoreConfig, dirsOnly,{});
currLevel.push({
"path":fullPath,
"name":item,
"type":"directory",
"children":treeAsJson(fullPath,ignoreConfig,dirsOnly)
})
Comment on lines 121 to 126
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Missing space after colons in object literals (e.g., "path": fullPath instead of "path":fullPath)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/tree.js
Line: 121:126

Comment:
**style:** Missing space after colons in object literals (e.g., `"path": fullPath` instead of `"path":fullPath`)

How can I resolve this? If you propose a fix, please make it concise.

}else{
jsonTree[item]="FILE"
currLevel.push({
"path":fullPath,
"name":item,
"type":"file"
})
}
});
return jsonTree;
return currLevel;
}


Expand All @@ -140,9 +147,16 @@ function runTree(
asJson = false
) {
const ignoreConfig = getIgnoreList(startPath, additionalFiles, additionalPatterns);
if (asJson){
const tree = { [startPath]: printTreeAsJson(startPath, ignoreConfig, dirsOnly) };
console.log(JSON.stringify(tree, null, 2));
if (asJson){
const tree = {
"path":startPath,
"name":startPath.split("/").at(-1),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The .at(-1) method will fail for Windows paths that use backslashes. Consider using path.basename(startPath) which handles cross-platform paths correctly

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/tree.js
Line: 153:153

Comment:
**logic:** The `.at(-1)` method will fail for Windows paths that use backslashes. Consider using `path.basename(startPath)` which handles cross-platform paths correctly

How can I resolve this? If you propose a fix, please make it concise.

"type":"directory",
"children":treeAsJson(startPath,ignoreConfig,dirsOnly)
}

console.log(JSON.stringify(tree,null,2))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Missing space after comma in JSON.stringify(tree, null, 2)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/tree.js
Line: 158:158

Comment:
**style:** Missing space after comma in `JSON.stringify(tree, null, 2)`

How can I resolve this? If you propose a fix, please make it concise.

// console.log(JSON.stringify( {[startPath]:printTreeAsJson(startPath, ignoreConfig, dirsOnly)} ,null , 4))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Remove this commented-out code before merging

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/tree.js
Line: 159:159

Comment:
**style:** Remove this commented-out code before merging

How can I resolve this? If you propose a fix, please make it concise.

}
else{
console.log(startPath);
Expand Down