@@ -107,8 +107,8 @@ function getImportPath(to: Protobuf.Type | Protobuf.Enum | Protobuf.Service): st
107
107
return stripLeadingPeriod ( to . fullName ) . replace ( / \. / g, '/' ) ;
108
108
}
109
109
110
- function getPath ( to : Protobuf . Type | Protobuf . Enum | Protobuf . Service , extension : string = '.ts' ) {
111
- return stripLeadingPeriod ( to . fullName ) . replace ( / \. / g, '/' ) + extension ;
110
+ function getPath ( to : Protobuf . Type | Protobuf . Enum | Protobuf . Service , options : GeneratorOptions ) {
111
+ return stripLeadingPeriod ( to . fullName ) . replace ( / \. / g, '/' ) + options . targetFileExtension ;
112
112
}
113
113
114
114
function getPathToRoot ( from : Protobuf . NamespaceBase ) {
@@ -155,7 +155,7 @@ function getImportLine(dependency: Protobuf.Type | Protobuf.Enum | Protobuf.Serv
155
155
throw new Error ( 'Invalid object passed to getImportLine' ) ;
156
156
}
157
157
}
158
- return `import type { ${ importedTypes } } from '${ filePath } ${ options . importFileExtension ?? '' } ';`
158
+ return `import type { ${ importedTypes } } from '${ filePath } ${ options . importFileExtension } ';`
159
159
}
160
160
161
161
function getChildMessagesAndEnums ( namespace : Protobuf . NamespaceBase ) : ( Protobuf . Type | Protobuf . Enum ) [ ] {
@@ -789,21 +789,21 @@ function generateFilesForNamespace(namespace: Protobuf.NamespaceBase, options: G
789
789
if ( nested instanceof Protobuf . Type ) {
790
790
generateMessageInterfaces ( fileFormatter , nested , options ) ;
791
791
if ( options . verbose ) {
792
- console . log ( `Writing ${ options . outDir } /${ getPath ( nested , options . targetFileExtension ) } from file ${ nested . filename } ` ) ;
792
+ console . log ( `Writing ${ options . outDir } /${ getPath ( nested , options ) } from file ${ nested . filename } ` ) ;
793
793
}
794
- filePromises . push ( writeFile ( `${ options . outDir } /${ getPath ( nested , options . targetFileExtension ) } ` , fileFormatter . getFullText ( ) ) ) ;
794
+ filePromises . push ( writeFile ( `${ options . outDir } /${ getPath ( nested , options ) } ` , fileFormatter . getFullText ( ) ) ) ;
795
795
} else if ( nested instanceof Protobuf . Enum ) {
796
796
generateEnumInterface ( fileFormatter , nested , options ) ;
797
797
if ( options . verbose ) {
798
- console . log ( `Writing ${ options . outDir } /${ getPath ( nested , options . targetFileExtension ) } from file ${ nested . filename } ` ) ;
798
+ console . log ( `Writing ${ options . outDir } /${ getPath ( nested , options ) } from file ${ nested . filename } ` ) ;
799
799
}
800
- filePromises . push ( writeFile ( `${ options . outDir } /${ getPath ( nested , options . targetFileExtension ) } ` , fileFormatter . getFullText ( ) ) ) ;
800
+ filePromises . push ( writeFile ( `${ options . outDir } /${ getPath ( nested , options ) } ` , fileFormatter . getFullText ( ) ) ) ;
801
801
} else if ( nested instanceof Protobuf . Service ) {
802
802
generateServiceInterfaces ( fileFormatter , nested , options ) ;
803
803
if ( options . verbose ) {
804
- console . log ( `Writing ${ options . outDir } /${ getPath ( nested , options . targetFileExtension ) } from file ${ nested . filename } ` ) ;
804
+ console . log ( `Writing ${ options . outDir } /${ getPath ( nested , options ) } from file ${ nested . filename } ` ) ;
805
805
}
806
- filePromises . push ( writeFile ( `${ options . outDir } /${ getPath ( nested , options . targetFileExtension ) } ` , fileFormatter . getFullText ( ) ) ) ;
806
+ filePromises . push ( writeFile ( `${ options . outDir } /${ getPath ( nested , options ) } ` , fileFormatter . getFullText ( ) ) ) ;
807
807
} else if ( isNamespaceBase ( nested ) ) {
808
808
filePromises . push ( ...generateFilesForNamespace ( nested , options ) ) ;
809
809
}
@@ -880,7 +880,7 @@ async function runScript() {
880
880
. option ( 'inputBranded' , boolDefaultFalseOption )
881
881
. option ( 'outputBranded' , boolDefaultFalseOption )
882
882
. option ( 'targetFileExtension' , { string : true , default : '.ts' } )
883
- . option ( 'importFileExtension' , { string : true } )
883
+ . option ( 'importFileExtension' , { string : true , default : '' } )
884
884
. coerce ( 'longs' , value => {
885
885
switch ( value ) {
886
886
case 'String' : return String ;
0 commit comments