Skip to content

Commit f6d3701

Browse files
committed
refactor(create-cli): pass single input to generateConfig
1 parent 47eb97a commit f6d3701

11 files changed

Lines changed: 24 additions & 18 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type {
55
CategoryCodegenConfig,
66
ImportDeclarationStructure,
77
PluginAnswer,
8+
PluginCodegenInput,
89
PluginCodegenResult,
910
PluginPromptDescriptor,
1011
PluginSetupBinding,

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ async function resolveBinding(
9393
tree: Pick<Tree, 'read' | 'write'>,
9494
): Promise<PluginCodegenResult> {
9595
if (!binding.prompts) {
96-
return binding.generateConfig({}, tree);
96+
return binding.generateConfig({
97+
tree,
98+
targetDir,
99+
cliArgs,
100+
answers: {},
101+
});
97102
}
98103
logger.newline();
99104
logger.info(ansis.bold(binding.title));
@@ -102,7 +107,7 @@ async function resolveBinding(
102107
descriptors.length > 0
103108
? await promptPluginOptions(descriptors, cliArgs)
104109
: {};
105-
return binding.generateConfig(answers, tree);
110+
return binding.generateConfig({ tree, targetDir, cliArgs, answers });
106111
}
107112

108113
async function writeStandaloneConfig(

packages/models/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export type {
116116
CategoryCodegenConfig,
117117
ImportDeclarationStructure,
118118
PluginAnswer,
119+
PluginCodegenInput,
119120
PluginCodegenResult,
120121
PluginDeclarationStructure,
121122
PluginPromptDescriptor,

packages/models/src/lib/plugin-setup.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ export type PluginSetupTree = {
7272
write: (path: string, content: string) => Promise<void>;
7373
};
7474

75+
export type PluginCodegenInput = {
76+
answers: Record<string, PluginAnswer>;
77+
tree: PluginSetupTree;
78+
targetDir: string;
79+
cliArgs: Record<string, unknown>;
80+
};
81+
7582
/**
7683
* Defines how a plugin integrates with the setup wizard.
7784
*
@@ -88,7 +95,6 @@ export type PluginSetupBinding = {
8895
prompts?: (targetDir: string) => Promise<PluginPromptDescriptor[]>;
8996
isRecommended?: (targetDir: string) => Promise<boolean>;
9097
generateConfig: (
91-
answers: Record<string, PluginAnswer>,
92-
tree: PluginSetupTree,
98+
input: PluginCodegenInput,
9399
) => PluginCodegenResult | Promise<PluginCodegenResult>;
94100
};

packages/plugin-axe/src/lib/binding.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
CategoryCodegenConfig,
44
PluginAnswer,
55
PluginSetupBinding,
6-
PluginSetupTree,
76
} from '@code-pushup/models';
87
import {
98
answerBoolean,
@@ -84,10 +83,7 @@ export const axeSetupBinding = {
8483
default: true,
8584
},
8685
],
87-
generateConfig: async (
88-
answers: Record<string, PluginAnswer>,
89-
tree: PluginSetupTree,
90-
) => {
86+
generateConfig: async ({ answers, tree }) => {
9187
const options = parseAnswers(answers);
9288
if (options.setupScript) {
9389
await tree.write(SETUP_SCRIPT_PATH, SETUP_SCRIPT_CONTENT);

packages/plugin-coverage/src/lib/binding.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ export const coverageSetupBinding = {
128128
},
129129
];
130130
},
131-
generateConfig: async (
132-
answers: Record<string, PluginAnswer>,
133-
tree?: PluginSetupTree,
134-
) => {
131+
generateConfig: async ({ answers, tree }) => {
135132
const options = parseAnswers(answers);
136133
const lcovConfigured = await configureLcovReporter(options, tree);
137134
return {

packages/plugin-eslint/src/lib/binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const eslintSetupBinding = {
9090
default: true,
9191
},
9292
],
93-
generateConfig: (answers: Record<string, PluginAnswer>) => {
93+
generateConfig: ({ answers }) => {
9494
const options = parseAnswers(answers);
9595
return {
9696
imports: [

packages/plugin-js-packages/src/lib/binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export const jsPackagesSetupBinding = {
105105
},
106106
];
107107
},
108-
generateConfig: (answers: Record<string, PluginAnswer>) => {
108+
generateConfig: ({ answers }) => {
109109
const options = parseAnswers(answers);
110110
return {
111111
imports: [

packages/plugin-jsdocs/src/lib/binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const jsDocsSetupBinding = {
6060
default: true,
6161
},
6262
],
63-
generateConfig: (answers: Record<string, PluginAnswer>) => {
63+
generateConfig: ({ answers }) => {
6464
const options = parseAnswers(answers);
6565
return {
6666
imports: [

packages/plugin-lighthouse/src/lib/binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const lighthouseSetupBinding = {
8080
default: CATEGORIES.map(({ slug }) => slug),
8181
},
8282
],
83-
generateConfig: (answers: Record<string, PluginAnswer>) => {
83+
generateConfig: ({ answers }) => {
8484
const options = parseAnswers(answers);
8585
const hasCategories = options.categories.length > 0;
8686
const imports = [

0 commit comments

Comments
 (0)