UNPKG

3.17 kBTypeScriptView Raw
1import inquirer = require("inquirer");
2// @types/globby doesn't export types for GlobOptions, so we have to work a little bit to extract them:
3// GlobOptions is the second parameter of the sync function, which can be extracted with the Parameters<T> type
4import { GlobbyOptions } from 'globby';
5import {HelperDelegate as HelperFunction} from 'handlebars';
6
7export interface NodePlopAPI {
8 getGenerator(name: string): PlopGenerator;
9 setGenerator(name: string, config: PlopGenerator): PlopGenerator;
10
11 setPrompt(name: string, prompt: inquirer.PromptModule): void;
12 setWelcomeMessage(message: string): void;
13 getWelcomeMessage(): string;
14 getGeneratorList(): { name: string; description: string }[];
15 setPartial(name: string, str: string): void;
16 getPartial(name: string): string;
17 getPartialList(): string[];
18 setHelper(name: string, fn: HelperFunction): void;
19 getHelper(name: string): Function;
20 getHelperList(): string[];
21 setActionType(name: string, fn: CustomActionFunction): void;
22 getActionType(name: string): ActionType;
23 getActionTypeList(): string[];
24
25 setPlopfilePath(filePath: string): void;
26 getPlopfilePath(): string;
27 getDestBasePath(): string;
28
29 // plop.load functionality
30 load(
31 target: string[] | string,
32 loadCfg: PlopCfg,
33 includeOverride: boolean
34 ): void;
35 setDefaultInclude(inc: object): void;
36 getDefaultInclude(): object;
37
38 renderString(template: string, data: any): String; //set to any matching handlebars declaration
39
40 // passthroughs for backward compatibility
41 addPrompt(name: string, prompt: inquirer.PromptModule): void;
42 addPartial(name: string, str: string): void;
43 addHelper(name: string, fn: Function): void;
44}
45
46export interface PlopGenerator {
47 description: string;
48 prompts: inquirer.Question[];
49 actions: ActionType[];
50}
51
52export type CustomActionFunction = (
53 answers: object,
54 config?: ActionConfig,
55 plopfileApi?: NodePlopAPI
56) => Promise<string> | string; // Check return type?
57
58export type ActionType =
59 | ActionConfig
60 | AddManyActionConfig
61 | ModifyActionConfig
62 | AppendActionConfig
63 | CustomActionFunction;
64
65export interface ActionConfig {
66 type: string;
67 force: boolean;
68 data: object;
69 abortOnFail: boolean;
70}
71
72export interface AddActionConfig extends ActionConfig {
73 type: "add";
74 path: string;
75 template: string;
76 templateFile: string;
77 skipIfExists: boolean;
78}
79
80export interface AddManyActionConfig
81 extends Pick<AddActionConfig, Exclude<keyof AddActionConfig, "type">> {
82 type: "addMany";
83 destination: string;
84 base: string;
85 templateFiles: string;
86 globOptions: GlobbyOptions;
87 verbose: boolean;
88}
89
90export interface ModifyActionConfig extends ActionConfig {
91 type: "modify";
92 path: string;
93 pattern: string | RegExp;
94 template: string;
95 templateFile: string;
96}
97
98export interface AppendActionConfig extends ActionConfig {
99 type: "append";
100 path: string;
101 pattern: string | RegExp;
102 unique: boolean;
103 separator: string;
104 template: string;
105 templateFile: string;
106}
107
108export interface PlopCfg {
109 force: boolean;
110 destBasePath: string;
111}
112
113declare function nodePlop(plopfilePath: string, plopCfg?: PlopCfg): NodePlopAPI;
114export default nodePlop;