From 818b20191c1b04a5eb25e9ee1aafd520a3cd5b23 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Sun, 28 Jul 2024 22:03:44 +0800 Subject: [PATCH] feat: add `exclude` input. --- .github/workflows/ci.yml | 6 ++++++ README.md | 3 ++- action.yml | 4 ++++ src/index.ts | 12 ++++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b10a3e8..ab48d33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/README.md b/README.md index 41e1221..b12e690 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/action.yml b/action.yml index 16848a7..7dd5e6c 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/src/index.ts b/src/index.ts index 68c6c79..791693e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; @@ -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}`);