1 | import inquirer = require('inquirer');
|
2 |
|
3 |
|
4 | import { sync as _sync } from 'globby';
|
5 | type GlobOptions = Parameters<typeof _sync>[1];
|
6 | import { HelperDelegate as HelperFunction } from 'handlebars';
|
7 |
|
8 | interface NodePlopAPI {
|
9 | getGenerator(name: string): PlopGenerator;
|
10 | setGenerator(name: string, config: PlopGeneratorConfig): PlopGenerator;
|
11 |
|
12 | setPrompt(name: string, prompt: inquirer.PromptModule): void;
|
13 | setWelcomeMessage(message: string): void;
|
14 | getWelcomeMessage(): string;
|
15 | getGeneratorList(): { name: string; description: string }[];
|
16 | setPartial(name: string, str: string): void;
|
17 | getPartial(name: string): string;
|
18 | getPartialList(): string[];
|
19 | setHelper(name: string, fn: HelperFunction): void;
|
20 | getHelper(name: string): Function;
|
21 | getHelperList(): string[];
|
22 | setActionType(name: string, fn: CustomActionFunction): void;
|
23 | getActionType(name: string): ActionType;
|
24 | getActionTypeList(): string[];
|
25 |
|
26 | setPlopfilePath(filePath: string): void;
|
27 | getPlopfilePath(): string;
|
28 | getDestBasePath(): string;
|
29 |
|
30 |
|
31 | load(target: string[] | string, loadCfg: PlopCfg, includeOverride: boolean): void;
|
32 | setDefaultInclude(inc: object): void;
|
33 | getDefaultInclude(): object;
|
34 |
|
35 | renderString(template: string, data: any): string;
|
36 |
|
37 |
|
38 | addPrompt(name: string, prompt: inquirer.PromptModule): void;
|
39 | addPartial(name: string, str: string): void;
|
40 | addHelper(name: string, fn: Function): void;
|
41 | }
|
42 |
|
43 | interface PlopActionHooksFailures {
|
44 | type: string;
|
45 | path: string;
|
46 | error: string;
|
47 | message: string;
|
48 | }
|
49 |
|
50 | interface PlopActionHooksChanges {
|
51 | type: string;
|
52 | path: string;
|
53 | }
|
54 |
|
55 | interface PlopActionHooks {
|
56 | onComment?: (msg: string) => void;
|
57 | onSuccess?: (change: PlopActionHooksChanges) => void;
|
58 | onFailure?: (failure: PlopActionHooksFailures) => void;
|
59 | }
|
60 |
|
61 | export interface PlopGeneratorConfig {
|
62 | description: string;
|
63 | prompts: Prompts;
|
64 | actions: Actions;
|
65 | }
|
66 |
|
67 | export interface PlopGenerator extends PlopGeneratorConfig {
|
68 | runPrompts: (bypassArr?: string[]) => Promise<any>;
|
69 | runActions: (
|
70 | answers: any,
|
71 | hooks?: PlopActionHooks
|
72 | ) => Promise<{
|
73 | changes: PlopActionHooksChanges[];
|
74 | failures: PlopActionHooksFailures[];
|
75 | }>;
|
76 | }
|
77 |
|
78 | export type PromptQuestion = inquirer.Question
|
79 | | inquirer.CheckboxQuestion
|
80 | | inquirer.ListQuestion
|
81 | | inquirer.ExpandQuestion
|
82 | | inquirer.ConfirmQuestion
|
83 | | inquirer.EditorQuestion
|
84 | | inquirer.RawListQuestion
|
85 | | inquirer.PasswordQuestion
|
86 | | inquirer.NumberQuestion
|
87 | | inquirer.InputQuestion;
|
88 |
|
89 | export type DynamicPromptsFunction = (inquirer: inquirer.Inquirer) => Promise<inquirer.Answers>;
|
90 | export type DynamicActionsFunction = (data?: inquirer.Answers) => ActionType[];
|
91 |
|
92 | export type Prompts = DynamicPromptsFunction | PromptQuestion[]
|
93 | export type Actions = DynamicActionsFunction | ActionType[];
|
94 |
|
95 | export type CustomActionFunction = (
|
96 | answers: object,
|
97 | config?: ActionConfig,
|
98 | plopfileApi?: NodePlopAPI
|
99 | ) => Promise<string> | string;
|
100 |
|
101 | export type ActionType =
|
102 | | ActionConfig
|
103 | | AddActionConfig
|
104 | | AddManyActionConfig
|
105 | | ModifyActionConfig
|
106 | | AppendActionConfig
|
107 | | CustomActionFunction;
|
108 |
|
109 | export interface ActionConfig {
|
110 | type: string;
|
111 | force?: boolean;
|
112 | data?: object;
|
113 | abortOnFail?: boolean;
|
114 | }
|
115 |
|
116 | export interface AddActionConfig extends ActionConfig {
|
117 | type: 'add';
|
118 | path: string;
|
119 | template: string;
|
120 | templateFile: string;
|
121 | skipIfExists: boolean;
|
122 | }
|
123 |
|
124 | export interface AddManyActionConfig extends Pick<AddActionConfig, Exclude<keyof AddActionConfig, 'type'>> {
|
125 | type: 'addMany';
|
126 | destination: string;
|
127 | base: string;
|
128 | templateFiles: string;
|
129 | globOptions: GlobOptions;
|
130 | verbose: boolean;
|
131 | }
|
132 |
|
133 | export interface ModifyActionConfig extends ActionConfig {
|
134 | type: 'modify';
|
135 | path: string;
|
136 | pattern: string | RegExp;
|
137 | template: string;
|
138 | templateFile: string;
|
139 | }
|
140 |
|
141 | export interface AppendActionConfig extends ActionConfig {
|
142 | type: 'append';
|
143 | path: string;
|
144 | pattern: string | RegExp;
|
145 | unique: boolean;
|
146 | separator: string;
|
147 | template: string;
|
148 | templateFile: string;
|
149 | }
|
150 |
|
151 | export interface PlopCfg {
|
152 | force: boolean;
|
153 | destBasePath: string;
|
154 | }
|
155 |
|
156 | declare function nodePlop(plopfilePath: string, plopCfg?: PlopCfg): NodePlopAPI;
|
157 | export default nodePlop;
|