@@ -6,6 +6,7 @@ A file tree generator for Deno. Generate beautiful directory trees instantly fro
66
77- [ Installation] ( #installation )
88- [ Quick Start] ( #quick-start )
9+ - [ Multiple Output Formats] ( #multiple-output-formats )
910- [ Configuration] ( #configuration )
1011 - [ Tree Options] ( #tree-options )
1112 - [ Performance Settings] ( #performance-settings )
@@ -18,7 +19,9 @@ A file tree generator for Deno. Generate beautiful directory trees instantly fro
1819- [ API Reference] ( #api-reference )
1920 - [ Main API] ( #main-api )
2021 - [ Configuration Options] ( #configuration-options )
22+ - [ Generate Options] ( #generate-options )
2123 - [ File Metadata] ( #file-metadata )
24+ - [ Tree Node Structure] ( #tree-node-structure )
2225- [ Troubleshooting] ( #troubleshooting )
2326 - [ Common Issues] ( #common-issues )
2427 - [ Debug Mode] ( #debug-mode )
@@ -28,7 +31,7 @@ A file tree generator for Deno. Generate beautiful directory trees instantly fro
2831## Installation
2932
3033``` bash
31- deno install @neabyte/deno-tree
34+ deno add jsr: @neabyte/deno-tree
3235```
3336
3437## Quick Start
@@ -66,6 +69,84 @@ console.log(result)
6669└── README.md
6770```
6871
72+ ### Multiple Output Formats
73+
74+ ``` ts
75+ import tree from ' @neabyte/deno-tree'
76+
77+ await tree .init (' /path/to/directory' , {
78+ ignoreDirs: [' node_modules' , ' .git' , ' dist' ],
79+ maxFiles: 1000 ,
80+ showHidden: false ,
81+ maxDepth: 3
82+ })
83+
84+ // Tree format (default)
85+ const treeOutput = await tree .generate (' /path/to/directory' )
86+ console .log (treeOutput )
87+
88+ // JSON format
89+ const jsonOutput = await tree .generate (' /path/to/directory' , { format: ' json' })
90+ console .log (jsonOutput )
91+
92+ // Markdown format
93+ const markdownOutput = await tree .generate (' /path/to/directory' , { format: ' markdown' })
94+ console .log (markdownOutput )
95+ ```
96+
97+ ** Format Examples:**
98+
99+ ** Tree Format:**
100+
101+ ```
102+ .
103+ ├── src/
104+ │ ├── components/
105+ │ │ ├── Button.tsx
106+ │ │ └── Modal.tsx
107+ │ └── index.ts
108+ ├── deno.json
109+ └── README.md
110+ ```
111+
112+ ** JSON Format:**
113+
114+ ``` json
115+ {
116+ "name" : " project" ,
117+ "type" : " directory" ,
118+ "path" : " /path/to/project" ,
119+ "children" : [
120+ {
121+ "name" : " src" ,
122+ "type" : " directory" ,
123+ "path" : " /path/to/project/src" ,
124+ "children" : [
125+ {
126+ "name" : " Button.tsx" ,
127+ "type" : " file" ,
128+ "path" : " /path/to/project/src/Button.tsx" ,
129+ "size" : 1024 ,
130+ "extension" : " tsx"
131+ }
132+ ]
133+ }
134+ ]
135+ }
136+ ```
137+
138+ ** Markdown Format:**
139+
140+ ```
141+ project/
142+ - src/
143+ - Button.tsx
144+ - Modal.tsx
145+ - index.ts
146+ - deno.json
147+ - README.md
148+ ```
149+
69150## Configuration
70151
71152### Tree Options
@@ -79,6 +160,15 @@ interface TreeOptions {
79160}
80161```
81162
163+ ### Generate Options
164+
165+ ``` ts
166+ interface GenerateOptions {
167+ format? : ' tree' | ' json' | ' markdown' // Output format (default: 'tree')
168+ includeStats? : boolean // Include file statistics (default: false)
169+ }
170+ ```
171+
82172### Performance Settings
83173
84174``` ts
@@ -134,6 +224,7 @@ const projectA = await tree.generate('/workspace/project-a')
134224const projectB = await tree .generate (' /workspace/project-b' )
135225const projectC = await tree .generate (' /workspace/project-c' )
136226
227+ // Log the trees
137228console .log (' Project A Tree:' , projectA )
138229console .log (' Project B Tree:' , projectB )
139230console .log (' Project C Tree:' , projectC )
@@ -202,13 +293,13 @@ console.log('Project B:', treeB)
202293
203294### Main API
204295
205- | Method | Description | Parameters | Returns |
206- | ------------ | -------------------------------------- | ------------------------------------- | ----------------- |
207- | ` clear() ` | Clear all stored file metadata | None | ` void ` |
208- | ` generate() ` | Generate formatted tree string | ` rootPath: string ` | ` Promise<string> ` |
209- | ` init() ` | Scan directory and store file metadata | ` path: string, options?: TreeOptions ` | ` Promise<void> ` |
210- | ` remove() ` | Remove file/directory from tree | ` path: string ` | ` Promise<void> ` |
211- | ` set() ` | Add single file to tree metadata | ` path: string ` | ` Promise<void> ` |
296+ | Method | Description | Parameters | Returns |
297+ | ------------ | -------------------------------------- | --------------------------------------------- | ----------------- |
298+ | ` clear() ` | Clear all stored file metadata | None | ` void ` |
299+ | ` generate() ` | Generate formatted tree string | ` rootPath: string, options?: GenerateOptions ` | ` Promise<string> ` |
300+ | ` init() ` | Scan directory and store file metadata | ` path: string, options?: TreeOptions ` | ` Promise<void> ` |
301+ | ` remove() ` | Remove file/directory from tree | ` path: string ` | ` Promise<void> ` |
302+ | ` set() ` | Add single file to tree metadata | ` path: string ` | ` Promise<void> ` |
212303
213304### Configuration Options
214305
@@ -219,6 +310,13 @@ console.log('Project B:', treeB)
219310| ` showHidden ` | boolean | ❌ | Show hidden files/directories | ` false ` |
220311| ` maxDepth ` | number | ❌ | Maximum directory depth | ` 3 ` |
221312
313+ ### Generate Options
314+
315+ | Property | Type | Required | Description | Example |
316+ | -------------- | ------- | -------- | ----------------------- | ---------------------- |
317+ | ` format ` | string | ❌ | Output format | ` 'json' ` , ` 'markdown' ` |
318+ | ` includeStats ` | boolean | ❌ | Include file statistics | ` true ` |
319+
222320### File Metadata
223321
224322``` ts
@@ -233,6 +331,20 @@ interface FileMetadata {
233331}
234332```
235333
334+ ### Tree Node Structure
335+
336+ ``` ts
337+ interface TreeNode {
338+ name: string // Node name
339+ type: ' file' | ' directory' // Node type
340+ path: string // Absolute path
341+ size? : number // File size in bytes
342+ modified? : Date // Last modification date
343+ extension? : string // File extension
344+ children? : TreeNode [] // Child nodes
345+ }
346+ ```
347+
236348## Troubleshooting
237349
238350### Common Issues
@@ -260,14 +372,21 @@ interface FileMetadata {
260372``` ts
261373import tree from ' @neabyte/deno-tree'
262374
263- // Debug file storage
375+ // Debug file storage and generation
264376await tree .init (' /path/to/project' , { maxFiles: 100 })
265- console .log (' Files stored:' , tree .files .size )
266377
267378// Debug specific path generation
268379const result = await tree .generate (' /path/to/project/src' )
269380console .log (' Generated tree length:' , result .length )
270381console .log (' Tree output:' , result )
382+
383+ // Debug JSON format
384+ const jsonResult = await tree .generate (' /path/to/project' , { format: ' json' })
385+ console .log (' JSON output length:' , jsonResult .length )
386+
387+ // Debug markdown format
388+ const markdownResult = await tree .generate (' /path/to/project' , { format: ' markdown' })
389+ console .log (' Markdown output length:' , markdownResult .length )
271390```
272391
273392## Contributing
0 commit comments