@@ -40,6 +40,14 @@ export class GeneratorService {
40
40
const commands = flatten ( enabledGenerators . map ( ( [ name , config ] ) => {
41
41
// eslint-disable-next-line @typescript-eslint/no-unused-vars
42
42
const { glob : globPattern , disabled, ...params } = config
43
+
44
+ if ( ! globPattern ) {
45
+ return [ {
46
+ name : `[${ name } ] ${ params . inputSpec } ` ,
47
+ command : this . buildCommand ( cwd , params )
48
+ } ]
49
+ }
50
+
43
51
const specFiles = glob . sync ( globPattern , { cwd} )
44
52
45
53
if ( specFiles . length < 1 ) {
@@ -48,7 +56,7 @@ export class GeneratorService {
48
56
49
57
return glob . sync ( globPattern , { cwd} ) . map ( spec => ( {
50
58
name : `[${ name } ] ${ spec } ` ,
51
- command : this . buildCommand ( cwd , spec , params ) ,
59
+ command : this . buildCommand ( cwd , params , spec )
52
60
} ) )
53
61
} ) )
54
62
@@ -77,11 +85,11 @@ export class GeneratorService {
77
85
} ) . join ( '\n' ) )
78
86
}
79
87
80
- private buildCommand ( cwd : string , specFile : string , params : Record < string , unknown > ) {
81
- const absoluteSpecPath = path . resolve ( cwd , specFile )
88
+ private buildCommand ( cwd : string , params : Record < string , unknown > , specFile ?: string ) {
89
+ const absoluteSpecPath = specFile ? path . resolve ( cwd , specFile ) : String ( params . inputSpec )
82
90
83
91
const command = Object . entries ( {
84
- [ 'input-spec' ] : absoluteSpecPath ,
92
+ inputSpec : absoluteSpecPath ,
85
93
...params ,
86
94
} ) . map ( ( [ k , v ] ) => {
87
95
@@ -113,17 +121,19 @@ export class GeneratorService {
113
121
cwd,
114
122
115
123
base : path . basename ( absoluteSpecPath ) ,
116
- dir : path . dirname ( absoluteSpecPath ) ,
124
+ dir : specFile && path . dirname ( absoluteSpecPath ) ,
117
125
path : absoluteSpecPath ,
118
126
119
- relDir : path . dirname ( specFile ) ,
127
+ relDir : specFile && path . dirname ( specFile ) ,
120
128
relPath : specFile ,
121
- ext : ext . split ( '.' ) . slice ( - 1 ) . pop ( ) ,
129
+ ext : ext . split ( '.' ) . slice ( - 1 ) . pop ( )
122
130
}
123
131
124
- return this . cmd ( Object . entries ( placeholders ) . reduce ( ( cmd , [ search , replacement ] ) => {
125
- return cmd . split ( `#{${ search } }` ) . join ( replacement )
126
- } , command ) )
132
+ return this . cmd ( Object . entries ( placeholders )
133
+ . filter ( ( [ , replacement ] ) => ! ! replacement )
134
+ . reduce ( ( cmd , [ search , replacement ] ) => {
135
+ return cmd . split ( `#{${ search } }` ) . join ( replacement )
136
+ } , command ) )
127
137
}
128
138
129
139
private cmd = ( appendix : string ) => [
0 commit comments