Skip to content

Commit

Permalink
Merge branch 'main' into add-defaults-to-plugin-options
Browse files Browse the repository at this point in the history
# Conflicts:
#	code-pushup.config.ts
  • Loading branch information
BioPhoton committed Jul 25, 2024
2 parents ff822e5 + 32dfce7 commit de4fce4
Show file tree
Hide file tree
Showing 36 changed files with 1,604 additions and 495 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
**/*.mock.*
**/code-pushup.config.ts
**/mocks/fixtures/**
128 changes: 16 additions & 112 deletions code-pushup.config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { DEFAULT_FLAGS } from 'chrome-launcher/dist/flags.js';
import 'dotenv/config';
import { z } from 'zod';
import {
coverageCoreConfigNx,
eslintCoreConfigNx,
jsPackagesCoreConfig,
lighthouseCoreConfig,
} from './code-pushup.preset';
import {
fileSizePlugin,
fileSizeRecommendedRefs,
packageJsonDocumentationGroupRef,
packageJsonPerformanceGroupRef,
packageJsonPlugin,
} from './dist/examples/plugins';
import coveragePlugin, {
getNxCoveragePaths,
} from './dist/packages/plugin-coverage';
import eslintPlugin, {
eslintConfigFromAllNxProjects,
} from './dist/packages/plugin-eslint';
import jsPackagesPlugin from './dist/packages/plugin-js-packages';
import {
lighthouseGroupRef,
lighthousePlugin,
} from './dist/packages/plugin-lighthouse';
import { mergeConfigs } from './dist/packages/utils';
import type { CoreConfig } from './packages/models/src';

// load upload configuration from environment
Expand All @@ -41,26 +36,6 @@ const config: CoreConfig = {
}),

plugins: [
await eslintPlugin(await eslintConfigFromAllNxProjects()),

await coveragePlugin({
coverageToolCommand: {
command: 'npx',
args: [
'nx',
'run-many',
'-t',
'unit-test',
'integration-test',
'--coverage.enabled',
'--skipNxCache',
],
},
reports: await getNxCoveragePaths(['unit-test', 'integration-test']),
}),

await jsPackagesPlugin(),

fileSizePlugin({
directory: './dist/examples/react-todos-app',
pattern: /\.js$/,
Expand All @@ -72,88 +47,9 @@ const config: CoreConfig = {
license: 'MIT',
type: 'module',
}),

await lighthousePlugin(
'https://github.com/code-pushup/cli?tab=readme-ov-file#code-pushup-cli/',
{ chromeFlags: DEFAULT_FLAGS.concat(['--headless']) },
),
],

categories: [
{
slug: 'performance',
title: 'Performance',
refs: [lighthouseGroupRef('performance')],
},
{
slug: 'a11y',
title: 'Accessibility',
refs: [lighthouseGroupRef('accessibility')],
},
{
slug: 'best-practices',
title: 'Best Practices',
refs: [lighthouseGroupRef('best-practices')],
},
{
slug: 'seo',
title: 'SEO',
refs: [lighthouseGroupRef('seo')],
},
{
slug: 'bug-prevention',
title: 'Bug prevention',
description: 'Lint rules that find **potential bugs** in your code.',
refs: [{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 }],
},
{
slug: 'code-style',
title: 'Code style',
description:
'Lint rules that promote **good practices** and consistency in your code.',
refs: [
{ type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 },
],
},
{
slug: 'code-coverage',
title: 'Code coverage',
description: 'Measures how much of your code is **covered by tests**.',
refs: [
{
type: 'group',
plugin: 'coverage',
slug: 'coverage',
weight: 1,
},
],
},
{
slug: 'security',
title: 'Security',
description: 'Finds known **vulnerabilities** in 3rd-party packages.',
refs: [
{
type: 'group',
plugin: 'js-packages',
slug: 'npm-audit',
weight: 1,
},
],
},
{
slug: 'updates',
title: 'Updates',
description: 'Finds **outdated** 3rd-party packages.',
refs: [
{
type: 'group',
plugin: 'js-packages',
slug: 'npm-outdated',
weight: 1,
},
],
},
{
slug: 'custom-checks',
title: 'Custom checks',
Expand All @@ -166,4 +62,12 @@ const config: CoreConfig = {
],
};

export default config;
export default mergeConfigs(
config,
await coverageCoreConfigNx(),
await jsPackagesCoreConfig(),
await lighthouseCoreConfig(
'https://github.com/code-pushup/cli?tab=readme-ov-file#code-pushup-cli/',
),
await eslintCoreConfigNx(),
);
164 changes: 164 additions & 0 deletions code-pushup.preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { DEFAULT_FLAGS } from 'chrome-launcher/dist/flags.js';
import coveragePlugin, {
getNxCoveragePaths,
} from './dist/packages/plugin-coverage';
import eslintPlugin, {
eslintConfigFromAllNxProjects,
eslintConfigFromNxProject,
} from './dist/packages/plugin-eslint';
import jsPackagesPlugin from './dist/packages/plugin-js-packages';
import lighthousePlugin, {
lighthouseGroupRef,
} from './dist/packages/plugin-lighthouse';
import type { CategoryConfig, CoreConfig } from './packages/models/src';

export const jsPackagesCategories: CategoryConfig[] = [
{
slug: 'security',
title: 'Security',
description: 'Finds known **vulnerabilities** in 3rd-party packages.',
refs: [
{
type: 'group',
plugin: 'js-packages',
slug: 'npm-audit',
weight: 1,
},
],
},
{
slug: 'updates',
title: 'Updates',
description: 'Finds **outdated** 3rd-party packages.',
refs: [
{
type: 'group',
plugin: 'js-packages',
slug: 'npm-outdated',
weight: 1,
},
],
},
];

export const lighthouseCategories: CategoryConfig[] = [
{
slug: 'performance',
title: 'Performance',
refs: [lighthouseGroupRef('performance')],
},
{
slug: 'a11y',
title: 'Accessibility',
refs: [lighthouseGroupRef('accessibility')],
},
{
slug: 'best-practices',
title: 'Best Practices',
refs: [lighthouseGroupRef('best-practices')],
},
{
slug: 'seo',
title: 'SEO',
refs: [lighthouseGroupRef('seo')],
},
];

export const eslintCategories: CategoryConfig[] = [
{
slug: 'bug-prevention',
title: 'Bug prevention',
description: 'Lint rules that find **potential bugs** in your code.',
refs: [{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 }],
},
{
slug: 'code-style',
title: 'Code style',
description:
'Lint rules that promote **good practices** and consistency in your code.',
refs: [{ type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 }],
},
];

export const coverageCategories: CategoryConfig[] = [
{
slug: 'code-coverage',
title: 'Code coverage',
description: 'Measures how much of your code is **covered by tests**.',
refs: [
{
type: 'group',
plugin: 'coverage',
slug: 'coverage',
weight: 1,
},
],
},
];

export const jsPackagesCoreConfig = async (): Promise<CoreConfig> => {
return {
plugins: [await jsPackagesPlugin({ packageManager: 'npm' })],
categories: jsPackagesCategories,
};
};

export const lighthouseCoreConfig = async (
url: string,
): Promise<CoreConfig> => {
return {
plugins: [
await lighthousePlugin(url, {
chromeFlags: DEFAULT_FLAGS.concat(['--headless']),
}),
],
categories: lighthouseCategories,
};
};

export const eslintCoreConfigNx = async (
projectName?: string,
): Promise<CoreConfig> => {
return {
plugins: [
await eslintPlugin(
await (projectName
? eslintConfigFromNxProject(projectName)
: eslintConfigFromAllNxProjects()),
),
],
categories: eslintCategories,
};
};

export const coverageCoreConfigNx = async (
projectName?: string,
): Promise<CoreConfig> => {
if (projectName) {
throw new Error('coverageCoreConfigNx for single projects not implemented');
}
const targetNames = ['unit-test', 'integration-test'];
const targetArgs = [
'-t',
'unit-test',
'integration-test',
'--coverage.enabled',
'--skipNxCache',
];
return {
plugins: [
await coveragePlugin({
coverageToolCommand: {
command: 'npx',
args: [
'nx',
projectName ? `run --project ${projectName}` : 'run-many',
...targetArgs,
],
},
reports: await getNxCoveragePaths(targetNames),
}),
],
categories: coverageCategories,
};
};
9 changes: 9 additions & 0 deletions packages/nx-plugin/executors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"executors": {
"autorun": {
"implementation": "./src/executors/autorun/executor",
"schema": "./src/executors/autorun/schema.json",
"description": "CodePushup CLI autorun command executor. Executes the @code-pushup/cli autorun command See: https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#autorun-command"
}
}
}
16 changes: 16 additions & 0 deletions packages/nx-plugin/mock/utils/executor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NormalizedExecutorContext } from '../../src/executors/internal/context';

export function normalizedExecutorContext(
nameOrOpt: string | { projectName: string },
): NormalizedExecutorContext {
const { projectName } =
typeof nameOrOpt === 'string' ? { projectName: nameOrOpt } : nameOrOpt;
return {
projectName,
workspaceRoot: 'workspaceRoot',
projectConfig: {
name: projectName,
root: 'root',
},
};
}
3 changes: 2 additions & 1 deletion packages/nx-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"generators": "./generators.json"
"generators": "./generators.json",
"executors": "./executors.json"
}
1 change: 1 addition & 0 deletions packages/nx-plugin/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/nx-plugin/src",
"projectType": "library",
"implicitDependencies": ["cli"],
"targets": {
"build": {
"executor": "@nx/js:tsc",
Expand Down
Loading

0 comments on commit de4fce4

Please sign in to comment.