@@ -32,6 +32,9 @@ export abstract class GeneratorBase {
3232 private outputStream ?: NodeJS . WritableStream ;
3333
3434 constructor ( ) {
35+ // The default YAML schema will represent BsonDate using the Date representation because
36+ // it's a subclass of Date. We find the implicit type for Date and modify it to use predicate
37+ // instead of instanceOf, so it will only match Date instances that are not BsonDate.
3538 if ( 'implicit' in yaml . DEFAULT_SCHEMA ) {
3639 const implicit = yaml . DEFAULT_SCHEMA . implicit as yaml . Type [ ] ;
3740 const timestamp = implicit . find ( ( type ) => type . instanceOf === Date ) ;
@@ -178,14 +181,16 @@ export abstract class GeneratorBase {
178181 'config' ,
179182 ) ;
180183
181- private async * listCategories ( ) : AsyncIterable < {
184+ private async * listCategories (
185+ filterRegex : RegExp | undefined ,
186+ ) : AsyncIterable < {
182187 category : string ;
183188 folder : string ;
184189 } > {
185190 for await ( const folder of await fs . readdir ( this . configDir , {
186191 withFileTypes : true ,
187192 } ) ) {
188- if ( folder . isDirectory ( ) ) {
193+ if ( folder . isDirectory ( ) && filterRegex ?. test ( folder . name ) !== false ) {
189194 yield {
190195 category : folder . name ,
191196 folder : path . join ( folder . parentPath , folder . name ) ,
@@ -194,18 +199,27 @@ export abstract class GeneratorBase {
194199 }
195200 }
196201
197- private async * listSourceYAMLFiles ( ) : AsyncIterable < {
202+ private async * listSourceYAMLFiles (
203+ categoryRegex : RegExp | undefined ,
204+ operatorRegex : RegExp | undefined ,
205+ ) : AsyncIterable < {
198206 category : string ;
199207 operators : ( ) => AsyncIterable < { yaml : unknown ; path : string } > ;
200208 } > {
201- for await ( const { category, folder } of this . listCategories ( ) ) {
209+ for await ( const { category, folder } of this . listCategories (
210+ categoryRegex ,
211+ ) ) {
202212 yield {
203213 category,
204214 operators : async function * ( ) {
205215 for await ( const file of await fs . readdir ( folder , {
206216 withFileTypes : true ,
207217 } ) ) {
208- if ( file . isFile ( ) && file . name . endsWith ( '.yaml' ) ) {
218+ if (
219+ file . isFile ( ) &&
220+ file . name . endsWith ( '.yaml' ) &&
221+ operatorRegex ?. test ( file . name ) !== false
222+ ) {
209223 const filePath = path . join ( file . parentPath , file . name ) ;
210224 const content = await fs . readFile ( filePath , 'utf8' ) ;
211225 const parsed = yaml . load ( content , GeneratorBase . loadOptions ) ;
@@ -261,8 +275,18 @@ export abstract class GeneratorBase {
261275
262276 protected abstract generateImpl ( iterable : YamlFiles ) : Promise < void > ;
263277
264- public generate ( ) : Promise < void > {
265- const files = this . listSourceYAMLFiles ( ) ;
278+ public generate (
279+ categoryFilter ?: string ,
280+ operatorFilter ?: string ,
281+ ) : Promise < void > {
282+ const categoryRegex = categoryFilter
283+ ? new RegExp ( categoryFilter )
284+ : undefined ;
285+ const operatorRegex = operatorFilter
286+ ? new RegExp ( operatorFilter )
287+ : undefined ;
288+
289+ const files = this . listSourceYAMLFiles ( categoryRegex , operatorRegex ) ;
266290 return this . generateImpl ( files ) ;
267291 }
268292}
0 commit comments