Skip to content

Commit c5b96a9

Browse files
committed
refactor(proto-loader-gen-types): refactor for more consistent code style
1 parent b43225d commit c5b96a9

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

packages/proto-loader/bin/proto-loader-gen-types.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ function getImportPath(to: Protobuf.Type | Protobuf.Enum | Protobuf.Service): st
107107
return stripLeadingPeriod(to.fullName).replace(/\./g, '/');
108108
}
109109

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;
112112
}
113113

114114
function getPathToRoot(from: Protobuf.NamespaceBase) {
@@ -155,7 +155,7 @@ function getImportLine(dependency: Protobuf.Type | Protobuf.Enum | Protobuf.Serv
155155
throw new Error('Invalid object passed to getImportLine');
156156
}
157157
}
158-
return `import type { ${importedTypes} } from '${filePath}${options.importFileExtension ?? ''}';`
158+
return `import type { ${importedTypes} } from '${filePath}${options.importFileExtension}';`
159159
}
160160

161161
function getChildMessagesAndEnums(namespace: Protobuf.NamespaceBase): (Protobuf.Type | Protobuf.Enum)[] {
@@ -789,21 +789,21 @@ function generateFilesForNamespace(namespace: Protobuf.NamespaceBase, options: G
789789
if (nested instanceof Protobuf.Type) {
790790
generateMessageInterfaces(fileFormatter, nested, options);
791791
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}`);
793793
}
794-
filePromises.push(writeFile(`${options.outDir}/${getPath(nested, options.targetFileExtension)}`, fileFormatter.getFullText()));
794+
filePromises.push(writeFile(`${options.outDir}/${getPath(nested, options)}`, fileFormatter.getFullText()));
795795
} else if (nested instanceof Protobuf.Enum) {
796796
generateEnumInterface(fileFormatter, nested, options);
797797
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}`);
799799
}
800-
filePromises.push(writeFile(`${options.outDir}/${getPath(nested, options.targetFileExtension)}`, fileFormatter.getFullText()));
800+
filePromises.push(writeFile(`${options.outDir}/${getPath(nested, options)}`, fileFormatter.getFullText()));
801801
} else if (nested instanceof Protobuf.Service) {
802802
generateServiceInterfaces(fileFormatter, nested, options);
803803
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}`);
805805
}
806-
filePromises.push(writeFile(`${options.outDir}/${getPath(nested, options.targetFileExtension)}`, fileFormatter.getFullText()));
806+
filePromises.push(writeFile(`${options.outDir}/${getPath(nested, options)}`, fileFormatter.getFullText()));
807807
} else if (isNamespaceBase(nested)) {
808808
filePromises.push(...generateFilesForNamespace(nested, options));
809809
}
@@ -880,7 +880,7 @@ async function runScript() {
880880
.option('inputBranded', boolDefaultFalseOption)
881881
.option('outputBranded', boolDefaultFalseOption)
882882
.option('targetFileExtension', { string: true, default: '.ts' })
883-
.option('importFileExtension', { string: true })
883+
.option('importFileExtension', { string: true, default: '' })
884884
.coerce('longs', value => {
885885
switch (value) {
886886
case 'String': return String;

0 commit comments

Comments
 (0)