Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support pattern strategy #482

Merged
merged 5 commits into from
Mar 4, 2024
Merged

Conversation

mdonnalley
Copy link
Contributor

  • Support schema generation when oclif.commands is a pattern-strategy object instead of a string
  • Disallow schema generation when CLI is a single command CLI or uses explicit command strategy

Depends on oclif/core#945

@W-15005785@

Copy link
Member

@mshanemc mshanemc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor perf comment...probably doesn't matter in a dev plugin like this.

src/util.ts Outdated
export function getAllFiles(dirPath: string, ext: string, allFiles: string[] = []): string[] {
let files: string[] = []
try {
files = fs.readdirSync(dirPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readdirSync has the withFileTypes option so you don't have to statSync them all to do isDir.

Can you also make a comment so that when we get everything to node20, we can just use the recursive option (it was backported to 18.17)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export const getAllFiles = (dirPath: string, ext: string, allFiles: string[] = []): string[] =>
  safeReadDirSync(dirPath)
    .flatMap((f) =>
      f.isDirectory() ? getAllFiles(path.join(dirPath, f.name), ext, allFiles) : path.join(dirPath, f.name),
    )
    .filter((f) => f.endsWith(ext))

const safeReadDirSync = (dirPath: string): fs.Dirent[] => {
  try {
    return fs.readdirSync(dirPath, {withFileTypes: true})
  } catch {
    return []
  }
}

@mdonnalley mdonnalley merged commit 687e764 into main Mar 4, 2024
8 checks passed
@mdonnalley mdonnalley deleted the mdonnalley/support-strategies branch March 4, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants