Skip to content

Commit f493911

Browse files
committed
refactor: extract plugin setup types to models
1 parent 9a288ee commit f493911

3 files changed

Lines changed: 80 additions & 66 deletions

File tree

packages/create-cli/src/lib/setup/types.ts

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import type { CategoryConfig, PluginMeta } from '@code-pushup/models';
1+
import type { PluginCodegenResult } from '@code-pushup/models';
22
import type { MonorepoTool } from '@code-pushup/utils';
33

4+
export type {
5+
ImportDeclarationStructure,
6+
PluginCodegenResult,
7+
PluginPromptDescriptor,
8+
PluginSetupBinding,
9+
} from '@code-pushup/models';
10+
411
export const CI_PROVIDERS = ['github', 'gitlab', 'none'] as const;
512
export type CiProvider = (typeof CI_PROVIDERS)[number];
613

@@ -24,50 +31,6 @@ export type CliArgs = {
2431
[key: string]: unknown;
2532
};
2633

27-
type PromptBase = {
28-
key: string;
29-
message: string;
30-
};
31-
32-
type PromptChoice<T extends string> = { name: string; value: T };
33-
34-
type InputPrompt = PromptBase & {
35-
type: 'input';
36-
default: string;
37-
};
38-
39-
type SelectPrompt<T extends string = string> = PromptBase & {
40-
type: 'select';
41-
choices: PromptChoice<T>[];
42-
default: T;
43-
};
44-
45-
type CheckboxPrompt<T extends string = string> = PromptBase & {
46-
type: 'checkbox';
47-
choices: PromptChoice<T>[];
48-
default: T[];
49-
};
50-
51-
/** Declarative prompt definition used to collect plugin-specific options. */
52-
export type PluginPromptDescriptor =
53-
| InputPrompt
54-
| SelectPrompt
55-
| CheckboxPrompt;
56-
57-
export type ImportDeclarationStructure = {
58-
moduleSpecifier: string;
59-
defaultImport?: string;
60-
namedImports?: string[];
61-
isTypeOnly?: boolean;
62-
};
63-
64-
/** Import declarations and plugin initialization code produced by `generateConfig`. */
65-
export type PluginCodegenResult = {
66-
imports: ImportDeclarationStructure[];
67-
pluginInit: string;
68-
categories?: CategoryConfig[];
69-
};
70-
7134
export type ScopedPluginResult = {
7235
scope: PluginScope;
7336
result: PluginCodegenResult;
@@ -79,27 +42,6 @@ export type ConfigContext = {
7942
tool: MonorepoTool | null;
8043
};
8144

82-
/**
83-
* Defines how a plugin integrates with the setup wizard.
84-
*
85-
* Each supported plugin provides a binding that controls:
86-
* - Pre-selection: `isRecommended` detects if the plugin is relevant for the repository
87-
* - Configuration: `prompts` collect plugin-specific options interactively
88-
* - Code generation: `generateConfig` produces the import and initialization code
89-
*/
90-
export type PluginSetupBinding = {
91-
slug: PluginMeta['slug'];
92-
title: PluginMeta['title'];
93-
packageName: NonNullable<PluginMeta['packageName']>;
94-
prompts?: PluginPromptDescriptor[];
95-
scope?: PluginScope;
96-
isRecommended?: (targetDir: string) => Promise<boolean>;
97-
generateConfig: (
98-
answers: Record<string, string | string[]>,
99-
context: ConfigContext,
100-
) => PluginCodegenResult;
101-
};
102-
10345
/** A project discovered in a monorepo workspace. */
10446
export type WizardProject = {
10547
name: string;

packages/models/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ export {
112112
type PluginScoreTargets,
113113
type PluginUrls,
114114
} from './lib/plugin-config.js';
115+
export type {
116+
ImportDeclarationStructure,
117+
PluginCodegenResult,
118+
PluginPromptDescriptor,
119+
PluginSetupBinding,
120+
} from './lib/plugin-setup.js';
115121
export {
116122
auditReportSchema,
117123
pluginReportSchema,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import type { CategoryConfig } from './category-config.js';
2+
import type { PluginMeta } from './plugin-config.js';
3+
4+
type PromptBase = {
5+
key: string;
6+
message: string;
7+
};
8+
9+
type PromptChoice<T extends string> = { name: string; value: T };
10+
11+
type InputPrompt = PromptBase & {
12+
type: 'input';
13+
default: string;
14+
};
15+
16+
type SelectPrompt<T extends string = string> = PromptBase & {
17+
type: 'select';
18+
choices: PromptChoice<T>[];
19+
default: T;
20+
};
21+
22+
type CheckboxPrompt<T extends string = string> = PromptBase & {
23+
type: 'checkbox';
24+
choices: PromptChoice<T>[];
25+
default: T[];
26+
};
27+
28+
/** Declarative prompt definition used to collect plugin-specific options. */
29+
export type PluginPromptDescriptor =
30+
| InputPrompt
31+
| SelectPrompt
32+
| CheckboxPrompt;
33+
34+
export type ImportDeclarationStructure = {
35+
moduleSpecifier: string;
36+
defaultImport?: string;
37+
namedImports?: string[];
38+
isTypeOnly?: boolean;
39+
};
40+
41+
/** Import declarations and plugin initialization code produced by `generateConfig`. */
42+
export type PluginCodegenResult = {
43+
imports: ImportDeclarationStructure[];
44+
pluginInit: string;
45+
categories?: CategoryConfig[];
46+
};
47+
48+
/**
49+
* Defines how a plugin integrates with the setup wizard.
50+
*
51+
* Each supported plugin provides a binding that controls:
52+
* - Pre-selection: `isRecommended` detects if the plugin is relevant for the repository
53+
* - Configuration: `prompts` collect plugin-specific options interactively
54+
* - Code generation: `generateConfig` produces the import and initialization code
55+
*/
56+
export type PluginSetupBinding = {
57+
slug: PluginMeta['slug'];
58+
title: PluginMeta['title'];
59+
packageName: NonNullable<PluginMeta['packageName']>;
60+
scope?: 'project' | 'root';
61+
prompts?: (targetDir: string) => Promise<PluginPromptDescriptor[]>;
62+
isRecommended?: (targetDir: string) => Promise<boolean>;
63+
generateConfig: (
64+
answers: Record<string, string | string[]>,
65+
) => PluginCodegenResult;
66+
};

0 commit comments

Comments
 (0)