├── .github └── workflows │ ├── deno.yml │ └── test.yml ├── .releaserc.json ├── LICENSE ├── README.md ├── _config.yml ├── mod.ts ├── mod_test.ts └── testfiles ├── file.txt └── to └── file.txt /.github/workflows/deno.yml: -------------------------------------------------------------------------------- 1 | name: Deno CI 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | build: 8 | name: ${{ matrix.kind }} ${{ matrix.os }} 9 | runs-on: ${{ matrix.os }} 10 | if: "!contains(github.event.head_commit.message, '[skip ci]')" 11 | strategy: 12 | matrix: 13 | os: [macOS-latest, ubuntu-latest, windows-latest] 14 | env: 15 | GH_ACTIONS: true 16 | DENO_BUILD_MODE: release 17 | V8_BINARY: true 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Setup Deno 21 | uses: denolib/setup-deno@master 22 | with: 23 | deno-version: 1.x 24 | - name: Tests 25 | run: deno test --allow-read 26 | release: 27 | name: Release 28 | runs-on: ubuntu-18.04 29 | if: "!contains(github.event.head_commit.message, '[skip ci]')" 30 | steps: 31 | - name: Checkout 32 | uses: actions/checkout@v2 33 | - name: Setup Node.js 34 | uses: actions/setup-node@v1 35 | with: 36 | node-version: 12.17.0 37 | - name: Setup package.json 38 | run: echo '{"name":"@denorg/recursive-readdir","version":"0.0.0","publishConfig":{"access":"public"},"scripts":{"semantic-release":"semantic-release"},"repository":{"type":"git","url":"https://github.com/denorg/recursive-readdir.git"},"author":"Denorg ","license":"MIT","bugs":{"url":"https://github.com/denorg/recursive-readdir/issues"},"homepage":"https://denorg.github.io/recursive-readdir/","devDependencies":{"semantic-release":"^17.0.4","semantic-release-gitmoji":"^1.3.3"}}' > package.json 39 | - name: Install dependencies 40 | run: npm install 41 | - name: Release 42 | run: npx semantic-release 43 | env: 44 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 45 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 46 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test CI 2 | on: 3 | push: 4 | branches-ignore: 5 | - "master" 6 | pull_request: 7 | branches-ignore: 8 | - "master" 9 | jobs: 10 | build: 11 | name: ${{ matrix.kind }} ${{ matrix.os }} 12 | runs-on: ${{ matrix.os }} 13 | if: "!contains(github.event.head_commit.message, '[skip ci]')" 14 | strategy: 15 | matrix: 16 | os: [macOS-latest, ubuntu-latest, windows-latest] 17 | env: 18 | GH_ACTIONS: true 19 | DENO_BUILD_MODE: release 20 | V8_BINARY: true 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Setup Deno 24 | uses: denolib/setup-deno@master 25 | with: 26 | deno-version: 1.x 27 | - name: Run tests 28 | run: deno test --allow-read 29 | -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "semantic-release-gitmoji", 5 | { 6 | "releaseRules": { 7 | "patch": { 8 | "include": [":bento:", ":recycle:"] 9 | } 10 | } 11 | } 12 | ], 13 | "@semantic-release/github", 14 | "@semantic-release/npm" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Anand Chowdhary 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 📁 Recursive Readdir 2 | 3 | Recursively read a directory in Deno. 4 | 5 | [![Deno CI](https://github.com/denorg/recursive-readdir/workflows/Deno%20CI/badge.svg)](https://github.com/denorg/recursive-readdir/actions) 6 | [![GitHub](https://img.shields.io/github/license/denorg/recursive-readdir)](https://github.com/denorg/recursive-readdir/blob/master/LICENSE) 7 | [![Contributors](https://img.shields.io/github/contributors/denorg/recursive-readdir)](https://github.com/denorg/recursive-readdir/graphs/contributors) 8 | [![Deno Starter](https://img.shields.io/badge/deno-starter-brightgreen)](https://denorg.github.io/starter/) 9 | [![Made by Denorg](https://img.shields.io/badge/made%20by-denorg-0082fb)](https://github.com/denorg) 10 | [![TypeScript](https://img.shields.io/badge/types-TypeScript-blue)](https://github.com/denorg/recursive-readdir) 11 | [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) 12 | 13 | ```ts 14 | import { recursiveReaddir } from "https://deno.land/x/recursive_readdir/mod.ts"; 15 | 16 | const files = await recursiveReaddir("path/to/dir"); // string[] 17 | ``` 18 | 19 | Required permissions: 20 | 21 | 1. `--allow-read` 22 | 23 | ## 💡 Recipes 24 | 25 | Search for all markdown files in the `content` folder: 26 | 27 | ```ts 28 | import { recursiveReaddir } from "https://deno.land/x/recursive_readdir/mod.ts"; 29 | import { join, extname } from "https://deno.land/std/path/mod.ts"; 30 | 31 | const markdownFiles = (await recursiveReaddir(join(".", "content"))).filter( 32 | (file: string) => extname(file) === ".md" 33 | ); 34 | ``` 35 | 36 | ## 👩‍💻 Development 37 | 38 | Run tests: 39 | 40 | ```bash 41 | deno test --allow-read 42 | ``` 43 | 44 | ## 📄 License 45 | 46 | MIT © [Denorg](https://den.org.in) 47 | 48 |

49 | 50 | 51 | 52 |

53 |

54 | A project by Denorg, the world's first Deno-focused community
organization and consulting company. Work with us →
55 |

56 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal 2 | -------------------------------------------------------------------------------- /mod.ts: -------------------------------------------------------------------------------- 1 | import { join } from "https://deno.land/std/path/mod.ts"; 2 | 3 | /** 4 | * Recursively read a directory 5 | */ 6 | export async function recursiveReaddir(path: string) { 7 | const files: string[] = []; 8 | const getFiles = async (path: string) => { 9 | for await (const dirEntry of Deno.readDir(path)) { 10 | if (dirEntry.isDirectory) { 11 | await getFiles(join(path, dirEntry.name)); 12 | } else if (dirEntry.isFile) { 13 | files.push(join(path, dirEntry.name)); 14 | } 15 | } 16 | }; 17 | await getFiles(path); 18 | return files; 19 | } 20 | -------------------------------------------------------------------------------- /mod_test.ts: -------------------------------------------------------------------------------- 1 | import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; 2 | import { recursiveReaddir } from "./mod.ts"; 3 | 4 | Deno.test("test starter function", async (): Promise => { 5 | const result = await recursiveReaddir("testfiles"); 6 | const correctResultUnix = ["testfiles/file.txt", "testfiles/to/file.txt"]; 7 | const correctResultWindows = [ 8 | "testfiles\\file.txt", 9 | "testfiles\\to\\file.txt", 10 | ]; 11 | try { 12 | assertEquals(result.sort(), correctResultUnix.sort()); 13 | } catch (error) { 14 | assertEquals(result.sort(), correctResultWindows.sort()); 15 | } 16 | }); 17 | -------------------------------------------------------------------------------- /testfiles/file.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denorg/recursive-readdir/3f3cd8ed446290071623ba94485c455bd49b6a87/testfiles/file.txt -------------------------------------------------------------------------------- /testfiles/to/file.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/denorg/recursive-readdir/3f3cd8ed446290071623ba94485c455bd49b6a87/testfiles/to/file.txt --------------------------------------------------------------------------------