11import { Field } from 'contentful' ;
2- import * as path from 'path' ;
2+ import * as path from 'node: path' ;
33import {
44 forEachStructureChild ,
55 ImportDeclarationStructure ,
@@ -52,7 +52,7 @@ export default class CFDefinitionsBuilder {
5252
5353 const interfaceDeclaration = this . createInterfaceDeclaration ( file , moduleFieldsName ( model . sys . id ) ) ;
5454
55- model . fields . forEach ( field => this . addProperty ( file , interfaceDeclaration , field ) ) ;
55+ for ( const field of model . fields ) this . addProperty ( file , interfaceDeclaration , field ) ;
5656
5757 this . addEntryTypeAlias ( file , model . sys . id , moduleFieldsName ( model . sys . id ) ) ;
5858
@@ -81,34 +81,33 @@ export default class CFDefinitionsBuilder {
8181 const imports : OptionalKind < ImportDeclarationStructure > [ ] = [ ] ;
8282 const types : string [ ] = [ ] ;
8383
84- this . project . getSourceFiles ( )
85- . filter ( sourceFile => sourceFile . getBaseNameWithoutExtension ( ) !== mergeFileName )
86- . forEach ( sourceFile => forEachStructureChild ( sourceFile . getStructure ( ) ,
87- childStructure => {
88- switch ( childStructure . kind ) {
89- case StructureKind . ImportDeclaration :
90- imports . push ( childStructure ) ;
91- break ;
92- case StructureKind . Interface :
93- types . push ( childStructure . name ) ;
94- mergeFile . addInterface ( childStructure ) ;
95- break ;
96- case StructureKind . TypeAlias :
97- types . push ( childStructure . name ) ;
98- mergeFile . addTypeAlias ( childStructure ) ;
99- break ;
100- default :
101- throw new Error ( `Unhandled node type '${ StructureKind [ childStructure . kind ] } '.` ) ;
102- }
103- } ) ) ;
84+ for ( const sourceFile of this . project . getSourceFiles ( )
85+ . filter ( sourceFile => sourceFile . getBaseNameWithoutExtension ( ) !== mergeFileName ) ) forEachStructureChild ( sourceFile . getStructure ( ) ,
86+ childStructure => {
87+ switch ( childStructure . kind ) {
88+ case StructureKind . ImportDeclaration :
89+ imports . push ( childStructure ) ;
90+ break ;
91+ case StructureKind . Interface :
92+ types . push ( childStructure . name ) ;
93+ mergeFile . addInterface ( childStructure ) ;
94+ break ;
95+ case StructureKind . TypeAlias :
96+ types . push ( childStructure . name ) ;
97+ mergeFile . addTypeAlias ( childStructure ) ;
98+ break ;
99+ default :
100+ throw new Error ( `Unhandled node type '${ StructureKind [ childStructure . kind ] } '.` ) ;
101+ }
102+ } ) ;
104103
105104 // only import modules not present in merge file
106- imports . forEach ( importD => {
105+ for ( const importD of imports ) {
107106 const name = importD . moduleSpecifier . slice ( 2 ) ;
108107 if ( ! types . includes ( name ) ) {
109108 mergeFile . addImportDeclaration ( importD ) ;
110109 }
111- } ) ;
110+ }
112111
113112 mergeFile . organizeImports ( {
114113 ensureNewLineAtEndOfFile : true ,
@@ -154,7 +153,7 @@ export default class CFDefinitionsBuilder {
154153 namedImports : [ 'CMSManagementEntry' ] ,
155154 } ) ;
156155
157- files . forEach ( fileName => {
156+ for ( const fileName of files ) {
158157 indexFile . addImportDeclaration ( {
159158 isTypeOnly : true ,
160159 namedImports : [ moduleName ( fileName ) , moduleFieldsName ( fileName ) ] ,
@@ -169,7 +168,7 @@ export default class CFDefinitionsBuilder {
169168 moduleSpecifier : `./${ fileName } ` ,
170169 } ) ;
171170 cmsEntries . push ( moduleName ( fileName ) ) ;
172- } ) ;
171+ }
173172
174173 indexFile . addTypeAlias ( { isExported : true , name : 'CMSEntries' , type : renderUnionType ( cmsEntries ) } ) ;
175174 indexFile . addTypeAlias ( { isExported : true , name : 'CMSManagementEntries' , type : renderUnionType ( cmsEntries . map ( name => renderGenericType ( 'CMSManagementEntry' , name ) ) ) } ) ;
0 commit comments