Skip to content

Commit 818b201

Browse files
committed
feat: add exclude input.
1 parent 51650d4 commit 818b201

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ jobs:
2323
with:
2424
path: ./src
2525

26+
- name: Output src/ folder tree
27+
# uses: jaywcjlove/github-action-folder-tree@main
28+
uses: ./
29+
with:
30+
exclude: "node_modules|dist"
31+
2632
- name: Create idoc config
2733
run: |
2834
cat > idoc.yml << EOF

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Print folder tree
1+
Print Folder Tree
22
===
33

44
[![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor)
@@ -20,6 +20,7 @@ View the folder directory tree structure, similar to the output of the `tree` co
2020
2121
- `path` Folder path. (default `./`)
2222
- `depth` Scan the maximum depth reachable for the given path (default `5`)
23+
- `exclude` Pass a regex string to exclude directories from printing
2324

2425
## Outputs
2526

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ inputs:
1010
description: 'Folder path'
1111
default: ''
1212
required: false
13+
exclude:
14+
description: 'Pass a regex string to exclude directories from printing'
15+
default: ''
16+
required: false
1317
depth:
1418
description: 'Scan the maximum depth reachable for the given path'
1519
default: 5

src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { context } from '@actions/github';
22
import { getInput, setOutput, startGroup, info, endGroup } from '@actions/core';
3-
import * as dree from 'dree';
3+
import { parse, ParseOptions } from 'dree';
44

55
function convertToNumber(str: string): number {
66
const num = +str;
@@ -9,9 +9,17 @@ function convertToNumber(str: string): number {
99

1010
;(async () => {
1111
const folderPath = getInput('path') || ".";
12+
const exclude = getInput('exclude');
1213
const depth: number = convertToNumber(getInput('depth') || "5");
1314
const {owner, repo} = context.repo
14-
const dreeResult = dree.parse(folderPath, { depth });
15+
16+
const dtreeOptions: ParseOptions = { depth };
17+
18+
if (exclude) {
19+
dtreeOptions.exclude = new RegExp(exclude);
20+
}
21+
22+
const dreeResult = parse(folderPath, dtreeOptions);
1523

1624
startGroup(`\x1b[32;1m ${owner}/${repo} \x1b[0m tree: `);
1725
info(`${dreeResult}`);

0 commit comments

Comments
 (0)