Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"glob": "^11.0.1",
"lighthouse": "^12.0.0",
"lighthouse-logger": "2.0.1",
"magicast": "^0.3.5",
"nx": "22.3.3",
"ora": "^9.0.0",
"parse-lcov": "^1.0.4",
Expand Down
12 changes: 12 additions & 0 deletions packages/create-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ Each plugin exposes its own configuration keys that can be passed as CLI argumen
| **`--eslint.patterns`** | `string` | `src` or `.` | File patterns to lint |
| **`--eslint.categories`** | `boolean` | `true` | Add recommended categories |

#### Coverage

| Option | Type | Default | Description |
| ------------------------------- | -------------------------------------- | -------------------- | ------------------------------ |
| **`--coverage.framework`** | `'jest'` \| `'vitest'` \| `'other'` | auto-detected | Test framework |
| **`--coverage.configFile`** | `string` | auto-detected | Path to test config file |
| **`--coverage.reportPath`** | `string` | `coverage/lcov.info` | Path to LCOV report file |
| **`--coverage.testCommand`** | `string` | auto-detected | Command to run tests |
| **`--coverage.types`** | `'function'` \| `'branch'` \| `'line'` | all | Coverage types to measure |
| **`--coverage.continueOnFail`** | `boolean` | `true` | Continue if test command fails |
| **`--coverage.categories`** | `boolean` | `true` | Add code coverage category |

### Examples

Run interactively (default):
Expand Down
1 change: 1 addition & 0 deletions packages/create-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"type": "module",
"dependencies": {
"@code-pushup/coverage-plugin": "0.120.1",
"@code-pushup/eslint-plugin": "0.120.1",
"@code-pushup/models": "0.120.1",
"@code-pushup/utils": "0.120.1",
Expand Down
8 changes: 6 additions & 2 deletions packages/create-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env node
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { coverageSetupBinding } from '@code-pushup/coverage-plugin';
import { eslintSetupBinding } from '@code-pushup/eslint-plugin';
import { parsePluginSlugs, validatePluginSlugs } from './lib/setup/plugins.js';
import {
Expand All @@ -11,8 +12,11 @@ import {
} from './lib/setup/types.js';
import { runSetupWizard } from './lib/setup/wizard.js';

// TODO: create, import and pass remaining plugin bindings (coverage, lighthouse, typescript, js-packages, jsdocs, axe)
const bindings: PluginSetupBinding[] = [eslintSetupBinding];
// TODO: create, import and pass remaining plugin bindings (lighthouse, typescript, js-packages, jsdocs, axe)
const bindings: PluginSetupBinding[] = [
eslintSetupBinding,
coverageSetupBinding,
];

const argv = await yargs(hideBin(process.argv))
.option('dry-run', {
Expand Down
22 changes: 20 additions & 2 deletions packages/create-cli/src/lib/setup/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
PluginCodegenResult,
PluginSetupBinding,
ScopedPluginResult,
Tree,
WriteContext,
} from './types.js';
import { createTree } from './virtual-fs.js';
Expand All @@ -57,6 +58,8 @@ export async function runSetupWizard(
const format = await promptConfigFormat(targetDir, cliArgs);
const ciProvider = await promptCiProvider(cliArgs);

const tree = createTree(await getGitRoot());

const resolved: ScopedPluginResult[] = await asyncSequential(
selectedBindings,
async binding => ({
Expand All @@ -65,11 +68,11 @@ export async function runSetupWizard(
}),
);

await applyAdjustments(tree, resolved);

const packageJson = await readPackageJson(targetDir);
const isEsm = packageJson.type === 'module';
const configFilename = resolveFilename('code-pushup.config', format, isEsm);

const tree = createTree(await getGitRoot());
const writeContext: WriteContext = { tree, format, configFilename, isEsm };

await (context.mode === 'monorepo' && context.tool != null
Expand Down Expand Up @@ -112,6 +115,21 @@ async function resolveBinding(
return binding.generateConfig(answers);
}

async function applyAdjustments(
tree: Pick<Tree, 'read' | 'write'>,
resolved: ScopedPluginResult[],
): Promise<void> {
await asyncSequential(
resolved.flatMap(({ result }) => result.adjustments ?? []),
async ({ path: filePath, transform }) => {
const content = await tree.read(filePath);
if (content != null) {
await tree.write(filePath, transform(content));
}
},
);
}

async function writeStandaloneConfig(
{ tree, format, configFilename }: WriteContext,
results: PluginCodegenResult[],
Expand Down
6 changes: 5 additions & 1 deletion packages/models/src/lib/plugin-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ export type ImportDeclarationStructure = {
/** A single value in the answers record produced by plugin prompts. */
export type PluginAnswer = string | string[] | boolean;

/** Import declarations and plugin initialization code produced by `generateConfig`. */
/** Code and file changes a plugin binding contributes to the generated config. */
export type PluginCodegenResult = {
imports: ImportDeclarationStructure[];
pluginInit: string;
categories?: CategoryConfig[];
adjustments?: {
path: string;
transform: (content: string) => string;
}[];
};

/**
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-coverage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"dependencies": {
"@code-pushup/models": "0.120.1",
"@code-pushup/utils": "0.120.1",
"magicast": "^0.3.5",
"parse-lcov": "^1.0.4",
"zod": "^4.2.1"
},
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-coverage/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { coveragePlugin } from './lib/coverage-plugin.js';

export default coveragePlugin;
export { coverageSetupBinding } from './lib/binding.js';
export type { CoveragePluginConfig } from './lib/config.js';
export { getNxCoveragePaths } from './lib/nx/coverage-paths.js';
Loading
Loading