bencoveney / barrelsby

Automatic TypeScript barrels (index.ts files) for your entire code base

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow exporting only specific exports

vjpr opened this issue · comments

I would like to include only a few exports in my barrelsby file that match a regex.

Does barrelsby parse the source code at present?

Use case: I want to export my GraphQL resolvers. Sometimes I export multiple classes from the file.

E.g. I want ChromeResolver and not WindowDTO because I want to create a barrel file called resolvers.ts and then pass it directly to Apollo.

This ensures all resolvers in my directory are included in my Apollo Server. The alternative is relying on directory scanning but this doesn't allow typesafety.

chrome.resolver.ts

@ObjectType()
export class WindowDto {
  @Field(type => GraphQLJSONObject, {nullable: true} as any)
  window: any
  @Field(type => [TabDto], {nullable: true} as any)
  tabs: TabDto
}

@Service()
@Resolver()
export class ChromeResolver {

  constructor(private readonly service: ChromeService) {
  }

  @Query(returns => [WindowDto])
  async allWindows() {
    let windows = await this.service.getAllWindows()
    console.log({windows})
    windows = windows.map(win => {
      let {tabs, ...window} = win
      tabs = tabs?.map(tab => ({data: tab}))
      return {window, tabs}
    })
    return windows
  }

}

index.ts

export {ChromeResolver} from `chrome.resolver.ts`
barrelsby --include-export='.*Resolver' --include='.*resolver.ts'

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator