@@ -100,6 +100,24 @@ export class GeneratorService {
100
100
const dockerVolumes = { } ;
101
101
const absoluteSpecPath = specFile ? path . resolve ( cwd , specFile ) : String ( params . inputSpec )
102
102
103
+ const ext = path . extname ( absoluteSpecPath )
104
+ const name = path . basename ( absoluteSpecPath , ext )
105
+
106
+ const placeholders : { [ key : string ] : string } = {
107
+ name,
108
+ Name : upperFirst ( name ) ,
109
+
110
+ cwd,
111
+
112
+ base : path . basename ( absoluteSpecPath ) ,
113
+ dir : specFile && path . dirname ( absoluteSpecPath ) ,
114
+ path : absoluteSpecPath ,
115
+
116
+ relDir : specFile && path . dirname ( specFile ) ,
117
+ relPath : specFile ,
118
+ ext : ext . split ( '.' ) . slice ( - 1 ) . pop ( )
119
+ }
120
+
103
121
const command = Object . entries ( {
104
122
inputSpec : absoluteSpecPath ,
105
123
...params ,
@@ -116,8 +134,9 @@ export class GeneratorService {
116
134
case 'boolean' :
117
135
return undefined
118
136
default :
119
-
120
137
if ( this . configService . useDocker ) {
138
+ v = this . replacePlaceholders ( placeholders , v ) ;
139
+
121
140
if ( key === 'output' ) {
122
141
fs . ensureDirSync ( v ) ;
123
142
}
@@ -133,37 +152,23 @@ export class GeneratorService {
133
152
} ) ( )
134
153
135
154
return value === undefined ? `--${ key } ` : `--${ key } =${ value } `
136
- } ) . join ( ' ' )
137
-
138
- const ext = path . extname ( absoluteSpecPath )
139
- const name = path . basename ( absoluteSpecPath , ext )
140
-
141
- const placeholders : { [ key : string ] : string } = {
142
- name,
143
- Name : upperFirst ( name ) ,
144
-
145
- cwd,
146
-
147
- base : path . basename ( absoluteSpecPath ) ,
148
- dir : specFile && path . dirname ( absoluteSpecPath ) ,
149
- path : absoluteSpecPath ,
150
-
151
- relDir : specFile && path . dirname ( specFile ) ,
152
- relPath : specFile ,
153
- ext : ext . split ( '.' ) . slice ( - 1 ) . pop ( )
154
- }
155
+ } ) . join ( ' ' ) ;
155
156
156
157
return this . cmd (
157
158
customGenerator ,
158
- Object . entries ( placeholders )
159
- . filter ( ( [ , replacement ] ) => ! ! replacement )
160
- . reduce ( ( cmd , [ search , replacement ] ) => {
161
- return cmd . split ( `#{${ search } }` ) . join ( replacement )
162
- } , command ) ,
159
+ this . replacePlaceholders ( placeholders , command ) ,
163
160
dockerVolumes ,
164
161
)
165
162
}
166
163
164
+ private replacePlaceholders ( placeholders : Record < string , string > , input : string ) {
165
+ return Object . entries ( placeholders )
166
+ . filter ( ( [ , replacement ] ) => ! ! replacement )
167
+ . reduce ( ( acc , [ search , replacement ] ) => {
168
+ return acc . split ( `#{${ search } }` ) . join ( replacement )
169
+ } , input ) ;
170
+ }
171
+
167
172
private cmd = ( customGenerator : string | undefined , appendix : string , dockerVolumes = { } ) => {
168
173
169
174
if ( this . configService . useDocker ) {
0 commit comments