1
- import inquirer from ' inquirer' ;
1
+ import inquirer from " inquirer" ;
2
2
// @types /globby doesn't export types for GlobOptions, so we have to work a little bit to extract them:
3
3
// GlobOptions is the second parameter of the sync function, which can be extracted with the Parameters<T> type
4
- import { globbySync } from ' globby' ;
4
+ import { globbySync } from " globby" ;
5
5
6
6
type GlobOptions = Parameters < typeof globbySync > [ 1 ] ;
7
- import { HelperDelegate as HelperFunction } from ' handlebars' ;
7
+ import { HelperDelegate as HelperFunction } from " handlebars" ;
8
8
9
9
export interface IncludeDefinitionConfig {
10
- generators ?: boolean ;
11
- helpers ?: boolean ;
12
- partials ?: boolean ;
13
- actionTypes ?: boolean ;
10
+ generators ?: boolean ;
11
+ helpers ?: boolean ;
12
+ partials ?: boolean ;
13
+ actionTypes ?: boolean ;
14
14
}
15
15
16
- export type IncludeDefinition =
17
- | boolean
18
- | string [ ]
19
- | IncludeDefinitionConfig ;
16
+ export type IncludeDefinition = boolean | string [ ] | IncludeDefinitionConfig ;
20
17
21
18
export interface NodePlopAPI {
22
- setGenerator ( name : string , config : Partial < PlopGeneratorConfig > ) : PlopGenerator ;
19
+ setGenerator (
20
+ name : string ,
21
+ config : Partial < PlopGeneratorConfig >
22
+ ) : PlopGenerator ;
23
23
24
- setPrompt ( name : string , prompt : inquirer . prompts . PromptConstructor ) : void ;
24
+ setPrompt ( name : string , prompt : inquirer . prompts . PromptConstructor ) : void ;
25
25
26
- setWelcomeMessage ( message : string ) : void ;
26
+ setWelcomeMessage ( message : string ) : void ;
27
27
28
- getWelcomeMessage ( ) : string ;
28
+ getWelcomeMessage ( ) : string ;
29
29
30
- getGenerator ( name : string ) : PlopGenerator ;
30
+ getGenerator ( name : string ) : PlopGenerator ;
31
31
32
- getGeneratorList ( ) : { name : string ; description : string } [ ] ;
32
+ getGeneratorList ( ) : { name : string ; description : string } [ ] ;
33
33
34
- setPartial ( name : string , str : string ) : void ;
34
+ setPartial ( name : string , str : string ) : void ;
35
35
36
- getPartial ( name : string ) : string ;
36
+ getPartial ( name : string ) : string ;
37
37
38
- getPartialList ( ) : string [ ] ;
38
+ getPartialList ( ) : string [ ] ;
39
39
40
- setHelper ( name : string , fn : HelperFunction ) : void ;
40
+ setHelper ( name : string , fn : HelperFunction ) : void ;
41
41
42
- // eslint-disable-next-line @typescript-eslint/ban-types
43
- getHelper ( name : string ) : Function ;
42
+ // eslint-disable-next-line @typescript-eslint/ban-types
43
+ getHelper ( name : string ) : Function ;
44
44
45
- getHelperList ( ) : string [ ] ;
45
+ getHelperList ( ) : string [ ] ;
46
46
47
- setActionType ( name : string , fn : CustomActionFunction ) : void ;
47
+ setActionType ( name : string , fn : CustomActionFunction ) : void ;
48
48
49
- /**
50
- * This does not include a `CustomActionConfig` for the same reasons
51
- * Listed in the `ActionType` declaration. Please see that JSDoc for more
52
- */
53
- getActionType ( name : string ) : ActionType ;
49
+ /**
50
+ * This does not include a `CustomActionConfig` for the same reasons
51
+ * Listed in the `ActionType` declaration. Please see that JSDoc for more
52
+ */
53
+ getActionType ( name : string ) : ActionType ;
54
54
55
- getActionTypeList ( ) : string [ ] ;
55
+ getActionTypeList ( ) : string [ ] ;
56
56
57
- setPlopfilePath ( filePath : string ) : void ;
57
+ setPlopfilePath ( filePath : string ) : void ;
58
58
59
- getPlopfilePath ( ) : string ;
59
+ getPlopfilePath ( ) : string ;
60
60
61
- getDestBasePath ( ) : string ;
61
+ getDestBasePath ( ) : string ;
62
62
63
- // plop.load functionality
64
- load ( target : string [ ] | string , loadCfg ?: Partial < PlopCfg > | null , includeOverride ?: IncludeDefinition ) : Promise < void > ;
63
+ // plop.load functionality
64
+ load (
65
+ target : string [ ] | string ,
66
+ loadCfg ?: Partial < PlopCfg > | null ,
67
+ includeOverride ?: IncludeDefinition
68
+ ) : Promise < void > ;
65
69
66
- setDefaultInclude ( inc : object ) : void ;
70
+ setDefaultInclude ( inc : object ) : void ;
67
71
68
- getDefaultInclude ( ) : object ;
72
+ getDefaultInclude ( ) : object ;
69
73
70
- renderString ( template : string , data : any ) : string ; //set to any matching handlebars declaration
74
+ renderString ( template : string , data : any ) : string ; //set to any matching handlebars declaration
71
75
72
- // passthroughs for backward compatibility
73
- /**
74
- * @deprecated Use "setPrompt" instead. This will be removed in the next major release
75
- */
76
- addPrompt ( name : string , prompt : inquirer . PromptModule ) : void ;
76
+ // passthroughs for backward compatibility
77
+ /**
78
+ * @deprecated Use "setPrompt" instead. This will be removed in the next major release
79
+ */
80
+ addPrompt ( name : string , prompt : inquirer . PromptModule ) : void ;
77
81
78
- /**
79
- * @deprecated Use "setPartial" instead. This will be removed in the next major release
80
- */
81
- addPartial ( name : string , str : string ) : void ;
82
+ /**
83
+ * @deprecated Use "setPartial" instead. This will be removed in the next major release
84
+ */
85
+ addPartial ( name : string , str : string ) : void ;
82
86
83
- /**
84
- * @deprecated Use "setHelper" instead. This will be removed in the next major release
85
- */
86
- // eslint-disable-next-line @typescript-eslint/ban-types
87
- addHelper ( name : string , fn : Function ) : void ;
87
+ /**
88
+ * @deprecated Use "setHelper" instead. This will be removed in the next major release
89
+ */
90
+ // eslint-disable-next-line @typescript-eslint/ban-types
91
+ addHelper ( name : string , fn : Function ) : void ;
88
92
}
89
93
90
94
interface PlopActionHooksFailures {
91
- type : string ;
92
- path : string ;
93
- error : string ;
94
- message : string ;
95
+ type : string ;
96
+ path : string ;
97
+ error : string ;
98
+ message : string ;
95
99
}
96
100
97
101
interface PlopActionHooksChanges {
98
- type : string ;
99
- path : string ;
102
+ type : string ;
103
+ path : string ;
100
104
}
101
105
102
106
interface PlopActionHooks {
103
- onComment ?: ( msg : string ) => void ;
104
- onSuccess ?: ( change : PlopActionHooksChanges ) => void ;
105
- onFailure ?: ( failure : PlopActionHooksFailures ) => void ;
107
+ onComment ?: ( msg : string ) => void ;
108
+ onSuccess ?: ( change : PlopActionHooksChanges ) => void ;
109
+ onFailure ?: ( failure : PlopActionHooksFailures ) => void ;
106
110
}
107
111
108
112
export interface PlopGeneratorConfig {
109
- description : string ;
110
- prompts : Prompts ;
111
- actions : Actions ;
113
+ description : string ;
114
+ prompts : Prompts ;
115
+ actions : Actions ;
112
116
}
113
117
114
118
export interface PlopGenerator extends PlopGeneratorConfig {
115
- runPrompts : ( bypassArr ?: string [ ] ) => Promise < any > ;
116
- runActions : (
117
- answers : inquirer . Answers ,
118
- hooks ?: PlopActionHooks
119
- ) => Promise < {
120
- changes : PlopActionHooksChanges [ ] ;
121
- failures : PlopActionHooksFailures [ ] ;
122
- } > ;
119
+ runPrompts : ( bypassArr ?: string [ ] ) => Promise < any > ;
120
+ runActions : (
121
+ answers : inquirer . Answers ,
122
+ hooks ?: PlopActionHooks
123
+ ) => Promise < {
124
+ changes : PlopActionHooksChanges [ ] ;
125
+ failures : PlopActionHooksFailures [ ] ;
126
+ } > ;
123
127
}
124
128
125
- export type PromptQuestion = inquirer . Question
126
- | inquirer . CheckboxQuestion
127
- | inquirer . ListQuestion
128
- | inquirer . ExpandQuestion
129
- | inquirer . ConfirmQuestion
130
- | inquirer . EditorQuestion
131
- | inquirer . RawListQuestion
132
- | inquirer . PasswordQuestion
133
- | inquirer . NumberQuestion
134
- | inquirer . InputQuestion ;
135
-
136
- export type DynamicPromptsFunction = ( inquirer : inquirer . Inquirer ) => Promise < inquirer . Answers > ;
129
+ export type PromptQuestion =
130
+ | inquirer . Question
131
+ | inquirer . CheckboxQuestion
132
+ | inquirer . ListQuestion
133
+ | inquirer . ExpandQuestion
134
+ | inquirer . ConfirmQuestion
135
+ | inquirer . EditorQuestion
136
+ | inquirer . RawListQuestion
137
+ | inquirer . PasswordQuestion
138
+ | inquirer . NumberQuestion
139
+ | inquirer . InputQuestion ;
140
+
141
+ export type DynamicPromptsFunction = (
142
+ inquirer : inquirer . Inquirer
143
+ ) => Promise < inquirer . Answers > ;
137
144
export type DynamicActionsFunction = ( data ?: inquirer . Answers ) => ActionType [ ] ;
138
145
139
- export type Prompts = DynamicPromptsFunction | PromptQuestion [ ]
146
+ export type Prompts = DynamicPromptsFunction | PromptQuestion [ ] ;
140
147
export type Actions = DynamicActionsFunction | ActionType [ ] ;
141
148
142
149
interface Template {
143
- template : string ;
144
- templateFile ?: never ;
150
+ template : string ;
151
+ templateFile ?: never ;
145
152
}
146
153
147
154
interface TemplateFile {
148
- template ?: never ;
149
- templateFile : string ;
155
+ template ?: never ;
156
+ templateFile : string ;
150
157
}
151
158
152
159
type TemplateStrOrFile = Template | TemplateFile ;
@@ -165,18 +172,17 @@ type TemplateStrOrFile = Template | TemplateFile;
165
172
*
166
173
* To ignore this limitation, simply pass "string"
167
174
*/
168
- export interface CustomActionConfig < TypeString extends string > extends Omit < ActionConfig , 'type' > {
169
- type : TypeString extends 'addMany' |
170
- 'modify' |
171
- 'append' ? never : TypeString ;
175
+ export interface CustomActionConfig < TypeString extends string >
176
+ extends Omit < ActionConfig , "type" > {
177
+ type : TypeString extends "addMany" | "modify" | "append" ? never : TypeString ;
172
178
173
- [ key : string ] : any ;
179
+ [ key : string ] : any ;
174
180
}
175
181
176
182
export type CustomActionFunction = (
177
- answers : inquirer . Answers ,
178
- config : CustomActionConfig < string > ,
179
- plopfileApi : NodePlopAPI
183
+ answers : inquirer . Answers ,
184
+ config : CustomActionConfig < string > ,
185
+ plopfileApi : NodePlopAPI
180
186
) => Promise < string > | string ;
181
187
182
188
/**
@@ -190,69 +196,83 @@ export type CustomActionFunction = (
190
196
* If you know of a solution, please open a GitHub issue to discuss
191
197
*/
192
198
export type ActionType =
193
- | string
194
- | ActionConfig
195
- | AddActionConfig
196
- | AddManyActionConfig
197
- | ModifyActionConfig
198
- | AppendActionConfig
199
- | CustomActionFunction ;
199
+ | string
200
+ | ActionConfig
201
+ | AddActionConfig
202
+ | AddManyActionConfig
203
+ | ModifyActionConfig
204
+ | AppendActionConfig
205
+ | CustomActionFunction ;
200
206
201
207
export interface ActionConfig {
202
- type : string ;
203
- force ?: boolean ;
204
- data ?: object ;
205
- abortOnFail ?: boolean ;
206
- // eslint-disable-next-line @typescript-eslint/ban-types
207
- skip ?: Function ;
208
+ type : string ;
209
+ force ?: boolean ;
210
+ data ?: object ;
211
+ abortOnFail ?: boolean ;
212
+ // eslint-disable-next-line @typescript-eslint/ban-types
213
+ skip ?: Function ;
208
214
}
209
215
210
- type TransformFn < T > = ( template : string , data : any , cfg : T ) => string | Promise < string > ;
216
+ type TransformFn < T > = (
217
+ template : string ,
218
+ data : any ,
219
+ cfg : T
220
+ ) => string | Promise < string > ;
211
221
212
222
interface AddActionConfigBase extends ActionConfig {
213
- type : ' add' ;
214
- path : string ;
215
- skipIfExists ?: boolean ;
216
- transform ?: TransformFn < AddActionConfig > ;
223
+ type : " add" ;
224
+ path : string ;
225
+ skipIfExists ?: boolean ;
226
+ transform ?: TransformFn < AddActionConfig > ;
217
227
}
218
228
219
229
export type AddActionConfig = AddActionConfigBase & TemplateStrOrFile ;
220
230
221
- export interface AddManyActionConfig extends Pick < AddActionConfig , Exclude < keyof AddActionConfig , 'type' | 'templateFile' | 'template' | 'transform' > > {
222
- type : 'addMany' ;
223
- destination : string ;
224
- base : string ;
225
- templateFiles : string | string [ ] ;
226
- stripExtensions ?: string [ ] ;
227
- globOptions : GlobOptions ;
228
- verbose ?: boolean ;
229
- transform ?: TransformFn < AddManyActionConfig > ;
231
+ export interface AddManyActionConfig
232
+ extends Pick <
233
+ AddActionConfig ,
234
+ Exclude <
235
+ keyof AddActionConfig ,
236
+ "type" | "templateFile" | "template" | "transform"
237
+ >
238
+ > {
239
+ type : "addMany" ;
240
+ destination : string ;
241
+ base : string ;
242
+ templateFiles : string | string [ ] ;
243
+ stripExtensions ?: string [ ] ;
244
+ globOptions : GlobOptions ;
245
+ verbose ?: boolean ;
246
+ transform ?: TransformFn < AddManyActionConfig > ;
230
247
}
231
248
232
249
interface ModifyActionConfigBase extends ActionConfig {
233
- type : ' modify' ;
234
- path : string ;
235
- pattern : string | RegExp ;
236
- transform ?: TransformFn < ModifyActionConfig > ;
250
+ type : " modify" ;
251
+ path : string ;
252
+ pattern : string | RegExp ;
253
+ transform ?: TransformFn < ModifyActionConfig > ;
237
254
}
238
255
239
256
export type ModifyActionConfig = ModifyActionConfigBase & TemplateStrOrFile ;
240
257
241
258
interface AppendActionConfigBase extends ActionConfig {
242
- type : ' append' ;
243
- path : string ;
244
- pattern : string | RegExp ;
245
- unique : boolean ;
246
- separator : string ;
259
+ type : " append" ;
260
+ path : string ;
261
+ pattern : string | RegExp ;
262
+ unique : boolean ;
263
+ separator : string ;
247
264
}
248
265
249
266
export type AppendActionConfig = AppendActionConfigBase & TemplateStrOrFile ;
250
267
251
268
export interface PlopCfg {
252
- force : boolean ;
253
- destBasePath : string | undefined ;
269
+ force : boolean ;
270
+ destBasePath : string | undefined ;
254
271
}
255
272
256
- declare function nodePlop ( plopfilePath ?: string , plopCfg ?: PlopCfg ) : Promise < NodePlopAPI > ;
273
+ declare function nodePlop (
274
+ plopfilePath ?: string ,
275
+ plopCfg ?: PlopCfg
276
+ ) : Promise < NodePlopAPI > ;
257
277
258
278
export default nodePlop ;
0 commit comments