@@ -50,7 +50,7 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service)
50
50
code . WriteLine ( $ "// DO NOT EDIT: generated by { GeneratorName } ") ;
51
51
52
52
code . WriteLine ( ) ;
53
- code . WriteLine ( "import { IServiceResult, IServiceError } from ' facility-core'; ") ;
53
+ WriteImports ( code , new [ ] { " IServiceResult" , " IServiceError" } , " facility-core") ;
54
54
55
55
code . WriteLine ( ) ;
56
56
WriteJsDoc ( code , service ) ;
@@ -93,7 +93,6 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service)
93
93
} ) ) ;
94
94
}
95
95
96
-
97
96
namedTexts . Add ( CreateFile ( clientFileName , code =>
98
97
{
99
98
code . WriteLine ( $ "// DO NOT EDIT: generated by { GeneratorName } ") ;
@@ -102,10 +101,14 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service)
102
101
code . WriteLine ( "'use strict';" ) ;
103
102
104
103
code . WriteLine ( ) ;
105
- code . WriteLine ( "import { HttpClientUtility" + IfTypeScript ( ", IServiceResult, IServiceError, IHttpClientOptions" ) + " } from 'facility-core';" ) ;
104
+ var facilityImports = new List < string > { "HttpClientUtility" } ;
105
+ if ( TypeScript )
106
+ facilityImports . AddRange ( new [ ] { "IServiceResult" , "IServiceError" , "IHttpClientOptions" } ) ;
107
+ WriteImports ( code , facilityImports , "facility-core" ) ;
108
+
106
109
if ( TypeScript )
107
110
{
108
- code . WriteLine ( $ "import {{ { string . Join ( ", " , typeNames ) } }} from ' ./{ Uncapitalize ( moduleName ) } Types'; ") ;
111
+ WriteImports ( code , typeNames , $ " ./{ Uncapitalize ( moduleName ) } Types") ;
109
112
code . WriteLine ( $ "export * from './{ Uncapitalize ( moduleName ) } Types';") ;
110
113
}
111
114
@@ -300,10 +303,13 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service)
300
303
code . WriteLine ( ) ;
301
304
code . WriteLine ( "import * as bodyParser from 'body-parser';" ) ;
302
305
code . WriteLine ( "import * as express from 'express';" ) ;
303
- code . WriteLine ( "import {" + IfTypeScript ( " IServiceResult, IServiceError" ) + " } from 'facility-core';" ) ;
306
+ var facilityImports = new List < string > ( ) ;
307
+ if ( TypeScript )
308
+ facilityImports . AddRange ( new [ ] { "IServiceResult" , "IServiceError" } ) ;
309
+ WriteImports ( code , facilityImports , "facility-core" ) ;
304
310
if ( TypeScript )
305
311
{
306
- code . WriteLine ( $ "import {{ { string . Join ( ", " , typeNames ) } }} from ' ./{ Uncapitalize ( moduleName ) } Types'; ") ;
312
+ WriteImports ( code , typeNames , $ " ./{ Uncapitalize ( moduleName ) } Types") ;
307
313
code . WriteLine ( $ "export * from './{ Uncapitalize ( moduleName ) } Types';") ;
308
314
}
309
315
@@ -608,6 +614,12 @@ private static void WriteJsDoc(CodeWriter code, IReadOnlyList<string> lines)
608
614
}
609
615
}
610
616
617
+ private static void WriteImports ( CodeWriter code , IReadOnlyList < string > imports , string from )
618
+ {
619
+ if ( imports . Count != 0 )
620
+ code . WriteLine ( $ "import {{ { string . Join ( ", " , imports ) } }} from '{ from } ';") ;
621
+ }
622
+
611
623
private static string Uncapitalize ( string value )
612
624
{
613
625
return value . Length == 0 ? "" : value . Substring ( 0 , 1 ) . ToLowerInvariant ( ) + value . Substring ( 1 ) ;
0 commit comments