Skip to content

Commit 7a8b0a7

Browse files
committed
chore: format ts files using eslint + prettier
1 parent 9536737 commit 7a8b0a7

File tree

6 files changed

+557
-504
lines changed

6 files changed

+557
-504
lines changed

packages/node-plop/types/index.d.ts

Lines changed: 157 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,159 @@
1-
import inquirer from 'inquirer';
1+
import inquirer from "inquirer";
22
// @types/globby doesn't export types for GlobOptions, so we have to work a little bit to extract them:
33
// 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";
55

66
type GlobOptions = Parameters<typeof globbySync>[1];
7-
import {HelperDelegate as HelperFunction} from 'handlebars';
7+
import { HelperDelegate as HelperFunction } from "handlebars";
88

99
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;
1414
}
1515

16-
export type IncludeDefinition =
17-
| boolean
18-
| string[]
19-
| IncludeDefinitionConfig;
16+
export type IncludeDefinition = boolean | string[] | IncludeDefinitionConfig;
2017

2118
export interface NodePlopAPI {
22-
setGenerator(name: string, config: Partial<PlopGeneratorConfig>): PlopGenerator;
19+
setGenerator(
20+
name: string,
21+
config: Partial<PlopGeneratorConfig>
22+
): PlopGenerator;
2323

24-
setPrompt(name: string, prompt: inquirer.prompts.PromptConstructor): void;
24+
setPrompt(name: string, prompt: inquirer.prompts.PromptConstructor): void;
2525

26-
setWelcomeMessage(message: string): void;
26+
setWelcomeMessage(message: string): void;
2727

28-
getWelcomeMessage(): string;
28+
getWelcomeMessage(): string;
2929

30-
getGenerator(name: string): PlopGenerator;
30+
getGenerator(name: string): PlopGenerator;
3131

32-
getGeneratorList(): { name: string; description: string }[];
32+
getGeneratorList(): { name: string; description: string }[];
3333

34-
setPartial(name: string, str: string): void;
34+
setPartial(name: string, str: string): void;
3535

36-
getPartial(name: string): string;
36+
getPartial(name: string): string;
3737

38-
getPartialList(): string[];
38+
getPartialList(): string[];
3939

40-
setHelper(name: string, fn: HelperFunction): void;
40+
setHelper(name: string, fn: HelperFunction): void;
4141

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;
4444

45-
getHelperList(): string[];
45+
getHelperList(): string[];
4646

47-
setActionType(name: string, fn: CustomActionFunction): void;
47+
setActionType(name: string, fn: CustomActionFunction): void;
4848

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;
5454

55-
getActionTypeList(): string[];
55+
getActionTypeList(): string[];
5656

57-
setPlopfilePath(filePath: string): void;
57+
setPlopfilePath(filePath: string): void;
5858

59-
getPlopfilePath(): string;
59+
getPlopfilePath(): string;
6060

61-
getDestBasePath(): string;
61+
getDestBasePath(): string;
6262

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>;
6569

66-
setDefaultInclude(inc: object): void;
70+
setDefaultInclude(inc: object): void;
6771

68-
getDefaultInclude(): object;
72+
getDefaultInclude(): object;
6973

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
7175

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;
7781

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;
8286

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;
8892
}
8993

9094
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;
9599
}
96100

97101
interface PlopActionHooksChanges {
98-
type: string;
99-
path: string;
102+
type: string;
103+
path: string;
100104
}
101105

102106
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;
106110
}
107111

108112
export interface PlopGeneratorConfig {
109-
description: string;
110-
prompts: Prompts;
111-
actions: Actions;
113+
description: string;
114+
prompts: Prompts;
115+
actions: Actions;
112116
}
113117

114118
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+
}>;
123127
}
124128

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>;
137144
export type DynamicActionsFunction = (data?: inquirer.Answers) => ActionType[];
138145

139-
export type Prompts = DynamicPromptsFunction | PromptQuestion[]
146+
export type Prompts = DynamicPromptsFunction | PromptQuestion[];
140147
export type Actions = DynamicActionsFunction | ActionType[];
141148

142149
interface Template {
143-
template: string;
144-
templateFile?: never;
150+
template: string;
151+
templateFile?: never;
145152
}
146153

147154
interface TemplateFile {
148-
template?: never;
149-
templateFile: string;
155+
template?: never;
156+
templateFile: string;
150157
}
151158

152159
type TemplateStrOrFile = Template | TemplateFile;
@@ -165,18 +172,17 @@ type TemplateStrOrFile = Template | TemplateFile;
165172
*
166173
* To ignore this limitation, simply pass "string"
167174
*/
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;
172178

173-
[key: string]: any;
179+
[key: string]: any;
174180
}
175181

176182
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
180186
) => Promise<string> | string;
181187

182188
/**
@@ -190,69 +196,83 @@ export type CustomActionFunction = (
190196
* If you know of a solution, please open a GitHub issue to discuss
191197
*/
192198
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;
200206

201207
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;
208214
}
209215

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>;
211221

212222
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>;
217227
}
218228

219229
export type AddActionConfig = AddActionConfigBase & TemplateStrOrFile;
220230

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>;
230247
}
231248

232249
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>;
237254
}
238255

239256
export type ModifyActionConfig = ModifyActionConfigBase & TemplateStrOrFile;
240257

241258
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;
247264
}
248265

249266
export type AppendActionConfig = AppendActionConfigBase & TemplateStrOrFile;
250267

251268
export interface PlopCfg {
252-
force: boolean;
253-
destBasePath: string | undefined;
269+
force: boolean;
270+
destBasePath: string | undefined;
254271
}
255272

256-
declare function nodePlop(plopfilePath?: string, plopCfg?: PlopCfg): Promise<NodePlopAPI>;
273+
declare function nodePlop(
274+
plopfilePath?: string,
275+
plopCfg?: PlopCfg
276+
): Promise<NodePlopAPI>;
257277

258278
export default nodePlop;

0 commit comments

Comments
 (0)