Skip to content

Commit 5d104af

Browse files
at-ishikawastanley-cheung
authored andcommitted
Support sub directories for generated typescript files (#360)
1 parent 81c07aa commit 5d104af

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

javascript/net/grpc/web/grpc_generator.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ string GetRootPath(const string& from_filename, const string& to_filename) {
235235
return result;
236236
}
237237

238+
// Returns the basename of a file.
239+
string GetBasename(string filename) {
240+
size_t last_slash = filename.find_last_of('/');
241+
if (last_slash != string::npos) {
242+
return filename.substr(last_slash + 1);
243+
}
244+
return filename;
245+
}
246+
238247
// Returns the alias we assign to the module of the given .proto filename
239248
// when importing.
240249
string ModuleAlias(const string& filename) {
@@ -319,12 +328,7 @@ void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) {
319328
}
320329

321330
// need to import the messages from our own file
322-
string filename = StripProto(file->name());
323-
size_t last_slash = filename.find_last_of('/');
324-
if (last_slash != string::npos) {
325-
filename = filename.substr(last_slash + 1);
326-
}
327-
vars["filename"] = filename;
331+
vars["filename"] = GetBasename(StripProto(file->name()));
328332

329333
if (!package.empty()) {
330334
printer->Print(
@@ -340,7 +344,7 @@ void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) {
340344
void PrintES6Imports(Printer* printer, const FileDescriptor* file) {
341345
std::map<string, string> vars;
342346
std::map<string, const Descriptor*> messages = GetAllMessages(file);
343-
vars["base_name"] = StripProto(file->name());
347+
vars["base_name"] = GetBasename(StripProto(file->name()));
344348
printer->Print("import * as grpcWeb from 'grpc-web';\n");
345349
printer->Print("import {\n");
346350
printer->Indent();

0 commit comments

Comments
 (0)