-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathplugin-setup.ts
More file actions
82 lines (70 loc) · 2.31 KB
/
plugin-setup.ts
File metadata and controls
82 lines (70 loc) · 2.31 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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[];
};
type ConfirmPrompt = PromptBase & {
type: 'confirm';
default: boolean;
};
/** Declarative prompt definition used to collect plugin-specific options. */
export type PluginPromptDescriptor =
| InputPrompt
| SelectPrompt
| CheckboxPrompt
| ConfirmPrompt;
export type ImportDeclarationStructure = {
moduleSpecifier: string;
defaultImport?: string;
namedImports?: string[];
isTypeOnly?: boolean;
};
/** A single value in the answers record produced by plugin prompts. */
export type PluginAnswer = string | string[] | boolean;
/** Code a plugin binding contributes to the generated config. */
export type PluginCodegenResult = {
imports: ImportDeclarationStructure[];
pluginInit: string;
categories?: CategoryConfig[];
};
/** Minimal file system abstraction passed to plugin bindings. */
export type PluginSetupTree = {
read: (path: string) => Promise<string | null>;
write: (path: string, content: string) => Promise<void>;
};
/**
* 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, PluginAnswer>,
tree: PluginSetupTree,
) => PluginCodegenResult | Promise<PluginCodegenResult>;
};