-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathplugin-setup.ts
More file actions
66 lines (57 loc) · 1.86 KB
/
Copy pathplugin-setup.ts
File metadata and controls
66 lines (57 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { CategoryConfig } from './category-config.js';
import type { PluginMeta } from './plugin-config.js';
type PromptBase = {
key: string;
message: string;
};
type PromptChoice<T extends string> = { name: string; value: T };
type InputPrompt = PromptBase & {
type: 'input';
default: string;
};
type SelectPrompt<T extends string = string> = PromptBase & {
type: 'select';
choices: PromptChoice<T>[];
default: T;
};
type CheckboxPrompt<T extends string = string> = PromptBase & {
type: 'checkbox';
choices: PromptChoice<T>[];
default: T[];
};
/** Declarative prompt definition used to collect plugin-specific options. */
export type PluginPromptDescriptor =
| InputPrompt
| SelectPrompt
| CheckboxPrompt;
export type ImportDeclarationStructure = {
moduleSpecifier: string;
defaultImport?: string;
namedImports?: string[];
isTypeOnly?: boolean;
};
/** Import declarations and plugin initialization code produced by `generateConfig`. */
export type PluginCodegenResult = {
imports: ImportDeclarationStructure[];
pluginInit: string;
categories?: CategoryConfig[];
};
/**
* Defines how a plugin integrates with the setup wizard.
*
* Each supported plugin provides a binding that controls:
* - Pre-selection: `isRecommended` detects if the plugin is relevant for the repository
* - Configuration: `prompts` collect plugin-specific options interactively
* - Code generation: `generateConfig` produces the import and initialization code
*/
export type PluginSetupBinding = {
slug: PluginMeta['slug'];
title: PluginMeta['title'];
packageName: NonNullable<PluginMeta['packageName']>;
scope?: 'project' | 'root';
prompts?: (targetDir: string) => Promise<PluginPromptDescriptor[]>;
isRecommended?: (targetDir: string) => Promise<boolean>;
generateConfig: (
answers: Record<string, string | string[]>,
) => PluginCodegenResult;
};