Skip to content

Commit

Permalink
feat: add exclude input.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 28, 2024
1 parent 51650d4 commit 818b201
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ jobs:
with:
path: ./src

- name: Output src/ folder tree
# uses: jaywcjlove/github-action-folder-tree@main
uses: ./
with:
exclude: "node_modules|dist"

- name: Create idoc config
run: |
cat > idoc.yml << EOF
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Print folder tree
Print Folder Tree
===

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

## Outputs

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
description: 'Folder path'
default: ''
required: false
exclude:
description: 'Pass a regex string to exclude directories from printing'
default: ''
required: false
depth:
description: 'Scan the maximum depth reachable for the given path'
default: 5
Expand Down
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { context } from '@actions/github';
import { getInput, setOutput, startGroup, info, endGroup } from '@actions/core';
import * as dree from 'dree';
import { parse, ParseOptions } from 'dree';

function convertToNumber(str: string): number {
const num = +str;
Expand All @@ -9,9 +9,17 @@ function convertToNumber(str: string): number {

;(async () => {
const folderPath = getInput('path') || ".";
const exclude = getInput('exclude');
const depth: number = convertToNumber(getInput('depth') || "5");
const {owner, repo} = context.repo
const dreeResult = dree.parse(folderPath, { depth });

const dtreeOptions: ParseOptions = { depth };

if (exclude) {
dtreeOptions.exclude = new RegExp(exclude);
}

const dreeResult = parse(folderPath, dtreeOptions);

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

0 comments on commit 818b201

Please sign in to comment.