Skip to content

Commit

Permalink
readdirRecursive locally
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanM04 committed Mar 27, 2021
1 parent c43a6be commit 105d720
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
"@types/flush-write-stream": "1.0.0",
"@types/from2": "2.3.0",
"@types/fs-extra": "9.0.6",
"@types/fs-readdir-recursive": "1.0.0",
"@types/gulp-if": "0.0.33",
"@types/htmlescape": "^1.1.1",
"@types/ink-spinner": "3.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"diff": "5.0.0",
"enquirer": "2.3.6",
"fs-extra": "^9.1.0",
"fs-readdir-recursive": "1.1.0",
"got": "^11.8.1",
"jscodeshift": "0.11.0",
"mem-fs": "1.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {log} from "@blitzjs/display"
import Enquirer from "enquirer"
import {EventEmitter} from "events"
import * as fs from "fs-extra"
import readDirRecursive from "fs-readdir-recursive"
import j from "jscodeshift"
import {Collection} from "jscodeshift/src/Collection"
import {create as createStore, Store} from "mem-fs"
Expand All @@ -15,6 +14,7 @@ import getBabelOptions, {Overrides} from "recast/parsers/_babel_options"
import * as babelParser from "recast/parsers/babel"
import {ConflictChecker} from "./conflict-checker"
import {pipe} from "./utils/pipe"
import {readdirRecursive} from "./utils/readdir-recursive"
const debug = require("debug")("blitz:generator")

export const customTsParser = {
Expand Down Expand Up @@ -229,7 +229,7 @@ export abstract class Generator<

async write(): Promise<void> {
debug("Generator.write...")
const paths = readDirRecursive(this.sourcePath(), (name) => {
const paths = await readdirRecursive(this.sourcePath(), (name) => {
const additionalFilesToIgnore = this.filesToIgnore()
return ![...alwaysIgnoreFiles, ...additionalFilesToIgnore].includes(name)
})
Expand Down
24 changes: 24 additions & 0 deletions packages/generator/src/utils/readdir-recursive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fs from "fs/promises"
import path from "path"

type Filter = (name: string, dir: string) => boolean

export async function readdirRecursive(root: string, filter?: Filter, dir = ""): Promise<string[]> {
const absoluteDir = path.resolve(root, dir)
const dirStats = await fs.stat(absoluteDir)

if (dirStats.isDirectory()) {
let entries = await fs.readdir(absoluteDir)

if (filter) {
entries = entries.filter((name) => filter(name, dir))
}

const recursiveList = await Promise.all(
entries.map((name) => readdirRecursive(root, filter, path.join(dir, name))),
)
return recursiveList.flat(Infinity) as string[]
} else {
return [dir]
}
}
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3908,11 +3908,6 @@
dependencies:
"@types/node" "*"

"@types/[email protected]":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/fs-readdir-recursive/-/fs-readdir-recursive-1.0.0.tgz#404f77bdadc6b90cccd3f04d15f6dd85cdde38ef"
integrity sha512-1w3aDEWvddRoBCPm3hdGehNovSvqwe30dxplDH5bjZXoMCDVbntkbNENxfyScS4kYsovJYcwLPxJ9gjN/hh2Xg==

"@types/glob-stream@*":
version "6.1.0"
resolved "https://registry.yarnpkg.com/@types/glob-stream/-/glob-stream-6.1.0.tgz#7ede8a33e59140534f8d8adfb8ac9edfb31897bc"
Expand Down Expand Up @@ -9548,11 +9543,6 @@ fs-mkdirp-stream@^1.0.0:
graceful-fs "^4.1.11"
through2 "^2.0.3"

[email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz#e32fc030a2ccee44a6b5371308da54be0b397d27"
integrity sha512-GNanXlVr2pf02+sPN40XN8HG+ePaNcvM0q5mZBd668Obwb0yD5GiUbZOFgwn8kGMY6I3mdyDJzieUy3PTYyTRA==

fs-write-stream-atomic@^1.0.8:
version "1.0.10"
resolved "https://registry.yarnpkg.com/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz#b47df53493ef911df75731e70a9ded0189db40c9"
Expand Down

0 comments on commit 105d720

Please sign in to comment.