-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unused imported types for generated typescript. #18
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,9 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service) | |
string serverFileName = Uncapitalize(moduleName) + "Server" + (TypeScript ? ".ts" : ".js"); | ||
|
||
var namedTexts = new List<CodeGenFile>(); | ||
var typeNames = new List<string>(); | ||
var requestTypeNames = new List<string>(); | ||
var responseTypeNames = new List<string>(); | ||
var dtoTypeNames = new List<string>(); | ||
if (TypeScript) | ||
{ | ||
namedTexts.Add(CreateFile(typesFileName, code => | ||
|
@@ -61,7 +63,7 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service) | |
|
||
code.WriteLine(); | ||
WriteJsDoc(code, service); | ||
typeNames.Add($"I{capModuleName}"); | ||
requestTypeNames.Add($"I{capModuleName}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't technically a request type, but wherever I needed the request types I also needed this so I included it here. |
||
using (code.Block($"export interface I{capModuleName} {{", "}")) | ||
{ | ||
foreach (var httpMethodInfo in httpServiceInfo.Methods) | ||
|
@@ -77,14 +79,14 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service) | |
foreach (var methodInfo in service.Methods) | ||
{ | ||
var requestDtoName = $"{CodeGenUtility.Capitalize(methodInfo.Name)}Request"; | ||
typeNames.Add($"I{requestDtoName}"); | ||
requestTypeNames.Add($"I{requestDtoName}"); | ||
WriteDto(code, new ServiceDtoInfo( | ||
name: requestDtoName, | ||
fields: methodInfo.RequestFields, | ||
summary: $"Request for {CodeGenUtility.Capitalize(methodInfo.Name)}."), service); | ||
|
||
var responseDtoName = $"{CodeGenUtility.Capitalize(methodInfo.Name)}Response"; | ||
typeNames.Add($"I{responseDtoName}"); | ||
responseTypeNames.Add($"I{responseDtoName}"); | ||
WriteDto(code, new ServiceDtoInfo( | ||
name: responseDtoName, | ||
fields: methodInfo.ResponseFields, | ||
|
@@ -93,7 +95,7 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service) | |
|
||
foreach (var dtoInfo in service.Dtos) | ||
{ | ||
typeNames.Add($"I{dtoInfo.Name}"); | ||
dtoTypeNames.Add($"I{dtoInfo.Name}"); | ||
WriteDto(code, dtoInfo, service); | ||
} | ||
code.WriteLine(); | ||
|
@@ -119,7 +121,7 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service) | |
|
||
if (TypeScript) | ||
{ | ||
WriteImports(code, typeNames, $"./{Uncapitalize(moduleName)}Types"); | ||
WriteImports(code, requestTypeNames.Concat(responseTypeNames).ToList(), $"./{Uncapitalize(moduleName)}Types"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming the order in which we import things is arbitrary, and we don't care that all the requests are imported first and then response, as opposed to what it was previously There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should sort them. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sorted them alphabetically which maybe is better. Though maybe even better would be to sort them by where they would be used in the file. Which would probably more closely correspond to where they are specified in the fsd file is my guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could do something like this and replace all this code
though I'd actually have to use a regular expression instead of |
||
code.WriteLine($"export * from './{Uncapitalize(moduleName)}Types';"); | ||
} | ||
|
||
|
@@ -314,13 +316,9 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service) | |
code.WriteLine(); | ||
code.WriteLine("import * as bodyParser from 'body-parser';"); | ||
code.WriteLine("import * as express from 'express';"); | ||
var facilityImports = new List<string>(); | ||
if (TypeScript) | ||
facilityImports.Add("IServiceResult"); | ||
WriteImports(code, facilityImports, "facility-core"); | ||
if (TypeScript) | ||
{ | ||
WriteImports(code, typeNames, $"./{Uncapitalize(moduleName)}Types"); | ||
WriteImports(code, requestTypeNames, $"./{Uncapitalize(moduleName)}Types"); | ||
code.WriteLine($"export * from './{Uncapitalize(moduleName)}Types';"); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I broke up the types and made this before I realized this wasn't actually being used anywhere.