-
Notifications
You must be signed in to change notification settings - Fork 10
Modified the output JSON structure relevant to issue #8 #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
8265702
e014cfd
da03592
5083de8
78ee9f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -116,16 +114,25 @@ function printTreeAsJson( | |
| return fs.statSync(fullPath).isDirectory(); | ||
| }); | ||
| } | ||
|
|
||
| let currLevel=[] | ||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Missing space after colons in object literals (e.g., Prompt To Fix With AIThis 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; | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -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), | ||
|
||
| "type":"directory", | ||
| "children":treeAsJson(startPath,ignoreConfig,dirsOnly) | ||
| } | ||
|
|
||
| console.log(JSON.stringify(tree,null,2)) | ||
|
||
| // console.log(JSON.stringify( {[startPath]:printTreeAsJson(startPath, ignoreConfig, dirsOnly)} ,null , 4)) | ||
|
||
| } | ||
| else{ | ||
| console.log(startPath); | ||
|
|
||
There was a problem hiding this comment.
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