Skip to content

Commit 5a6f12d

Browse files
committed
➕ | Add support for showing hidden files
1 parent 7002407 commit 5a6f12d

File tree

6 files changed

+36
-57
lines changed

6 files changed

+36
-57
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<img src="media/SocialPreview.png" alt="File Tree Extractor Logo" width="640" />
2+
<img src="media/FileTreeLogo.png" alt="File Tree Extractor Logo" width="90" />
33
</p>
44

55
---
@@ -271,7 +271,7 @@ The format of the output tree structure.
271271

272272
</br>
273273

274-
### `fileTreeExtractor.directoryOnly`
274+
### `fileTreeExtractor.directoryOnly` 🆕
275275

276276
**Description:**
277277
Show only directories in the tree structure, excluding all files from the output.
@@ -294,6 +294,18 @@ menuy/
294294

295295
</br>
296296

297+
### `fileTreeExtractor.showHiddenFiles` 🆕
298+
299+
**Description:**
300+
Show hidden files in the tree output.
301+
302+
**Default Value:**
303+
`true`
304+
305+
> Notice: The option only works for Linux and Mac OS.
306+
307+
</br>
308+
297309
## Commands
298310

299311
- `File Tree Extractor: Copy File Tree`

media/FileTreeLogo.svg

Lines changed: 0 additions & 52 deletions
This file was deleted.

media/SocialPreview.png

-31.2 KB
Binary file not shown.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@
9393
"default": false,
9494
"description": "Include file sizes in the generated tree."
9595
},
96+
"fileTreeExtractor.showHiddenFiles": {
97+
"type": "boolean",
98+
"default": true,
99+
"description": "Show hidden files (files starting with a dot) in the tree output."
100+
},
96101
"fileTreeExtractor.maxDepth": {
97102
"type": "number",
98103
"default": -1,

src/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ConfigurationManager {
1515
ignoredBy: 'ignoredItems',
1616
indent: 1,
1717
showFileSize: false,
18+
showHiddenFiles: true,
1819
maxDepth: -1,
1920
outputFormat: 'ascii',
2021
directoryOnly: false
@@ -40,6 +41,10 @@ class ConfigurationManager {
4041
errors.push('"showFileSize" must be a boolean')
4142
}
4243

44+
if (typeof config.showHiddenFiles !== 'boolean') {
45+
errors.push('"showHiddenFiles" must be a boolean value')
46+
}
47+
4348
if (typeof config.maxDepth !== 'number' || config.maxDepth < -1) {
4449
errors.push('"maxDepth" must be -1 or a positive number')
4550
}

src/extract.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function generateFileTree(startPath) {
2424
if (configErrors.length > 0) {
2525
throw new ConfigurationError(configErrors)
2626
}
27-
27+
2828
// Validate start path
2929
try {
3030
await fs.access(startPath, fs.constants.R_OK)
@@ -36,15 +36,15 @@ async function generateFileTree(startPath) {
3636
}
3737
throw error
3838
}
39-
39+
4040
const depth = 0
4141
const tree = await buildTree(startPath, startPath, buildConfig, depth)
4242
return formatOutput(tree, buildConfig, depth)
4343
} catch (error) {
4444
if (error instanceof TreeExtractorError) {
4545
throw error
4646
}
47-
47+
4848
throw new TreeExtractorError(
4949
'An unexpected error occurred while generating the file tree',
5050
'UNKNOWN_ERROR',
@@ -64,6 +64,10 @@ async function buildTree(itemPath, startPath, buildConfig, depth) {
6464
return null
6565
}
6666

67+
if (!buildConfig.showHiddenFiles && isHiddenFile(itemPath)) {
68+
return null
69+
}
70+
6771
if (shouldIgnore(itemPath, startPath, buildConfig.ignoredBy, buildConfig.ignoredItems)) {
6872
return null
6973
}
@@ -196,6 +200,11 @@ function transformTreeForXml(node) {
196200
return transformed
197201
}
198202

203+
function isHiddenFile(filePath) {
204+
const basename = path.basename(filePath)
205+
return basename.startsWith('.')
206+
}
207+
199208
module.exports = {
200209
generateFileTree
201210
}

0 commit comments

Comments
 (0)