@@ -24,6 +24,9 @@ afterAll(() => {
2424} ) ;
2525
2626const modules = processComponents ( getProject ( ) ) ;
27+ const moduleByMethod = new Map (
28+ modules . flatMap ( ( m ) => m . methods . map ( ( method ) => [ method . name , m . camelTitle ] ) )
29+ ) ;
2730
2831function resolveDirToModule ( moduleName : string ) : string {
2932 return resolve ( tempDir , moduleName ) ;
@@ -38,6 +41,13 @@ function resolvePathToMethodFile(
3841 return resolve ( dir , `${ methodName } _${ signature } .ts` ) ;
3942}
4043
44+ function toKebabCase ( str : string ) : string {
45+ return str
46+ . replaceAll ( / ( [ a - z ] ) ( [ A - Z ] ) / g, '$1-$2' )
47+ . replaceAll ( / [ \s _ ] + / g, '-' )
48+ . toLowerCase ( ) ;
49+ }
50+
4151const allowedReferences = new Set (
4252 modules . flatMap ( ( { camelTitle, methods, category } ) => {
4353 return methods . map ( ( { name } ) =>
@@ -94,6 +104,10 @@ describe('verify JSDoc tags', () => {
94104 } ) ;
95105 } ) ;
96106
107+ const thisModuleByMethod = new Map (
108+ module . methods . map ( ( method ) => [ method . name , moduleName ] )
109+ ) ;
110+
97111 describe . each ( module . methods . map ( ( m ) => [ m . name , m ] ) ) (
98112 '%s' ,
99113 ( methodName , method ) => {
@@ -145,10 +159,41 @@ ${examples}`;
145159 ] ;
146160
147161 if ( imports . length > 0 ) {
148- examples = `import { ${ imports . join (
149- ', '
150- ) } } from '${ relativeImportPath } ';\n\n${ examples } `;
162+ examples = `// imports
163+ import { ${ imports . join ( ', ' ) } } from '${ relativeImportPath } ';
164+
165+ ${ examples } `;
166+ }
167+
168+ const functionImports = [
169+ ...new Set ( examples . match ( / \b ( \w + ) \( f a k e r C o r e / g) ) ,
170+ ]
171+ . map ( ( s ) => s . replace ( '(fakerCore' , '' ) )
172+ . map ( ( functionName ) => [
173+ functionName ,
174+ (
175+ thisModuleByMethod . get ( functionName ) ??
176+ moduleByMethod . get ( functionName ) ??
177+ '..'
178+ ) ?. replace (
179+ 'utils' ,
180+ moduleName === 'utils' ? '../utils' : 'utils'
181+ ) ,
182+ ] ) ;
183+
184+ if ( examples . includes ( 'fakerCore' ) ) {
185+ examples = `// fakerCore
186+ import { base, en } from '${ relativeImportPath } ';
187+ import { createFakerCore } from '${ relativeImportPath } /faker-core';
188+ const fakerCore = createFakerCore({ definitions: [en, base] });
189+
190+ ${ examples . replace ( "import { fakerCore } from '../../../../../src';" , '' ) } `;
151191 }
192+
193+ examples = `// functionImports
194+ ${ functionImports . map ( ( [ functionName , moduleName ] ) => `import { ${ functionName } } from '${ relativeImportPath } /modules/${ moduleName } /${ toKebabCase ( functionName ) } ';` ) . join ( '\n' ) }
195+
196+ ${ examples } `;
152197 }
153198
154199 writeFileSync ( path , examples ) ;
0 commit comments