@@ -25,6 +25,7 @@ import type {
2525} from "@mustache/types" ;
2626import type { TypeSchemaIndex } from "@root/typeschema/utils" ;
2727import type { CodegenLogger } from "@root/utils/codegen-logger" ;
28+ import { type Identifier , isComplexTypeIdentifier , isResourceIdentifier , type TypeSchema } from "@typeschema/types" ;
2829import { default as Mustache } from "mustache" ;
2930import { FileSystemWriter , type FileSystemWriterOptions } from "./writer" ;
3031
@@ -125,6 +126,27 @@ function runCommand(cmd: string, args: string[] = [], options = {}) {
125126 } ) ;
126127}
127128
129+ const checkFilter = ( type : Identifier , filters : MustacheFilter ) : boolean => {
130+ if ( type . kind !== "complex-type" && type . kind !== "resource" ) {
131+ return true ;
132+ }
133+ if ( ! filters [ type . kind as "resource" | "complexType" ] ) {
134+ return true ;
135+ }
136+ const whitelist = filters [ type . kind as "resource" | "complexType" ] ?. whitelist ?? [ ] ;
137+ const blacklist = filters [ type . kind as "resource" | "complexType" ] ?. blacklist ?? [ ] ;
138+ if ( ! whitelist . length && ! blacklist . length ) {
139+ return true ;
140+ }
141+ if ( blacklist . find ( ( pattern : any ) => type . name . match ( pattern as any ) ) ) {
142+ return false ;
143+ }
144+ if ( whitelist . find ( ( pattern : any ) => type . name . match ( pattern as any ) ) ) {
145+ return true ;
146+ }
147+ return whitelist . length === 0 ;
148+ } ;
149+
128150export class MustacheGenerator extends FileSystemWriter < MustacheGeneratorOptions > {
129151 private readonly templateFileCache : TemplateFileCache ;
130152 private readonly nameGenerator : NameGenerator ;
@@ -151,13 +173,19 @@ export class MustacheGenerator extends FileSystemWriter<MustacheGeneratorOptions
151173 resourcesByUri : { } ,
152174 complexTypesByUri : { } ,
153175 } ;
154- schemaLoaderFacade
155- . getComplexTypes ( )
176+ tsIndex
177+ . collectComplexTypes ( )
178+ . map ( ( i ) => i . identifier )
179+ . filter ( ( i ) => checkFilter ( i , this . opts . filters ) )
180+ . sort ( ( a , b ) => a . url . localeCompare ( b . url ) )
156181 . map ( ( typeRef ) => modelFactory . createComplexType ( typeRef , cache ) )
157182 . forEach ( this . _renderComplexType . bind ( this ) ) ;
158183
159- schemaLoaderFacade
160- . getResources ( )
184+ tsIndex
185+ . collectResources ( )
186+ . map ( ( i ) => i . identifier )
187+ . filter ( ( i ) => checkFilter ( i , this . opts . filters ) )
188+ . sort ( ( a , b ) => a . url . localeCompare ( b . url ) )
161189 . map ( ( typeRef ) => modelFactory . createResource ( typeRef , cache ) )
162190 . forEach ( this . _renderResource . bind ( this ) ) ;
163191
0 commit comments